node.js - handle response from telegram bot api -
i using api: https://github.com/orzfly/node-telegram-bot
it should work other.
now want bot have option update string keeps reason. on "/update" update function called, msg message object (https://core.telegram.org/bots/api#message):
link = "something"; function update(msg) { response = tg.sendmessage({ text: "send new url, please", chat_id: msg.chat.id, reply_to_message_id: msg.message_id, reply_markup: { force_reply: true, selective: true } }); console.log("response: " + response); // on reply want update link } now bot asks me provide new string. next answer in telegram answer bots request, because of force_reply. how answer? 'response' here promise object , don't know it.
after reading promises objects, tried this:
response.then(function successhandler(result) { tg.sendmessage({ text: "new url is: don't know", chat_id: msg.chat.id }); }, function failurehandler(error) { colsole.log("error: " + error); }); but didn't work. in no way.
i don't know reply message object from. hope it's clear asking. otherwise let me know.
if understood right, you're trying next message user , treat new string; problem is: response contain response telegram servers stating result of message tried send; has nothing user's response message;
in order this, need control last message bot sent user and, based on that, decide how handle user's next message; this:
link = "something"; states = {} function update(msg) { if (!states[msg.chat.id] || states[msg.chat.id] == 1) { tg.sendmessage({ text: "send new url, please", chat_id: msg.chat.id, reply_to_message_id: msg.message_id, reply_markup: { force_reply: true, selective: true } }).then(() => { states[msg.chat.id] = 2 console.log(`asked question ${msg.chat.id}`); }); } else { link = msg.text; tg.sendmessage({ text: `new url is: ${link}`, chat_id: msg.chat.id, reply_to_message_id: msg.message_id }) } }
Comments
Post a Comment