deleteMessage method

Future<bool> deleteMessage(
  1. dynamic chatId,
  2. int messageId
)

Use this method to delete a message, including service messages

It has the following limitations:

  • A message can only be deleted if it was sent less than 48 hours ago.
  • Bots can delete outgoing messages in groups and supergroups.
  • Bots can delete incoming messages in private chats.
  • Bots granted canPostMessages permissions can delete outgoing messages in channels.
  • If the bot is an administrator of a group, it can delete any message there.
  • If the bot has canDeleteMessages permission in a supergroup or a channel, it can delete any message there.

Returns True on success.

https://core.telegram.org/bots/api#deletemessage

Implementation

Future<bool> deleteMessage(dynamic chatId, int messageId) async {
  if (chatId is! String && chatId is! int) {
    return Future.error(TelegramException(
        'Attribute \'chatId\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('deleteMessage');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'message_id': messageId,
  };
  return await HttpClient.httpPost(requestUrl, body: body);
}