# Telegram Response Payload

**URL:** <https://discourse.nodered.org/t/telegram-response-payload/50631>\
**Category:** General\
**Created:** [5 September 2021 10:33 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631 "2021-09-05T10:33:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 10:33 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/1 "2021-09-05T10:33:20Z")

</div>

Good afternoon, everyone!  
I use code-red-contrib-telegrambot, I can't understand how to determine the payload for a specific request. The answer comes only YES or NO. But it is not clear to what request. How do I determine which request was answered?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 September 2021 12:15 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/2 "2021-09-05T12:15:31Z")

</div>

> [@NooBAsTiK](#):
>
> But it is not clear to what request. How do I determine which request was answered?

If you have only one command then its that one. Are you somehow multiplexing a command?

Show us your flow and try to describe a bit more what your issue is (e.g. is it a problem for single users or multiple users? are there multiple questions? are you using the keyboard? etc)

---

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 12:35 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/3 "2021-09-05T12:35:59Z")

</div>

I'm doing the logic. If the light in the bathroom is turned on for more than 30 minutes, the bot asks "turn off the light or not", if there is no answer within 5 minutes, the light turns off. Requests will be for the light of the toilet, corridor, etc. How to determine what the answer refers to.  
I use this request code in the telegram:

```auto
 var buttons = {
   reply_markup: JSON.stringify({
     keyboard: [
     ["YES","NO"]],
     'resize_keyboard' : true, 
     'one_time_keyboard' : true
   })
 };
 msg.error = false;
 msg.payload = {
     chatId : 'id_group',
     type : 'message',
     content : "Turn off the bathroom light?",
     options : buttons,
     //messageId : 99,
     //sentMessageId : 99,
 }
 return msg ;

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 September 2021 12:40 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/4 "2021-09-05T12:40:43Z")

</div>

Note: I edited your post and changed the inserted code to be surrounded by back-tics to make it ore readable,

---

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 13:16 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/5 "2021-09-05T13:16:35Z")

</div>

In the description there is such a code, as I understand it, it adds a payload to the answer:

```auto
"inline_keyboard": [[
     {"text": "Yes","callback_data": "FOO YES"},
     {"text": "No", "callback_data": "FOO NO"}
]]

```

But for some reason it doesn't work. The menu appears in the telegram bot, but the answer does not come in node-red

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 September 2021 14:30 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/6 "2021-09-05T14:30:43Z")

</div>

Are you checking 2nd output?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e279fef8e8f826e07cc05f14ddc387088f6f9a9.png)

---

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 15:02 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/7 "2021-09-05T15:02:24Z")

</div>

yes.  
I took the code from the example and the payload began to come to node red:

```auto
var opts = {
  reply_markup: JSON.stringify({
    "inline_keyboard": [[
                {
                    "text": "A1",
                    "callback_data": "1"            
                }, 
                {
                    "text": "A2",
                    "callback_data": "2"            
                }]
            ]
  })
};

msg.payload.content = "Selection?";
msg.payload.options = opts;
msg.payload.chatId = id_group;
msg.payload.messageId = 99;
msg.payload.sentMessageId = 99;
msg.payload.type = "message";

return [msg];

```

But in the Telegram, I can press these buttons many times, they do not disappear, this is bad.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 September 2021 15:35 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/8 "2021-09-05T15:35:18Z")

</div>

There is no need to stringify the options.

try this flow...

```auto
[{"id":"261f71c7.09969e","type":"catch","z":"5d3f964c.fef898","name":"","x":640,"y":960,"wires":[["3188d108.c5c9ce"]]},{"id":"3188d108.c5c9ce","type":"debug","z":"5d3f964c.fef898","name":"No Repsonse","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1220,"y":960,"wires":[]},{"id":"64d9c2e7.37f9fc","type":"telegram sender","z":"5d3f964c.fef898","name":"show keyboard","bot":"fa7a9376.321ce","haserroroutput":false,"outputs":1,"x":966,"y":785,"wires":[["b9181155c9712c9f"]]},{"id":"922f958f.6b2a18","type":"function","z":"5d3f964c.fef898","name":"confirmation message","func":"const opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: JSON.stringify({\n keyboard: [\n ['Yes'],\n ['No']],\n 'resize_keyboard' : true, \n 'one_time_keyboard' : true\n })\n};\n\nmsg.payload.content = 'Are you sure?';\nmsg.payload.options = opts;\n\nreturn msg;\n","outputs":"1","noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":785,"wires":[["64d9c2e7.37f9fc"]]},{"id":"d50e9648.1c6648","type":"telegram command","z":"5d3f964c.fef898","name":"/bar","command":"/bar","description":"","registercommand":false,"language":"","bot":"fa7a9376.321ce","strict":false,"hasresponse":true,"useregex":false,"removeregexcommand":false,"outputs":2,"x":480,"y":812,"wires":[["922f958f.6b2a18"],["d9debf3e.255fe"]]},{"id":"d9debf3e.255fe","type":"function","z":"5d3f964c.fef898","name":"check answer and respond","func":"if(msg.payload.content === 'Yes')\n{\n msg.payload.content = 'Consider it done';\n return [msg, null]; \n} else {\n msg.payload.content = 'No';\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"initialize":"","finalize":"","libs":[],"x":724,"y":844,"wires":[["7060d4f9.f196dc","68861cc0636dd0a0"],["3188d108.c5c9ce"]]},{"id":"7060d4f9.f196dc","type":"telegram sender","z":"5d3f964c.fef898","name":"send response","bot":"fa7a9376.321ce","outputs":1,"x":1220,"y":840,"wires":[[]]},{"id":"b9181155c9712c9f","type":"debug","z":"5d3f964c.fef898","name":"Show Keyboard","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1220,"y":780,"wires":[]},{"id":"68861cc0636dd0a0","type":"debug","z":"5d3f964c.fef898","name":"Yes response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1220,"y":900,"wires":[]},{"id":"fa7a9376.321ce","type":"telegram bot","botname":"my bot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","botpath":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

```

it requires you so send `/bar` but you can adapt it into your solution

---

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 16:48 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/9 "2021-09-05T16:48:56Z")

</div>

It works. But if there are two messages at the same time /bar and /foo for example. I understand correctly that it will be necessary to send commands from node red (/light\_off /light\_on, etc.) to the chat with the bot

---

<div class="post-metadata">

**Author:** ![NooBAsTiK](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NooBAsTiK](https://discourse.nodered.org/u/NooBAsTiK)\
**Post date:** [5 September 2021 17:08 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/10 "2021-09-05T17:08:30Z")

</div>

And somehow you can skip entering the command (/bar). My trigger is a timer in node-red.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 November 2021 17:09 UTC](https://discourse.nodered.org/t/telegram-response-payload/50631/11 "2021-11-04T17:09:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
