setChatPhoto method

Future<bool> setChatPhoto(
  1. dynamic chatId,
  2. File photo
)

Use this method to set a profile photo for the chat

Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Returns True on success.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

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

Implementation

Future<bool> setChatPhoto(dynamic chatId, io.File photo) 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('setChatPhoto');
  var body = <String, dynamic>{'chat_id': chatId};
  // filename cannot be empty to post to Telegram server
  var files = List<MultipartFile>.filled(
      1,
      MultipartFile('photo', photo.openRead(), photo.lengthSync(),
          filename: '${photo.lengthSync()}'));
  return await HttpClient.httpMultipartPost(requestUrl, files, body: body);
}