Telegram custom keyboard

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:

[
    {
        "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:

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!

As far as i remember reply_markup has to be a JSON eg a string
try this

[{"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"]]}]
{
    "type": "message",
    "chatId": "xxx",
    "content": "Selections?",
    "options": {
        "reply_markup": "{\"resize_keyboard\":true,\"one_time_keyboard\":true,\"keyboard\":[[\"A1\"],[\"A2\"]]}"
    }
}

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:
{"_msgid":"24bbac3deb32ed2f","payload":{"type":"message","chatId":"xxx","content":"Selections?","options":{"reply_markup":{"keyboard":[["Yes"],["No"]]}}},"topic":""}
{
  "_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!

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.

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.

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

I agree - guessing is difficult.

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:

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

Your output works for me in a sender node

[{"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}]

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

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.

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

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

yes, it is!

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

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.

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!

I have the chat id in the chatid input field.

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!

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

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!

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