Telegram Inline keyboard without Command node

Hello,
From https://flows.nodered.org/node/node-red-contrib-telegrambot I can create a flow to start a chat (the /foo example). However this requires the user to send the /foo to start the process using a command node. I would like to query a feedback from the user without him doing sending a message (command) first.
Basically, my video portal sends an image using telegram when someone rings. After that, I would like to have the inline keyboard to query a Yes/No answer to open the door.
Is there a way to do that? Can I use directly the sender node? What should be the payload?
All examples I found are based on the /foo first!
Thanks,
GV

You should be able to send a custom keyboard after the image. Unfortunately, I'm not in a position to get you any code right now but this should certainly be possible.

Thanks... Yes, I guess it is possible. I just don't know how :slight_smile:
GV

Do you know how to set up a keyboard anyway? That would be the place to start. Once you've done that, you probably need to send the image in one message and then the keyboard in the next.

This is done via node-red as well ?

Yes. I am using a Grandstream GDS3710. When someone rings, it sends a HTTP request, received by nodered. Then, NodeRed takes a snapshot and sends using telegram.
After that, I am stuck!

I am using node-red-contrib-telegrambot-home and which has a "command" node that can 'listen' for keywords and trigger actions based on that. Then in your case I would send the image + a text and based on the text I would trigger the reply_markup keyboard.

I am using the example from the document of telegrambot and once I have sent the /foo I have the keyboard.
I have also used another example https://discourse.nodered.org/t/turn-flow-on-off-via-iphone/8395/16 and both are working fine.
However they all start with a /foo or /start sent by the user.
GV

I am using the same telegrambot-home. What I can't find is how to "trigger the reply_markup keyboard." ?
GV

You will need read through the documentation of the telegram bot api.

This is the general idea, put this in a function node:

out = {
    method: "sendMessage",
    payload: {
        text: "Open the door",
        reply_markup: {
            inline_keyboard: [
                [{
                    text: "Yes"
                }],
                [{
                    text: "No"
                }]
            ]
        }
    }
}
return out;

command node -> function node -> telegram payload node
Set the telegram payload node method to -set-by-msg.method -

The command node is the trigger.

I’ve seen flows for this on a Dutch forum with a large NR thread, I’m waiting for an appointment to start so I’ll look up those flows later. Someone hooked a telegram node up to a door camera to be able to see when people are ringing the door, or when the mailman delivers packages. Iirc this one also had commands to unlock the door when someone is there.

Thank you for the help. I quite don't understand though.

Did it... but I don't get it.

With this, the "command" is still the trigger (as far as I understand...)

At the moment, my working flow is:

[{"id":"94151847.d29f68","type":"telegram sender","z":"fa35c8e.783dd38","name":"show inline keyboard","bot":"8ec03315.965a1","x":720,"y":600,"wires":[["836ad3f.f92053"]]},{"id":"acabf36d.5dca","type":"function","z":"fa35c8e.783dd38","name":"initial inline keyboard message","func":"// context.global.keyboard = { pending : true, messageId : msg.payload.messageId };\n\nvar opts = {\n reply_to_message_id: msg.payload.messageId,\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\n \"text\": \"Oui\",\n \"callback_data\": \"ouvre\" \n }, \n {\n \"text\": \"Non\",\n \"callback_data\": \"ignore\" \n },\n ]]\n })\n};\n\nmsg.payload.content = 'Ouverture du portail ?';\nmsg.payload.options = opts;\n\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":430,"y":600,"wires":[["94151847.d29f68"]]},{"id":"836ad3f.f92053","type":"debug","z":"fa35c8e.783dd38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":600,"wires":[]},{"id":"5bccc33.d131b3c","type":"telegram command","z":"fa35c8e.783dd38","name":"/Ouvrir","command":"/Ouvrir","bot":"8ec03315.965a1","strict":false,"x":170,"y":600,"wires":[["acabf36d.5dca"],[]]},{"id":"8ec03315.965a1","type":"telegram bot","z":"","botname":"@Jeedom","usernames":"","chatids":"782589784","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"verboselogging":true}]

In order to trigger I need "/Ouvrir" to be sent. This is not what I would like to do... I need to trigger that flow after sending the photo to telegram without any human created message.

GV

If you send the picture to the bot, include a text as well. That text can be the command trigger (this does not have to start with a /)

you can test this:

command-node just with text: "test", connect it to a debug node.

type "test" to your bot, you will get a payload.

It is exactly what I tried. If I send a "start" message (via the msg.payload and not manually) and even if the command is expecting a "start" to trigger, it doesn't work.
I tried using the caption or a separate text. Same result.

GV

My Dutch is even worse than my English! So, your feedback will be really welcome.

GV

My example works. (btw I am dutch but don't need that thread to make this work) :wink:

Ok I forgot 1 thing, for the text an optional property is required, I removed it in the example:

out = {
    method: "sendMessage",
    payload: {
        text: "Open door ?",
        reply_markup: {
            inline_keyboard: [
                [{
                    text: "Yes",
                    url: "http://google.com"
                }],
                [{
                    text: "No",
                    url: "http://google.com"
                }]
            ]
        }
    }
}
return out;

36

Would you be kind to share the flow? I can't figure out what to do with your explanation.
I am fairly new to NR...
Thanks for helping.

GV

This is the flow (i had to desanitize it).
Make sure to enter the chatid in the command-node and payload-node.

[{"id":"4d52e6db.884308","type":"telegrambot-command","z":"30358c58.b1f39c","name":"","bot":"7f0ce88d.8f81e","command":"door_event","commandType":"str","commandCase":false,"x":150,"y":725,"wires":[["ff98728c.b9243"]]},{"id":"54c6182b.d8a728","type":"telegrambot-payload","z":"30358c58.b1f39c","name":"","bot":"7f0ce88d.8f81e","chatId":"","sendMethod":"","payload":"","x":515,"y":725,"wires":[["32b7ce43.71e73a"]]},{"id":"ff98728c.b9243","type":"function","z":"30358c58.b1f39c","name":"","func":"out = {\n    method: \"sendMessage\",\n    payload: {\n        text: \"Open door ?\",\n        reply_markup: {\n            inline_keyboard: [\n                [{\n                    text: \"Yes\",\n                    url: \"http://google.com\"\n                }],\n                [{\n                    text: \"No\",\n                    url: \"http://google.com\"\n                }]\n            ]\n        }\n    }\n}\nreturn out;","outputs":1,"noerr":0,"x":325,"y":725,"wires":[["54c6182b.d8a728"]]},{"id":"32b7ce43.71e73a","type":"debug","z":"30358c58.b1f39c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":725,"wires":[]},{"id":"7f0ce88d.8f81e","type":"telegrambot-config","z":0,"botname":"","usernames":"","chatIds":"","pollInterval":"1000"}]

Now if you receive a message "door_event", you will get the buttons and as an example url it will take you to google, ofcourse you need to change this to the action you want.

I would have probably confused you anyway since I user the other Telegram node - https://github.com/windkh/node-red-contrib-telegrambot - which also allows you to use the new webhook feature rather than polling if you want.