sendMessage method
Use this method to send text messages. On success, the sent Message is returned.
Implementation
Future<Message> sendMessage(dynamic chatId, String text,
{int? messageThreadId,
String? parseMode,
List<MessageEntity>? entities,
bool? disableWebPagePreview,
bool? disableNotification,
bool? protectContent,
int? replyToMessageId,
bool? allowSendingWithoutReply,
ReplyMarkup? replyMarkup}) 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('sendMessage');
var body = <String, dynamic>{
'chat_id': chatId,
'message_thread_id': messageThreadId,
'text': text,
'parse_mode': parseMode,
'entities': entities == null ? null : jsonEncode(entities),
'disable_web_page_preview': disableWebPagePreview,
'disable_notification': disableNotification,
'protect_content': protectContent,
'reply_to_message_id': replyToMessageId,
'allow_sending_without_reply': allowSendingWithoutReply,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body));
}