Core: How to remove service messages from Telegram?

Created on 24 Dec 2017  路  3Comments  路  Source: php-telegram-bot/core

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!

Most helpful comment

Thank you for your answear and excelent library!

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohsenshahab picture mohsenshahab  路  4Comments

Recouse picture Recouse  路  3Comments

Bl0ck154 picture Bl0ck154  路  3Comments

abbe-cipher picture abbe-cipher  路  4Comments

tchibomann picture tchibomann  路  3Comments