restrictChatMember method

Future<bool> restrictChatMember(
  1. dynamic chatId,
  2. int userId,
  3. ChatPermissions permissions, {
  4. bool? useIndependentChatPermissions,
  5. int? untilDate,
})

Use this method to restrict a user in a supergroup

The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.

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

This method now takes the new user permissions in a single argument of the type ChatPermissions. The old way of passing parameters will keep working for a while for backward compatibility.

Implementation

Future<bool> restrictChatMember(
    dynamic chatId, int userId, ChatPermissions permissions,
    {bool? useIndependentChatPermissions, int? untilDate}) 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('restrictChatMember');
  var body = <String, dynamic>{
    'chat_id': chatId,
    'user_id': userId,
    'permissions': jsonEncode(permissions),
    'use_independent_chat_permissions': useIndependentChatPermissions,
    'until_date': untilDate,
  };
  return await HttpClient.httpPost(requestUrl, body: body);
}