sendMessage method

Future<Message> sendMessage(
  1. dynamic chat_id,
  2. String text, {
  3. String? parse_mode,
  4. List<MessageEntity>? entities,
  5. bool? disable_web_page_preview,
  6. bool? disable_notification,
  7. int? reply_to_message_id,
  8. bool? allow_sending_without_reply,
  9. ReplyMarkup? reply_markup,
})
inherited

Use this method to send text messages. On success, the sent Message is returned.

Formatting options

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

Implementation

Future<Message> sendMessage(dynamic chat_id, String text,
    {String? parse_mode,
    List<MessageEntity>? entities,
    bool? disable_web_page_preview,
    bool? disable_notification,
    int? reply_to_message_id,
    bool? allow_sending_without_reply,
    ReplyMarkup? reply_markup}) async {
  if (chat_id is! String && chat_id is! int) {
    return Future.error(TelegramException(
        'Attribute \'chat_id\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('sendMessage');
  var body = <String, dynamic>{
    'chat_id': chat_id,
    'text': text,
    'parse_mode': parse_mode,
    'entities': entities == null ? null : jsonEncode(entities),
    'disable_web_page_preview': disable_web_page_preview,
    'disable_notification': disable_notification,
    'reply_to_message_id': reply_to_message_id,
    'allow_sending_without_reply': allow_sending_without_reply,
    'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup),
  };
  return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body));
}