sendSticker method

Future<Message> sendSticker(
  1. dynamic chatId,
  2. dynamic sticker, {
  3. int? messageThreadId,
  4. String? emoji,
  5. bool? disableNotification,
  6. bool? protectContent,
  7. int? replyToMessageId,
  8. bool? allowSendingWithoutReply,
  9. ReplyMarkup? replyMarkup,
})

Use this method to send .webp stickers

On success, the sent Message is returned.

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

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)'));
  }
}