sendPhoto method
Use this method to send photos
On success, the sent Message is returned.
Implementation
Future<Message> sendPhoto(dynamic chatId, dynamic photo,
{int? messageThreadId,
String? caption,
String? parseMode,
List<MessageEntity>? captionEntities,
bool? hasSpoiler,
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('sendPhoto');
var body = <String, dynamic>{
'chat_id': chatId,
'message_thread_id': messageThreadId,
'caption': caption,
'parse_mode': parseMode,
'caption_entities':
captionEntities == null ? null : jsonEncode(captionEntities),
'has_spoiler': hasSpoiler,
'disable_notification': disableNotification,
'protect_content': protectContent,
'reply_to_message_id': replyToMessageId,
'allow_sending_without_reply': allowSendingWithoutReply,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
var multiPartFiles = <MultipartFile>[];
if (photo is io.File) {
multiPartFiles.add(HttpClient.toMultiPartFile(photo, 'photo'));
} else if (photo is String) {
body.addAll({'photo': photo});
} else {
return Future.error(TelegramException(
'Attribute \'photo\' can only be either io.File or String (Telegram fileId or image url)'));
}
return multiPartFiles.isEmpty
? Message.fromJson(await HttpClient.httpPost(requestUrl, body: body))
: Message.fromJson(await HttpClient.httpMultipartPost(
requestUrl, multiPartFiles,
body: body));
}