getUpdates method

Future<List<Update>> getUpdates({
  1. int? offset,
  2. int? limit,
  3. int? timeout,
  4. List<String>? allowedUpdates,
})

Use this method to receive incoming updates using long polling (wiki)

An Array of Update objects is returned.

Notes

  1. This method will not work if an outgoing webhook is set up.
  2. In order to avoid getting duplicate updates, recalculate offset after each server response.

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

Implementation

Future<List<Update>> getUpdates(
    {int? offset,
    int? limit,
    int? timeout,
    List<String>? allowedUpdates}) async {
  var requestUrl = _apiUri('getUpdates', {
    'offset': ['$offset'],
    'limit': ['$limit'],
    'timeout': ['$timeout'],
    'allowed_updates': [jsonEncode(allowedUpdates)]
  });

  return (await HttpClient.httpGet(requestUrl).timeout(
          Duration(milliseconds: ((timeout ?? 0) * 1.1 * 1000).round())))
      .map<Update>((update) => Update.fromJson(update))
      .toList();
}