1
votes

I am using irazasyed.github.io Telegram SDK for sending message here is my code when I send message to bot nothing happen and no reply receives Where is the problem ?

MY_BOT_TOKEN is replaced

<?php

require 'vendor/autoload.php';

use Telegram\Bot\Api;

$telegram = new Api('MY_BOT_TOKEN');

$update = json_decode( file_get_contents( 'php://input' ) ); 
$chat_id = $update->getMessage()->getChat()->getId();

$response = $telegram->sendMessage([
    'chat_id' => $chat_id; 
    'text' => 'Hello World'
]);
$response->getMessageId();

?>
1
I am fairly certain that the function json_decode does not return an object that has those methods. Correct me if I'm wrong, but you should be getting an error stating that the $update object does not have those methods. For more information on what the json_decode function should return, check out the manual page for that function. - meun5

1 Answers

1
votes

need to do some changes:

$update = json_decode( file_get_contents( 'php://input' ) , true); 
$chat_id = $update->getMessage->getChat->getId();