telenode-js
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -27,2 +27,9 @@ const Telenode = require('../src/bot'); | ||
bot.onButton('', callbackQuery => { | ||
bot.sendTextMessage( | ||
'The random button was pressed, it was targeted via the button handler with empty string parameter', | ||
callbackQuery.message.chat.id, | ||
); | ||
}); | ||
const inlineKeyboard = [ | ||
@@ -45,2 +52,8 @@ [ | ||
], | ||
[ | ||
{ | ||
text: 'Random button (onButton with empty string)', | ||
callback_data: 'random', | ||
}, | ||
], | ||
]; |
{ | ||
"name": "telenode-js", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Lightweight Telegram API framework for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,2 +14,3 @@ const { runServer } = require('./server'); | ||
this.buttonHandlers = {}; | ||
this.anyButtonHandler = null; | ||
this.#baseUrl = 'https://api.telegram.org/bot' + apiToken; | ||
@@ -91,3 +92,8 @@ this.#secretToken = secretToken; | ||
buttonHandler(callbackQuery); | ||
return; | ||
} | ||
// Similar to the text message handler, this should be the final step to validate that no matches occurred | ||
if (this.anyButtonHandler) { | ||
this.anyButtonHandler(callbackQuery); | ||
} | ||
} | ||
@@ -111,6 +117,10 @@ | ||
onButton(buttonDataTrigger, handler) { | ||
if (!buttonDataTrigger || typeof buttonDataTrigger !== 'string') { | ||
if (typeof buttonDataTrigger !== 'string') { | ||
return; | ||
} | ||
this.buttonHandlers[buttonDataTrigger] = handler; | ||
if (buttonDataTrigger === '') { | ||
this.anyButtonHandler = handler; | ||
} else { | ||
this.buttonHandlers[buttonDataTrigger] = handler; | ||
} | ||
} | ||
@@ -117,0 +127,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20129
449