Core: Delete all messages in chat from none-admin users

Created on 22 Jan 2018  路  2Comments  路  Source: php-telegram-bot/core

Hi!

Is it possible? I have a supergroup with invite link. I want the bot to delete all messages from none-admin users.

For example:
User writes "Hi everyone"
And bot delete message at once.

How should the command look like? Do I need to change the Request::sendMessage method in vendor?

Thanks you a lot!

Most helpful comment

In GenericmessageCommand you can check if the user is an admin, if not, delete the message:
(untested, but you get the idea)

$message    = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id    = $message->getChat()->getId();
$user_id    = $message->getFrom()->getId();

if (!$this->getTelegram()->isAdmin($user_id)) {
    return Request::deleteMessage(compact('message_id', 'chat_id'));
}

All 2 comments

In GenericmessageCommand you can check if the user is an admin, if not, delete the message:
(untested, but you get the idea)

$message    = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id    = $message->getChat()->getId();
$user_id    = $message->getFrom()->getId();

if (!$this->getTelegram()->isAdmin($user_id)) {
    return Request::deleteMessage(compact('message_id', 'chat_id'));
}

@noplanman thank you a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smaznet picture smaznet  路  4Comments

TheSleepySlee picture TheSleepySlee  路  3Comments

NabiKAZ picture NabiKAZ  路  3Comments

ttvd94 picture ttvd94  路  4Comments

abbe-cipher picture abbe-cipher  路  4Comments