两个嵌入式键盘电报

时间:2018-10-15 16:40:09

标签: javascript node.js telegram-bot

我有此代码:

`
const bot = new TelegramBot(token, {polling: true});
bot.onText(/\/curse/, (msg, match) => {
 const chatId = msg.chat.id;
 bot.sendMessage(chatId, "Val?", {
  reply_markup: {
      inline_keyboard: [
          [
                {
                    text:"USD $",
                    callback_data: "USD"
                }

             ]
        ]
     }
    });
  });
bot.on('callback_query', query => {
const id = query.message.chat.id;

request('https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5', 
(err, res, body) => {
    const data = JSON.parse(body);
    const result = data.filter(item => item.ccy === query.data)[0];
    let md = `
    *${result.ccy} => ${result.base_ccy}*
        Buy: _${result.buy}_
        Sale: _${result.sale}_
    `;
    bot.sendMessage(id, md, {parse_mode: "Markdown"});
});
 });
bot.onText(/\/rasp/, (msg, match) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Day?", {
    reply_markup: {
        inline_keyboard: [
            [
                {
                    text: "Mon",
                    callback_data: "monday"
                }  
            ]
        ]
    }
})
});

如果我使用一个键盘时我遇到了错误:

 `*${result.ccy} => ${result.base_ccy}*
              ^
TypeError: Cannot read property 'ccy' of undefined`

我该如何解决?问题出在哪里呢? 当我只使用一个键盘时,我没有这个问题。 我认为它必须有自己的名字,但我不知道

0 个答案:

没有答案