douxueke5653 2016-09-01 06:45
浏览 220

如何区分“消息”更新和“回调查询”更新? (Telegram Bot API)

Sorry if my question gets too messy, I'm new here, so, any advice is welcome.

How can I differentiate between a 'Message' update and a 'Callback Query' update? I've managed to make an inline keyboard, but when I use it, the bot just hangs, he doesn't reply anything. I did a little bit of research and found this question, which helped me understand the problem, but not much else.

My bot uses something like this right now:

// read incoming info and grab the chatID
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];

switch($update["message"]["text"]){
    /* insert magic here */
}

So, this code can handle Messages, but not CallbackQueries. If I wantew to handle them, I could use something like this (based on the other question's answer):

$callback_query = $update["callback_query"]
/* same as above */

But how can I check whether it is a message or a callback query?

  • 写回答

2条回答 默认 最新

  • dota220141003 2016-11-08 08:07
    关注

    You can simply check if CallbackQuery is null or not. See the Telegram docs:

    CallbackQuery

    This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度