@ -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 ) ;
} ) ;