mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 04:47:38 +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:
parent
31a2376a1f
commit
0174b875ff
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
|
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||||
const TelegramBot = require('..');
|
const TelegramBot = require('..');
|
||||||
const options = {
|
const options = {
|
||||||
webHook: {
|
webHook: {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
|
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||||
const TelegramBot = require('..');
|
const TelegramBot = require('..');
|
||||||
// See https://developers.openshift.com/en/node-js-environment-variables.html
|
// See https://developers.openshift.com/en/node-js-environment-variables.html
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
|
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||||
const TelegramBot = require('..');
|
const TelegramBot = require('..');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const options = {
|
const options = {
|
||||||
@ -52,3 +52,41 @@ bot.onText(/\/echo (.+)/, function onEchoText(msg, match) {
|
|||||||
const resp = match[1];
|
const resp = match[1];
|
||||||
bot.sendMessage(msg.chat.id, resp);
|
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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user