【问题标题】:Reply_Message telegram bot apiReply_Message 电报机器人 api
【发布时间】:2017-02-14 21:42:24
【问题描述】:

我无法理解电报机器人 api 的 Reply_to_message 方法。这是我的代码:

    <?php

define('API_KEY','My_token');

function bot($method,$datas=[]){
    $url = "https://api.telegram.org/bot".API_KEY."/".$method;
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($datas));
    $res = curl_exec($ch);
    if(curl_error($ch)){
        var_dump(curl_error($ch));
    }else{
        return json_decode($res);
    }
}

$update = json_decode(file_get_contents('php://input'));

if($update->message->text == '/start'){
  bot('sendMessage',[
    'chat_id'=>$update->message->chat->id,
    'text'=>'Hello word!'
  ]);
}

当用户发送/启动机器人时,这里发送 hello world 文本。我想用户回复发送 hello world 的消息。我的意思是当用户发送/启动机器人回复到带有文本“Hello world!”的消息时

我正在使用 webhook。

【问题讨论】:

    标签: telegram-bot


    【解决方案1】:

    您需要将reply_to_message_id键添加到您正在发布的对象中,并将您要回复的消息的id设置为值。

    if($update->message->text == '/start'){
      bot('sendMessage',[
        'chat_id'=>$update->message->chat->id,
        'text'=>'Hello word!',
        'reply_to_message_id' => $update->message->message_id
      ]);
    }
    

    【讨论】:

    • 它不起作用。它就像第一个代码一样,不作为回复发送。
    • 密钥称为message_id ($update-&gt;message-&gt;message_id)。我更新了我的答案
    • 抱歉,您知道如何在 php 上通过机器人发送贴纸吗?
    • 这是一个不同的问题,但请查看sendSticker
    • 你能举个例子吗?
    猜你喜欢
    • 2017-08-18
    • 2017-10-24
    • 2015-07-21
    • 2016-03-22
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 2020-10-28
    相关资源
    最近更新 更多