I want to remove this service messages from my channel:
bot pinned 芦new message...禄
This is quite easy actually!
When the bot (or any other user) pins a message, a new message object is sent to the bot, which is then handled by the GenericmessageCommand.
So in the execute method you can put the following:
$message = $this->getMessage();
if ($message && $message->getPinnedMessage()) {
return Request::deleteMessage([
'chat_id' => $message->getChat()->getId(),
'message_id' => $message->getMessageId(),
]);
}
This is quite easy actually!
When the bot (or any other user) pins a message, a new message object is sent to the bot, which is then handled by the
GenericmessageCommand.So in the
executemethod you can put the following:$message = $this->getMessage(); if ($message && $message->getPinnedMessage()) { return Request::deleteMessage([ 'chat_id' => $message->getChat()->getId(), 'message_id' => $message->getMessageId(), ]); }
Thanks @noplanman ...
It seems that the deleteMessage never executed...
Request::pinChatMessage([
'chat_id' => $channel_id,
'message_id' => $send_message_id,
'disable_notification' => false,
]);
I put following to GenericmessageCommand's execute method and run above in SurveyCommand, but nothing happened after message pin!
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
if ($message && $message->getPinnedMessage()) {
Request::sendMessage([
'chat_id' => 'My Telegram user ID',
'text' => print_r($message, 1),
]);
return Request::deleteMessage([
'chat_id' => $chat_id,
'message_id' => $message->getMessageId(),
]);
}
You might have to create ChannelpostCommand and put that code there - replace getMessage() with getChannelPost().
@WISTFUL12 I assume it works now and we can close this off?
Most helpful comment
This is quite easy actually!
When the bot (or any other user) pins a message, a new message object is sent to the bot, which is then handled by the
GenericmessageCommand.So in the
executemethod you can put the following: