sadfasdf
sadfasdf

Reputation: 1

Reply_Message telegram bot api

i cannot understand the Reply_to_message method for telegram bot api. here is my code :

    <?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!'
  ]);
}

here when user send /start the bot send hello world text. i wanna user reply to message for sending hello world. i mean when user send /start the bot reply's to message with the text 'Hello world!'

im using webhook.

Upvotes: 0

Views: 5193

Answers (1)

Maak
Maak

Reputation: 5038

You need to add the key reply_to_message_id to the object you are posting and set the id of the message you want to reply to as the value.

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

Upvotes: 3

Related Questions