editMessageReplyMarkup method

Future<Message> editMessageReplyMarkup({
  1. dynamic chatId,
  2. int? messageId,
  3. String? inlineMessageId,
  4. InlineKeyboardMarkup? replyMarkup,
})

Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

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

Implementation

Future<Message> editMessageReplyMarkup(
    {dynamic chatId,
    int? messageId,
    String? inlineMessageId,
    InlineKeyboardMarkup? replyMarkup}) async {
  if (inlineMessageId == null && (chatId == null || messageId == null)) {
    return Future.error(TelegramException(
        'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\''));
  }
  if (chatId != null && (chatId is! String && chatId is! int)) {
    return Future.error(TelegramException(
        'Attribute \'chatId\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('editMessageReplyMarkup');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'message_id': messageId,
    'inline_message_id': inlineMessageId,
    'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
  };
  var res = await HttpClient.httpPost(requestUrl, body: body);
  if (res == true) {
    return Future.error(
        TelegramException('Edited message is NOT sent by the bot'));
  } else {
    return Message.fromJson(res);
  }
}