电报游戏机器人没有响应

时间:2018-08-03 13:59:47

标签: telegram

我正在使用nodejs api制作电报机器人。我遵循了本教程:whitelisted exceptions

我成功设置了机器人串联按钮,但是当我按下Play Game按钮时,什么也没发生。

如何确定调用了answerCallbackQuery

var TelegramBot = require("node-telegram-bot-api");
var bot = new TelegramBot("YOUR_TOKEN", { polling: true });

var GAME_SHORT_NAME = 'test';

bot.onText(/\/start/, function (msg) {
    bot.sendMessage(
        msg.from.id, "Hi <b>" + msg.from.first_name + "</> " + msg.from.last_name + "\nLet's play game!",
        {
            parse_mode: "HTML"
        }
    );
});

bot.onText(/\/GameStart (.+)/, function (msg, match) { 
    var fromId = msg.from.id;

    switch (match[1]) {
        case GAME_SHORT_NAME:
            bot.sendGame(
                fromId,
                GAME_SHORT_NAME,
                {
                    reply_markup: JSON.stringify({
                        inline_keyboard: [
                            [{ text: "GameStart", callback_game: JSON.stringify({ game_short_name: GAME_SHORT_NAME }) }],
                            [{ text: "Share", url: "t.me/dygamesGameTestBot?game=test" }]
                        ]
                    })
                }
            );
            break;
        default:
            bot.sendMessage(fromId, "Sorry " + msg.from.first_name + ", but this game does' t exist..");

    }

});

bot.on("callback_query", function (cq) {
    if (cq.game_short_name) {
        switch (cq.game_short_name) {
            case GAME_SHORT_NAME:
                console.log(bot.answerCallbackQuery(cq.id, undefined, false, JSON.stringify({ url: "https://tbot.xyz/math/" })));
                return;
        }
        bot.answerCallbackQuery(cq.id, "Sorry, '" + cq.game_short_name + "' is not available.", true);
    }
})

bot.on("inline_query", function (iq) {
    bot.answerInlineQuery(iq.id, [{ type: "game", id: "0", game_short_name: GAME_SHORT_NAME }]);
});

控制台显示:

Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _cancellationParent:
   Promise {
     _bitField: 1,
     _fulfillmentHandler0: undefined,
     _rejectionHandler0: [Function],
     _promise0: [Circular],
     _receiver0: undefined,
     _cancellationParent:
      Promise {
        _bitField: 1,
        _fulfillmentHandler0: [Function],
        _rejectionHandler0: undefined,
        _promise0: [Circular],
        _receiver0: undefined,
        _onCancelField: [Function],
        _branchesRemainingToCancel: 1 },
     _branchesRemainingToCancel: 1 } }

0 个答案:

没有答案