Adding commands to your Telegram Bot with Pipedream Workflows

Adding commands to your Telegram Bot with Pipedream Workflows

Telegram bots can respond to slash commands, just like Slack. In Pipedream you can easily integrate with your Telegram Bot and reply to slash commands from direct messages or in channels - with very little code of course!

Copy this workflow to get started, or follow the steps below!

Creating a Telegram Bot

First, in Telegram open a new conversation with the Botfather.

Then issue the /newbot command to the Botfather to create a new bot.

Follow the prompts, and at the first end you'll be given a special bot token to interact with the bot in Pipedream.

Copy this code and use it to create a new Telegram Bot account connection in Pipedream.

Now you have successfully connected a Telegram Bot to your Pipedream account!

Registering a command

Now that you have a bot created and connected to Pipedream, it's time to create a command.

How to register a bot command with the BotFather

To add commands to your Telegram Bot, open a conversation with the BotFather and issue the command /mybots. Then select your bot from the list.

Click the Edit Bot option, and finally the Set Commands option.

The BotFather expects commands in this format of command - description and each command has it's own line:

hi - send greeting
bye - send bye now
Example of an "Edit commands" response

Send a message in that format of all of the commands you'd like to register on your bot.

Then you'll see autocomplete prompts in your bot when using the / command in the conversation:

Listening to commands

Now you can use the Telegram Bot - New Updates trigger in Pipedream to listen to new message events.

This will trigger your workflow whenever a new message is sent to your bot, either in a channel or in a direct message.

You can differentiate between types of commands under the text field in the event.

Responding to commands

To send a reply to a command, use the Telegram Bot - Reply to Message action in a step in your workflow.

You can use the chat ID from the data sent to your workflow in the Telegram Bot - New Update trigger. This will make sure your Telegram bot replies to the correct chat.

Then you can use the text field to differentiate your bot's response based on the type of command you've set up with either a Node.js step or a Python step.

Learn more

Learn more and get connected!

🔨  Start building at https://pipedream.com
📣  Read our blog https://pipedream.com/blog
💬  Join our community https://pipedream.com/community