Telegram bot posting to group

(PointCell) #1


I created a simple flow for my telegram bot which asks a few questions then outputs the answers on the screen.

I wanted to know if the bot can take that output and post it on a Group in telegram? (the bot is a member of the group)

And how can i add a “action button” to that output. i need one of the group members to confirm what the bot is displaying. (doesn’t matter who, whichever clicked first)

Is this possible?

(Daniel Beckett) #2


What kind of output do you want to pass to the group?

The main consideration is how you want to trigger the message being sent to the group in Telegram. You could use the Broadcast service with a trigger for webhook so that once your main flow has completed it can send a webhook & http request to the broadcast trigger. For ease of use, you may want to save the output to something like Google Sheets but it’s also possible to pass data between webhooks so that it’s shared across flows.

To display a confirmation button you could either use Bot > Send a Message with a shortcut or look into using the inline requests with our custom request service. An example would look something like this:

"chat_id": "{{bot_new_message.channel_id}}",
"text": "Output Here",
"reply_markup": {
            "inline_keyboard": [
			"text": "Confirmed",
                            "callback_data": "Confirmed"


(PointCell) #3

Thank you so much for your help, the output i want to send is the answers to questions i set the bot to ask.
ill give this a go and report back.

(PointCell) #4


Ok…so far i have managed to create a flow which asks a few questions, then add the answers to google spreadsheet and then send these answers to a webhook.

I have another flow which picks up that webhook info and broadcast it to the bot with the button you gave me.

I am facing these problems:

  1. It seems the webhook flow sends the answers only to the bot chat window, non of the answers gets sent to the group, which the bot is a member of. (we can call it “Test1 group”), it is possible that i dont know what to write in this line:
    "chat_id": "{{23467****}}",
    And thats whats causing it, but im guessing here :slight_smile:

2.The other issue is, i need that button to be disabled once a user clicked on it. and i need the user who clicked on it, to be added to the spreadsheet row with the answers, as the guy who picked up the call.

How can i achieve this?

(Daniel Beckett) #5


Shortcuts aren’t quite the same in Telegram as the other platforms. I think you may be best off using Bot > Send a Message with a shortcut instead of the custom request.

Unfortunately there’s no method available which would present a button to the group and then disappear once a user has clicked it. The closest you could get to achieving this would be to log an entry onto your Google Sheet for something like ‘Assigned User’ where you can log an entry of the person which clicked the button first.

I would pass some kind of unique identifier for each entry on the Google Sheet so that it can be queried in the broadcast flow and then used when one of the users claims the job.

Once someone presses the button /shortcut you could search the Google Sheet for the unique reference sent in the broadcast and then have a column for assigned user - using Filters you would decide which action should happen at this point. If there is no assigned user then whomever sent the request is passed to the next action which will do Google Sheets > Update Row. If an assigned user is already set then they are sent a message saying that the job has been claimed.

(PointCell) #6


Ok i see what you mean…

I am trying your approach now and managed to add the shortcut button, however i cant find where i can set the behaviour of a shortcut to log the user ID who clicked it…

Also the big issue remains, the message dose not get sent to the group, what am i missing?

(Daniel Beckett) #7


It’s always easier when you’re just passing ideas to others, can’t always see some of the complications until you get stuck in to actually building something :laughing:

I’ve put together a test case that shows how this could work. All in all it’s taken three flows to achieve this and I’ll explain how it works as best as I can.

First, a general overview:

Flow 1 - Questions are asked and answered. The answers are saved to a Google Sheet and passed in a webhook to the broadcast flow. An attribute is used to assign a unique ‘request’ number for each row.

Flow 2 - Retrieves the answers from the Google Sheet by searching for the request # sent in the webhook. Sends the answers in a message to the broadcast audience and also outputs a shortcut that can be clicked to claim the job (row).

Flow 3 - New message trigger that is activated by a user clicking the shortcut from Flow 2. Checks for the request number and assigns the user to the row if no user is already assigned.

For reference, here’s what my test Google Sheet looks like:

It’s the column names that are important but you can see request number 5 is a completed run of all three flows, the others were just test runs for flows 1 & 2.

Okay, now for a more detailed look. Let’s start with Flow 1.

Flow 1, Questions

This Flow is fairly straightforward. The user is asked two questions; “What day is it?” & “Pick a colour”.

An important thing to note here is that on my Google Sheet I manually added the first entry so that the Request column had the number 1 there.

First Row

Now that we have a request number to work with we can do a list rows action to pull through all of the rows and follow it up with a simple calculation.

{{list_rows.results_+_gsx:request n}}+1

Collection Output Modifier


So we’re taking the last result for the request column and adding 1 to it, which with request number 1 is simply 1+1.

An attribute is set to contain the new request number, we get the value and then add a new row to the Google Sheet that contains the request number and the question answers.

Set Attribute

Get Attribute

Add Row

The final step for this flow is to send a webhook to trigger the broadcast flow. in the webhook I’m also passing out the request number and answers to the questions by adding them to the URL.

For example:{{ask_a_question_day.parsed_answer}}&colour={{ask_a_question_colour.choice}}&request={{get_an_attribute_request.value}}


The real important value to pass here is the request number.

See Using Data from the Web in Flow XO for more info on passing values between webhooks.

Flow 2, Broadcast

A broadcast is triggered by receiving a webhook from the previous flow.

Using the received request number from the webhook a Google Sheets > Get Row action can be done to find the appropriate row.

Get a Row

A send message action is then used to output the answers to the questions from flow 1 with a shortcut that contains the request number.

Send Message

Having the request number on the shortcut is important for the next flow.

Since we’re using a shortcut the only way to detect that a user has selected it is to have another flow with a new message trigger.

Flow 3, Assign User

A new message trigger listens out for the shortcut from Flow 2. You’ll need to make sure that the ‘Overhear’ message type is enabled for the trigger.

New Message Trigger

The shortcut from the previous flow also included the request number so we need to parse that value from the message. This can be done by using the Text service to Find Matches. Some basic regex is needed to find the number, the expression is [\d]

Find Match

Now that we have the request number we can do a Search Rows action to find the right row.

Search Row

Now the filters start to come into play. We need one of two things to happen:

  1. No user is assigned to the row so the person that clicked on the shortcut is assigned to it.
  2. A user is already assigned so the person that clicked on the shortcut is told that they can’t be assigned.

Scenario one will run an Update Row action IF {{search_rows.results_+_gsx:user}} Is Empty.
You can use the row ID returned from the previous search rows action.

Update Row

Filter for Update Row

You can output a message to confirm that the user has been assigned, again, using the same filter.

Send Message

Send Message Filter

Scenario 2 sends a message if a user is already assigned and also outputs that user’s name.

Send Message

Send Message Filter

And that’s it. Possibly a bit over engineered but it should do the trick.

Hopefully it helps! :slight_smile:


(PointCell) #8


I am literally lost for words for your help!

Thank you so much i learned a lot from this! greatly appreciated!

Gonna give this a go during the weekend :slight_smile:

(Crazy One) #9

Hi, I am literally stuck, can you guys help me as well, I am creating a bot for posts to sale things, What I want to do is to create a bot that gathers some info about the product from a seller and post it to the group. is there any ways to do it?