setGameScore method

Future<Message> setGameScore(
  1. int userId,
  2. int score, {
  3. bool? force,
  4. bool? disableEditMessage,
  5. dynamic chatId,
  6. int? messageId,
  7. String? inlineMessageId,
})

Use this method to set the score of the specified user in a game

On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the score is not greater than the user's current score in the chat and force is False.

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

Implementation

Future<Message> setGameScore(int userId, int score,
    {bool? force,
    bool? disableEditMessage,
    dynamic chatId,
    int? messageId,
    String? inlineMessageId}) async {
  if (inlineMessageId == null && (chatId == null || messageId == null)) {
    return Future.error(TelegramException(
        'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\''));
  }
  if (chatId != null && (chatId is! String && chatId is! int)) {
    return Future.error(TelegramException(
        'Attribute \'chatId\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('setGameScore');
  var body = <String, dynamic>{
    'user_id': userId,
    'score': score,
    'force': force,
    'disable_edit_message': disableEditMessage,
    'chat_id': chatId,
    'message_id': messageId,
    'inline_message_id': inlineMessageId,
  };
  return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body));
}