电报机器人从用户那里得到回复消息

时间:2019-02-20 13:40:55

标签: php telegram-bot

我有以下代码:

define('API_KEY','*********************');
$update = json_decode(file_get_contents('php://input'));

$text = $update->message->text;
$chat_id = $update->message->chat->id;
$message_id = $update->callback_query->message->message_id;
$reply = $update->message->reply_to_message->text;
$rpto = $update->message->reply_to_message->forward_from->id;
$nowdate = date("Y-m-d");

function coding($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,$datas);
    $res = curl_exec($ch);
    if(curl_error($ch)){
        var_dump(curl_error($ch));
    }else{
        return json_decode($res);
    }
}

和:

if ($text == "name") {
  coding('sendMessage',[
    'chat_id'=>$chat_id,
    'message_id'=>$message_id,
    'text'=> "Your Name :",
    'parse_mode'=>'html',
    'reply_markup' => json_encode(['force_reply' => true,'selective' => false])
  ]);
mysqli_query($connect,"INSERT INTO users_details (chat_id,date,name) VALUES ('$chat_id','$nowdate','$reply')"); 
}

,它工作正常,我想问用户一个问题,然后从答复中得到她的答案并存储在数据库中,但是听起来$reply没有得到用户消息,所以我可以这样做错误吗?

0 个答案:

没有答案