sendSticker method
Use this method to send .webp stickers
On success, the sent Message is returned.
Implementation
Future<Message> sendSticker(dynamic chatId, dynamic sticker,
{int? messageThreadId,
String? emoji,
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('sendSticker');
var body = <String, dynamic>{
'chat_id': chatId,
'message_thread_id': messageThreadId,
'emoji': emoji,
'disable_notification': disableNotification,
'protect_content': protectContent,
'reply_to_message_id': replyToMessageId,
'allow_sending_without_reply': allowSendingWithoutReply,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
if (sticker is io.File) {
// filename cannot be empty to post to Telegram server
var files = List<MultipartFile>.filled(
1,
MultipartFile('sticker', sticker.openRead(), sticker.lengthSync(),
filename: '${sticker.lengthSync()}'));
return Message.fromJson(
await HttpClient.httpMultipartPost(requestUrl, files, body: body));
} else if (sticker is String) {
body.addAll({'sticker': sticker});
return Message.fromJson(
await HttpClient.httpPost(requestUrl, body: body));
} else {
return Future.error(TelegramException(
'Attribute \'sticker\' can only be either io.File or String (Telegram fileId or image url)'));
}
}