Skip to content

Commit

Permalink
fixed #266
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Aug 28, 2022
1 parent 0e2f101 commit 99985c4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

# [13.0.0] - 2022-08-28
### breaking change in answerCallbackQuery: options is now an object - [#266](https://github.com/windkh/node-red-contrib-telegrambot/issues/266)

# [12.0.0] - 2022-07-17
### upgraded socks-proxy-agent to 7.0 - [#260](https://github.com/windkh/node-red-contrib-telegrambot/issues/260)

Expand Down
2 changes: 1 addition & 1 deletion examples/basicinlinekeyboard.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"f7c18f49.063c4","type":"telegram sender","z":"c8b50aaa.e632d","name":"","bot":"2db9661a.cf3b0a","x":730,"y":900,"wires":[[]]},{"id":"f97878f7.de1bf8","type":"function","z":"c8b50aaa.e632d","name":"build keyboard","func":"var opts = {\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\n \"text\": \"A1\",\n \"callback_data\": \"1\" \n }, \n {\n \"text\": \"A2\",\n \"callback_data\": \"2\" \n }]\n ]\n })\n};\n\nmsg.payload.content = \"Selection?\";\nmsg.payload.options = opts;\nmsg.payload.chatId = 12345;\nmsg.payload.messageId = 99;\nmsg.payload.sentMessageId = 99;\nmsg.payload.type = \"message\";\n\nreturn [ msg ];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":900,"wires":[["f7c18f49.063c4","67925ff5.4c7c9"]]},{"id":"67925ff5.4c7c9","type":"debug","z":"c8b50aaa.e632d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":960,"wires":[]},{"id":"e1a6a394.269598","type":"inject","z":"c8b50aaa.e632d","name":"","props":[{"p":"payload.content","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":230,"y":900,"wires":[["f97878f7.de1bf8"]]},{"id":"981d4537.1ced18","type":"telegram event","z":"c8b50aaa.e632d","name":"","bot":"2db9661a.cf3b0a","event":"callback_query","autoanswer":false,"x":240,"y":982,"wires":[["ab3f06a.9c5a0f8"]]},{"id":"ab3f06a.9c5a0f8","type":"debug","z":"c8b50aaa.e632d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":982,"wires":[]},{"id":"93430912.0f4f4","type":"comment","z":"c8b50aaa.e632d","name":"Inline keyboard: Reply with \"callback_query\"","info":"","x":350,"y":842,"wires":[]},{"id":"2db9661a.cf3b0a","type":"telegram bot","z":"","botname":"HeinzBot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]
[{"id":"f7c18f49.063c4","type":"telegram sender","z":"ec1cf3fd9654e7e5","name":"","bot":"65ca12172854cc2d","haserroroutput":false,"outputs":1,"x":670,"y":420,"wires":[[]]},{"id":"f97878f7.de1bf8","type":"function","z":"ec1cf3fd9654e7e5","name":"build keyboard","func":"var opts = {\n reply_markup: JSON.stringify({\n \"inline_keyboard\": [[\n {\n \"text\": \"A1\",\n \"callback_data\": \"1\" \n }, \n {\n \"text\": \"A2\",\n \"callback_data\": \"2\" \n }]\n ]\n })\n};\n\nmsg.payload.content = \"Selection?\";\nmsg.payload.options = opts;\nmsg.payload.chatId = 138708568;\nmsg.payload.messageId = 29;\nmsg.payload.sentMessageId = 29;\nmsg.payload.type = \"message\";\n\nreturn [ msg ];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":420,"wires":[["f7c18f49.063c4","67925ff5.4c7c9"]]},{"id":"67925ff5.4c7c9","type":"debug","z":"ec1cf3fd9654e7e5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":380,"wires":[]},{"id":"e1a6a394.269598","type":"inject","z":"ec1cf3fd9654e7e5","name":"","props":[{"p":"payload.content","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":170,"y":420,"wires":[["f97878f7.de1bf8"]]},{"id":"981d4537.1ced18","type":"telegram event","z":"ec1cf3fd9654e7e5","name":"","bot":"65ca12172854cc2d","event":"callback_query","autoanswer":false,"x":180,"y":502,"wires":[["385615779f4b3364"]]},{"id":"93430912.0f4f4","type":"comment","z":"ec1cf3fd9654e7e5","name":"Inline keyboard: Reply with \"callback_query\"","info":"","x":290,"y":362,"wires":[]},{"id":"385615779f4b3364","type":"function","z":"ec1cf3fd9654e7e5","name":"answerCallbackQuery","func":"var text = \"You clicked \" + msg.payload.content;\nvar options = {\n // text : text, <-- you can set the text here or use msg.payload.content \n show_alert : true,\n cache_time : 10\n};\n\nmsg.payload.content = text;\nmsg.payload.options = options;\nmsg.payload.type = \"answerCallbackQuery\";\n\nreturn [ msg ];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":500,"wires":[["f7c18f49.063c4"]]},{"id":"65ca12172854cc2d","type":"telegram bot","botname":"HeinzBot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-telegrambot",
"version": "12.0.0",
"version": "13.0.0",
"description": "Telegram bot nodes for Node-RED",
"dependencies": {
"bluebird": "^3.7.2",
Expand Down
16 changes: 10 additions & 6 deletions telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2150,13 +2150,17 @@ module.exports = function (RED) {
case 'callback_query':
case 'answerCallbackQuery':
if (this.hasContent(msg)) {
// The new signature expects one object instead of three arguments.
let callbackQueryId = msg.payload.callbackQueryId;
let options = {
callback_query_id: callbackQueryId,
text: msg.payload.content,
show_alert: msg.payload.options,
};

let options = msg.payload.options;
if (options === undefined) {
options = {};
}

if (options.text === undefined) {
options.text = msg.payload.content;
}

node.telegramBot
.answerCallbackQuery(callbackQueryId, options)
.catch(function (ex) {
Expand Down

0 comments on commit 99985c4

Please sign in to comment.