sendSticker method
Future<Message>
sendSticker(
- dynamic chat_id,
- dynamic sticker, {
- bool? disable_notification,
- int? reply_to_message_id,
- bool? allow_sending_without_reply,
- ReplyMarkup? reply_markup,
inherited
Use this method to send .webp stickers
On success, the sent Message
is returned.
Implementation
Future<Message> sendSticker(dynamic chat_id, dynamic sticker,
{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('sendSticker');
var body = <String, dynamic>{
'chat_id': chat_id,
'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),
};
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 file_id or image url)'));
}
}