How to Configure Pipedream to Perform Different Workflows for Each Telegram Command?

This topic was automatically generated from Slack. You can find the original thread here.

i need to create a telegram bot with unique commands. Each command needs to have its own workflow. How can i configure pipedream so each telegram command performs different workflows? cc @UPYT7RBJP

To create a Telegram bot with unique commands, each triggering its own workflow, you can follow these steps: 1. First, you need to create a bot on Telegram. You can do this by talking to the BotFather on Telegram, which will provide you with a bot token. 2. Then, in Pipedream, you can create a workflow for each command you want your bot to respond to. For each workflow, you would use the Telegram Bot API trigger. When setting up the trigger, you’ll be asked to enter your bot token. 3. In the “Command” field of the trigger setup, you would enter the command that should trigger this workflow. For example, if you want a command “/start” to trigger a workflow, you would enter “start” in the Command field. 4. Then, you can add actions to each workflow that should be performed when the respective command is received. Remember to create a separate workflow for each command you want your bot to respond to. Each workflow will have its own unique endpoint, which you can find in the workflow’s settings. Please note that you can search for “Telegram Bot API” in the Pipedream UI to find the trigger. For more detailed instructions on how to use the Telegram Bot API trigger, you can visit https://pipedream.com/apps/telegram/sources/telegram-bot-api.

ive created a few different workflows for unique telegram commands. For example i created a command /hello that returns “hello” and /hi that returns “hi”. But when I send a message execute the command “/hello”, both workflows (hi & hello) are simultaneously run, why is this happening?

This might be happening because of the way the Telegram Bot API trigger is configured in Pipedream. When you set up the trigger, you specify a command that should trigger the workflow. However, the command is not filtered out from the message text that is sent to all workflows. This means that if you have a workflow for the “/hi” command and another for the “/hello” command, and you send the command “/hello”, both workflows will receive the message text “/hello”. The “/hi” workflow will not recognize “/hello” as the “/hi” command, but it will still be triggered because it received a message. To ensure that each workflow only runs for its specific command, you can add a condition at the beginning of each workflow that checks if the received command matches the expected command. Here’s an example of how you can do this: ```
if (steps.trigger.event.command !== “/hello”) { $.end(“This workflow only handles the /hello command”); }

can you give me the python version of this code please

I’m sorry, but it seems there was a misunderstanding. I don’t see any code attached to your question. Could you please provide the specific Node.js code you’d like to convert to Python? This will help me provide a more accurate Python equivalent.

could you give me the python code of snippet of code

if (steps.trigger.event.command !== "/hello") {
  $.end("This workflow only handles the /hello command");
}

Sure, here’s the equivalent code in Python: if steps.trigger.event.command != "/hello": raise Exception("This workflow only handles the /hello command") This Python code will raise an exception and stop the execution of the script if the command is not “/hello”. This is similar to the $.end() function in the Pipedream Node.js environment which stops the execution of the workflow.

steps.trigger.event.command does not exists

I apologize for the confusion. The steps.trigger.event.command is a hypothetical reference to the command from the Telegram Bot API trigger in Pipedream. However, Pipedream might not expose the command directly in this way. In Pipedream, each event that triggers a workflow is passed as the event object to the run() function. The structure of this event object depends on the trigger you’re using. For the Telegram Bot API trigger, you might need to inspect the event object to see how the command is passed. You can do this by adding a step in your workflow with the following code: console.log(steps.trigger.event); This will log the event object to the Pipedream console, allowing you to see its structure and how the command is passed. Once you know the structure, you can modify the condition in your workflow to check for the correct command. For example, if the command is passed as event.body.command, you would use: if (steps.trigger.event.body.command !== "/hello") { $.end("This workflow only handles the /hello command"); } Please replace body.command with the correct path to the command in the event object.

since as you pointed out, Telegram only allows you to create a single webhook at a time, there are a few ways you can work around that constraint:
• Handle the logic within a single workflow, and you can have a step that handles all the logic for what to do, based on the inbound command
• A probably cleaner way to do it is to assess the command that came in, then kick trigger the corresponding workflow that handles that logic

Does that make sense?