2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-22 09:57:10 +00:00

[examples] Update examples

Feature:

  * Add example demonstrating use of inline keyboards
    and callback queries (see PR #150)
  * Use token from environment variable, if available

References:

  * PR #150 - Provided example with inline keyboard and callbacks:
    https://github.com/yagop/node-telegram-bot-api/pull/150
This commit is contained in:
GochoMugo 2017-01-07 18:30:07 +03:00
parent 31a2376a1f
commit 0174b875ff
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
3 changed files with 41 additions and 3 deletions

View File

@ -4,7 +4,7 @@
*/
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const TelegramBot = require('..');
const options = {
webHook: {

View File

@ -4,7 +4,7 @@
*/
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const TelegramBot = require('..');
// See https://developers.openshift.com/en/node-js-environment-variables.html
const options = {

View File

@ -4,7 +4,7 @@
*/
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const TelegramBot = require('..');
const request = require('request');
const options = {
@ -52,3 +52,41 @@ bot.onText(/\/echo (.+)/, function onEchoText(msg, match) {
const resp = match[1];
bot.sendMessage(msg.chat.id, resp);
});
// Matches /editable
bot.onText(/\/editable/, function onEditableText(msg) {
const opts = {
reply_markup: {
inline_keyboard: [
[
{
text: 'Edit Text',
// we shall check for this value when we listen
// for "callback_query"
callback_data: 'edit'
}
]
]
}
};
bot.sendMessage(msg.from.id, 'Original Text', opts);
});
// Handle callback queries
bot.on('callback_query', function onCallbackQuery(callbackQuery) {
const action = callbackQuery.data;
const msg = callbackQuery.message;
const opts = {
chat_id: msg.chat.id,
message_id: msg.message_id,
};
let text;
if (action === 'edit') {
text = 'Edited Text';
}
bot.editMessageText(text, opts);
});