skip to Main Content

I am making a personal small PHP Telegram Bot. But there is a problem I want to make a function which helps me to reply to user just by replying to the message he sent. Like when a user sends a message in the Bot it will forward the message to me.I want to reply to this user by replying to the message he sent.
I tried with the help of Telegram Bot API but didnt succeed.

Here is the forwardMessage function which works

//forward msg
function forwardMessage($adminid,$chatId, $message_id){
$url = $GLOBALS["website"]."/forwardMessage 
chat_id=".$adminid."&from_chat_id=".$chatId."&message_id=".$message_id."&parse_mode=HTML";
file_get_contents($url);      
}

I tried to make a sendReply function with the help of API but it does not work

//send reply
function sendReply($userId,$message, $reply_to_message_id){
$url = $GLOBALS["website"]."/sendMessage? 
chat_id=".$userId."&text=".$message."&reply_to_message_id=".$reply_to_message_id."&parse_mode=HTML";
file_get_contents($url);      
}

2

Answers


  1. By your Question, I guess you want to make a System like Livegram Bot. Here is the Code. DM Me on Telegram @NinjaNaveen if you Need Further Help 🙂

     $admin = "xxxx" //Admin ID
        $from_id = $update->message->from->id; //User ID
        $text = $update->message->text; //Message sent by Admin
        $replytomessage = $update->message->reply_to_message //A Reply to a Message 
        $replytomessageUSERID = $update->message->reply_to_message->from->id; //User ID of the replied to message user
        $replytomessageID = $update->message->reply_to_message->message_id; //Replied to Message ID
        
        
        //////////////
        
        if (isset($replytomessage) && $from_id == $admin){ //If A Reply exists and the ID is Admin ID
        
        sendMessage($replytomessageUSERID, $text, $message_id);
        
        }
    
    Login or Signup to reply.
  2. It seems your code has some errors in declaring values, but you can try this function:

    function reply_to_message_id($chatId, $message, $message_id){
    $url = $GLOBALS[website]."/sendMessage?chat_id=".$chatId."&text=".$message."&reply_to_message_id=".$message_id."&parse_mode=HTML&disable_web_page_preview=1";
    file_get_contents($url);      
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search