# Telegram custom keyboard

**URL:** <https://discourse.nodered.org/t/telegram-custom-keyboard/81587>\
**Category:** General\
**Created:** [26 September 2023 11:45 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587 "2023-09-26T11:45:43Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 11:45 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/1 "2023-09-26T11:45:43Z")

</div>

Im am using node-red-contrib-telegrambot.  
I am trying to create a custom keyboard but was not able to setup the payload properly.  
This is how I tried it:

```auto
[
    {
        "id": "2cebda8cf198719a",
        "type": "change",
        "z": "33667947.7eff86",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "payload.type",
                "pt": "msg",
                "to": "message",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.chatId",
                "pt": "msg",
                "to": "xxx",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.content",
                "pt": "msg",
                "to": "Selections?",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.options.reply_markup.resize_keyboard",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "payload.options.reply_markup.one_time_keyboard",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "payload.options.reply_markup.keyboard",
                "pt": "msg",
                "to": "[['A1'],['A2']]",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 310,
        "y": 2340,
        "wires": [
            [
                "60218a44b83f18ac",
                "6714a738e84a504d"
            ]
        ]
    }
]

```

Reply is:

```auto
Caught exception in sender node:
Error: ETELEGRAM: 400 Bad Request: inline keyboard expected
when processing message: 

```

I would apreciate some help how to setup it correctly!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 12:29 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/3 "2023-09-26T12:29:15Z")

</div>

As far as i remember reply\_markup has to be a JSON eg a string  
try this

```auto
[{"id":"2cebda8cf198719a","type":"change","z":"c31640d81bf733c7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.type","pt":"msg","to":"message","tot":"str"},{"t":"set","p":"payload.chatId","pt":"msg","to":"xxx","tot":"str"},{"t":"set","p":"payload.content","pt":"msg","to":"Selections?","tot":"str"},{"t":"set","p":"payload.options.reply_markup","pt":"msg","to":"$string(\t {\t \"resize_keyboard\":true,\t \"one_time_keyboard\":true,\t \"keyboard\":[[\"A1\"],[\"A2\"]]\t }\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":480,"wires":[["3c48c891c7d62745","c8a8015.60267"]]}]

```

```auto
{
    "type": "message",
    "chatId": "xxx",
    "content": "Selections?",
    "options": {
        "reply_markup": "{\"resize_keyboard\":true,\"one_time_keyboard\":true,\"keyboard\":[[\"A1\"],[\"A2\"]]}"
    }
}

```

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 14:03 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/4 "2023-09-26T14:03:56Z")

</div>

thanks

1. I have tried your proposal with same result
2. help me on the horse. Where is the difference to my way? If I take the output of a debug-node:

```auto
{"_msgid":"24bbac3deb32ed2f","payload":{"type":"message","chatId":"xxx","content":"Selections?","options":{"reply_markup":{"keyboard":[["Yes"],["No"]]}}},"topic":""}

```

```auto
{
  "_msgid":"24bbac3deb32ed2f",
  "payload":
  {
    "type":"message",
    "chatId":"xxx",
    "content":"Selections?",
    "options":
    {
      "reply_markup":
      {
        "keyboard":[["Yes"],["No"]]
      }
    }
  },
  "topic":""
}

```

reply-markup looks very much alike a JSON-String!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 14:09 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/5 "2023-09-26T14:09:12Z")

</div>

No you have not made reply mark up a string look at the change node i posted. If it was a string the quotes would be escaped as in my example.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 14:23 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/6 "2023-09-26T14:23:06Z")

</div>

first of all: you are naturally right.  
The TELEGRAM-API Docu says: A JSON-serialized object ....

I think, my example was a JSON Object, but not a serialized object.

Anyhow. I imported your example, change the ChatID and sent it to a sender-node - same error message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 14:24 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/7 "2023-09-26T14:24:33Z")

</div>

show us the output of the change node using a debug node. Can not help guessing what is happening.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 14:30 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/8 "2023-09-26T14:30:07Z")

</div>

I agree - guessing is difficult.

```auto
Caught exception in sender node:
Error: ETELEGRAM: 400 Bad Request: inline keyboard expected
when processing message: 
{"_msgid":"934fd9517486e26f","payload":{"type":"message","chatId":"xxx","content":"Selections?","options":{"reply_markup":"{\"resize_keyboard\":true,\"one_time_keyboard\":true,\"keyboard\":[[\"A1\"],[\"A2\"]]}","chat_id":"xxx","text":"Selections?"}},"topic":""}

```

This was the error output on the debug view - not the output of a debug-node.

The debug-node says:

```auto
{"_msgid":"35f9f52fecee7a63","payload":{"type":"message","chatId":"xxx","content":"Selections?","options":{"reply_markup":"{\"resize_keyboard\":true,\"one_time_keyboard\":true,\"keyboard\":[[\"A1\"],[\"A2\"]]}"}},"topic":""}

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 14:39 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/9 "2023-09-26T14:39:58Z")

</div>

Your output works for me in a sender node

```auto
[{"id":"609460f3a83e6b3d","type":"telegram sender","z":"d1395164b4eec73e","name":"","bot":"2199975104e81aee","haserroroutput":false,"outputs":1,"x":910,"y":480,"wires":[[]]},{"id":"32c8b00b35e29397","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"message\",\"chatId\":\"-155667774082\",\"content\":\"Selections?\",\"options\":{\"reply_markup\":\"{\\\"resize_keyboard\\\":true,\\\"one_time_keyboard\\\":true,\\\"keyboard\\\":[[\\\"A1\\\"],[\\\"A2\\\"]]}\"}}","payloadType":"json","x":670,"y":480,"wires":[["609460f3a83e6b3d"]]},{"id":"2199975104e81aee","type":"telegram bot","botname":"elcidtestbot","usernames":"","chatids":"-822824734","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

```

 ![image18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4bd69fb35628b03dbcf6b33fafc64ec07e5fe45.jpeg)

Have you looked at Import \> examples \> telegram bot \> custom keyboards. The first example is a keyboard.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 14:47 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/10 "2023-09-26T14:47:01Z")

</div>

the example was the base where I started. But I am not that much familiar with JAVASCRIPT so I tried to port it to a change-node.  
I will check why I got a different output or even none.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 14:54 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/11 "2023-09-26T14:54:32Z")

</div>

I again imported what you provided with the screenshot. Againt the error message.  
I guess, there must be some difference in the environment.

I have:  
node-red 3.1.0  
node-red-contrib-telegrambot 15.1.6  
node.js 14.16.0

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 15:14 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/12 "2023-09-26T15:14:16Z")

</div>

Tested on  
node-red 3.0.2  
node-red-contrib-telegrambot 15.1.6  
node.js 20.2.0  
But would not expect tthese differences to cause an issue.

Is the error the same `400 inline keyboard expected`

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 15:24 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/13 "2023-09-26T15:24:01Z")

</div>

yes, it is!

Update: by the way - an inline-example works!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 15:34 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/14 "2023-09-26T15:34:25Z")

</div>

Strange

How is your bot config set up in th sender node config pencil icon.

and what about you botfather bot settings privacy , group setting and inline mode.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 15:54 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/15 "2023-09-26T15:54:21Z")

</div>

> How is your bot config set up in th sender node config pencil icon.

Only the API-Key

> botfather bot settings privacy , group setting and inline mode

Inline-Mode: yes; allow-groups: yes; group-privacy: on; channel admin rights: post in channel, manage channel

Nothing suspicious!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 16:03 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/16 "2023-09-26T16:03:40Z")

</div>

> [@khfischbach](#):
>
> Only the API-Key

I have the chat id in the chatid input field.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [26 September 2023 16:07 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/17 "2023-09-26T16:07:24Z")

</div>

didn't change anything. And if I have seen it right you also had the chatid inside the message. But anyhow.

Thanks for help - I will shutdown for now!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 September 2023 16:08 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/18 "2023-09-26T16:08:34Z")

</div>

No where the api key is entered there is a chatid field.

---

<div class="post-metadata">

**Author:** ![khfischbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/khfischbach/32/16627_2.png) [@khfischbach](https://discourse.nodered.org/u/khfischbach)\
**Post date:** [28 September 2023 12:46 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/19 "2023-09-28T12:46:41Z")

</div>

found the error!  
I only can send the custom keyboard with my own users chat-id. Not to any chat!  
Inline Keyboards can obvieously be sent to any chat-id!

---

<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:** [27 November 2023 12:47 UTC](https://discourse.nodered.org/t/telegram-custom-keyboard/81587/20 "2023-11-27T12:47:06Z")

</div>

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