I’m writing a telegram bot to delete spam from a channel where the bot is administrator (with permission to delete messages)
I’m doing some tests using PHP and telegram-bot-sdk 2.0
I’m able to answer to messages using the bot, but if I try to delete a specific message nothing happens, and the method always returns false
require 'vendor/autoload.php';
use TelegramBotApi;
$client = new Api('[api key here]');
$last_update_id=0;
while(true){
$response = $client->getUpdates(['offset'=>$last_update_id, 'timeout'=>5]);
if (count($response)<=0) continue;
foreach ($response as $r){
//Get the message somebody sent
$last_update_id=$r->getUpdateId()+1;
$message=$r->getMessage();
$messageId = $message['message_id'];
$chat = $message['chat'];
$chatId = $chat['id'];
//Log to console the message received
echo "Somebody said: ".$message['text']." with message id: ".$messageId." on chat ".$chatId."n";
//Answering works
$ret = $client->sendMessage(['chat_id' => $chatId, 'text' => 'I'm deleting your message!']);
//Deleting doesn't work
$ret = $client->deleteMessage([ 'chat_id' => $chatId, 'message_id' => $messageId]);
echo "ret:".($ret?"true":"false");
}
}
Any Advice?
I’m not even 100% sure deleteMessage() is a method of $client (according the documentation it seems so, but it’s not totally clear) because if it mispell the method on purposes like deleteMessagx() I get false and no error.