Hi!
I have a supergroup in Telegram and a Bot, which is administrator of a group. Bot is based on your code. When a new user join or left group, service message (with grey background) is appear in chat, for example
Username join to a chat
Username is join to a chat by invite link
Username is left the chat
Is it possible to catch and delete such service messages from chat with Bot API?
Thank you in advance!
Yes, you can remove them easily. These types of messages are handled by the system commands found here: https://github.com/php-telegram-bot/core/tree/master/src/Commands/SystemCommands
Namely, NewchatmembersCommand and LeftchatmemberCommand. When you look at all the other SystemCommands, you can see what other operations can be handled.
Just create your own custom version of them and simply delete the message itself in the execute() method using:
Request::deleteMessage([
'chat_id' => $this->getMessage()->getChat()->getId(),
'message_id' => $this->getMessage()->getMessageId(),
]);
Thank you for your answear and excelent library!
hi . my bot delete 50 service in 30 seconds . it shoud work very faster ! which part of my code is wrong ? please help me for solve this problem thanks.
@$newmember = $result->message->new_chat_member->id;
@$leftmember = $result->message->left_chat_member->id;
@$gpid = $result->message->chat->id;
@$messageid = $result->message->message_id;
$telegram = new telegram(TOKEN,HOST,USERNAME,PASSWORD,DBNAME);
if(!empty($newmember)|| !empty($leftmember)){
$telegram->deleteMessage($gpid,$messageid);
die();
}
Most helpful comment
Thank you for your answear and excelent library!