sendPoll method

Future<Message> sendPoll(
  1. dynamic chatId,
  2. String question,
  3. List<String> options, {
  4. int? messageThreadId,
  5. bool? isAnonymous,
  6. String? type,
  7. bool? allowsMultipleAnswers,
  8. int? correctOptionId,
  9. String? explanation,
  10. String? explanationParseMode,
  11. List<MessageEntity>? explanationEntities,
  12. int? openPeriod,
  13. int? closeDate,
  14. bool? isClosed,
  15. bool? disableNotification,
  16. bool? protectContent,
  17. int? replyToMessageId,
  18. bool? allowSendingWithoutReply,
  19. ReplyMarkup? replyMarkup,
})

Use this method to send a native poll

A native poll can't be sent to a private chat.

On success, the sent Message is returned.

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

Implementation

Future<Message> sendPoll(
    dynamic chatId, String question, List<String> options,
    {int? messageThreadId,
    bool? isAnonymous,
    String? type,
    bool? allowsMultipleAnswers,
    int? correctOptionId,
    String? explanation,
    String? explanationParseMode,
    List<MessageEntity>? explanationEntities,
    int? openPeriod,
    int? closeDate,
    bool? isClosed,
    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('sendPoll');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'message_thread_id': messageThreadId,
    'question': question,
    'options': jsonEncode(options),
    'is_anonymous': isAnonymous,
    'type': type,
    'allows_multiple_answers': allowsMultipleAnswers,
    'correct_option_id': correctOptionId,
    'explanation': explanation,
    'explanation_parse_mode': explanationParseMode,
    'explanation_entities':
        explanationEntities == null ? null : jsonEncode(explanationEntities),
    'open_period': openPeriod,
    'close_date': closeDate,
    'is_closed': isClosed,
    '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));
}