Razzor
(Razzor)
August 12, 2022, 1:53pm
1
Hey Everyone, I’m building a workflow for telegram bot as follow:
1- Send command from telegram bot
2- pipedream trigger for the event
3- pipedream send a text message as “Enter name”
how can I add in the workflow the next text to be received or how can I add a trigger event to proceed with more steps?
pierce
(Pierce)
August 12, 2022, 3:54pm
2
Hi @Razzor
First off, welcome to the Pipedream community. Happy to have you!
Great question. I assume you’ve already created your bot via the Telegram BotFather.
Next you’ll need to register your command on your bot with the BotFather:
Open a chat with the BotFather
Send the command /mybots
Choose your bot
Select Edit Commands
Define your command
Then in your Pipedream Telegram trigger, you can detect commands vs normal messages using the entities
property in the Telegram message from the user:
If steps.trigger.event.entities
includes a { type: 'bot_command' }
then you know you should reply with a message.
Then you can send a reply, below I’m using a pre-built action:
Note: I added the ForceReply
option to make the user respond with a reply to the prompt:
Then you’ll have to conditionally accept this answer and move onto the next.
I would recommend using a Node.js or Python step to act as the “chat router”, and store the message_id
of the user’s responses in a Data Store.
Hi Piecre,
There is great workmanship in your message. Pipedream has excellent features.
I’m trying to understand everything. I think the following scenario is possible;
I have a telegram bot, I added it to a channel, and we can auto-reply to a command or message called /hi?
pierce
(Pierce)
November 3, 2022, 5:29pm
4
Hi @ryanggunner
Thanks for reaching out, yes that scenario is definitely possible.
You’ll have to first use the BotMaster to add a new command to your pre-existing bot.
Then in Pipedream follow the directions I have described above.
Then in the workflow, you can use the steps.trigger.event.text
to determine which slash command the user initiated.
I’ll be making a short video on how to do this as well. Hope you don’t mind a shout out.
Yes please make a video, ser.
You say it’s very easy to do. but I can’t.
Im 40 yo. I even started learning node.js to be able to do this.
It’s not easy to deal with codes. I respect you!
If it is difficult to make a video, can you send me a detailed e-mail? Pls
btw, I learned to write a code in node.js below
I wrote this so you know I’m not lazy and trying to learn
bot.hears(‘/today’, (ctx)=> [
ctx.reply(‘Todays Launch List’)
])
pierce
(Pierce)
November 4, 2022, 6:19pm
7
1 Like
Thank you
This really helped a lot.
It’s great that you make a video and respond in such a short time.
You are a great person. and Pipedream awesome!
1 Like
Hi @pierce
The bot works fine, responds to my commands as I want. and more.
When I interact with the bot’s posts(reply,quote) to the Channel, it resends the message. How do I prevent it from doing this?
I couldn’t find if this is due to telegram bot api or is it related to codes, I’m researching
Hmm, I looked at Inspector a bit. unlike normal trigger
''reply_to_message {6} ‘’ appears.
steps.trigger.event.message.reply_to_message
i think this is related to update type - message
Thanks again.
pierce
(Pierce)
November 7, 2022, 3:38pm
10
Hi @ryanggunner
Glad to hear the example unblocked you.
So you’ll need to use the Node.js code step to exit the workflow early on Telegram messages that shouldn’t trigger a reply.
Here’s the code from the video, with an example of exiting the workflow early using $.flow.exit()
:
// To use previous step data, pass the `steps` object to the run() function
export default defineComponent({
async run({ steps, $ }) {
if(steps.trigger.event.message.text == '/hi') {
return 'Hi from Pipedream AGAIN';
} else if(steps.trigger.event.message.text == '/bye') {
return 'Bye nice to see ya come again soon';
} else {
$.flow.exit("Not a recognized command, exiting early");
}
},
})
Here’s documentation on how to use $.flow.exit
.
1 Like
pierce
(Pierce)
November 7, 2022, 4:25pm
11
Based on my experience building a Telegram bot slash command from the video walkthrough, I think a new trigger can be added to only listen to bot slash commands, instead of all messages.
I’ve opened up an issue here:
opened 04:23PM - 07 Nov 22 UTC
enhancement
help wanted
good first issue
trigger / source
**Describe the event source. What app is this for, and what event does the trigg… er correspond to?**
Currently we don't have a source specifically for responding to Telegram Bot slash commands.
As a Pipedream user, you can use the **New Updates** trigger, but it's clunky for building slash commands for Telegram Bots.
Here's an example of all of the steps you need to take currently to build a Telegram Bot that responds to a slash command:
https://www.youtube.com/watch?v=Tv2eT0CxoP4
Instead, it would be great if you could easily define a specific trigger to listen to all slash commands, or just a subset of slash commands.
**Please provide a link to the relevant API docs for the specific service / operation this trigger is tied to.**
* `getMyCommands` - [list all commands available to the current bot](https://core.telegram.org/bots/api#getmycommands).
The `getMyCommands` endpoint should be used to build an async options list for a `commands` prop.
Then you can detect if a particular incoming event is a slash command via the event's payload under the `entities` array`:
![CleanShot 2022-11-07 at 11 19 32@2x](https://user-images.githubusercontent.com/2694734/200360779-371203a1-e74e-4dc7-983e-128d30fc054d.png)
Pseudocode example:
```javascript
import telegramBot from '../telegramBot.app.mjs';
export default {
key: 'telegram-new-bot-command',
name: 'New Bot Command',
props: {
telegramBot,
commands: {
optional: true,
type: 'string[]',
async options() {
// list commands from the `getMyCommands` endpoint
}
}
}
async run(event) {
// detect if the event is a slash command using the `entites` attribute
// detect if there is a subset of commands defined in this.commands, and if this event is one of them
}
}
```
1 Like