2016-11-05 219 views
0

我正在使用irazasyed.github.io電報SDK發送消息 這裏是我的代碼,當我發送消息給機器人什麼都沒有發生,沒有回覆收到 問題在哪裏?Telegram bot發送消息

MY_BOT_TOKEN被替換

<?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(); 

?> 
+0

我相當肯定的是,功能'json_decode'不返回有這些方法的對象。糾正我,如果我錯了,但你應該得到一個錯誤,指出'$ update'對象沒有這些方法。有關'json_decode'函數應該返回的更多信息,請查看該函數的[manual page](https://secure.php.net/manual/en/function.json-decode.php)。 – meun5

回答

0

需要做一些改變:

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