/// <summary> /// [async] отправить фото TelegramBot /// </summary> public async void SendPhotoTelegramBotAsync(long chat_id, InputFileClass photo, string caption = null, string telegram_cloud_cache_id = null) { SetStatus("Отправка фото"); await Task.Run(() => { MessageClass message; if (string.IsNullOrWhiteSpace(telegram_cloud_cache_id)) { message = TelegramClient.sendPhoto(chat_id.ToString(), photo, caption, ParseModes.Markdown); } else { string uploaded_photo_cache = null; if (cache.TryGetValue(telegram_cloud_cache_id, out uploaded_photo_cache)) { message = TelegramClient.sendPhoto(chat_id.ToString(), uploaded_photo_cache, caption, ParseModes.Markdown); } else { message = TelegramClient.sendPhoto(chat_id.ToString(), photo, caption, ParseModes.Markdown); cache.Set(telegram_cloud_cache_id, message.photo[0].file_id, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(48))); } } SetStatus(null); }); }
/// <summary> /// [async] отправить документ TelegramBot /// </summary> public async void SendDocumentTelegramBotAsync(long chat_id, InputFileClass document, string caption = null) { SetStatus("Отправка документа"); await Task.Run(() => { MessageClass message = TelegramClient.sendDocument(chat_id.ToString(), document, caption); }); }
private async Task <string> SendRequest(string api_bot_method_name, NameValueCollection request_param, InputFileClass file_post) { http_response_raw = ""; if (request_param != null && !string.IsNullOrEmpty(request_param["captiom"]) && string.IsNullOrWhiteSpace(request_param["parse_mode"])) { request_param["captiom"] = HttpUtility.UrlEncode(request_param["captiom"]); } await Task.Run(() => { http_response_raw = MyWebClient.SendRequest(apiUrl + "/" + api_bot_method_name, HttpMethod.Post, request_param, new List <PostedFile>() { new PostedFile() { Data = file_post.Data, FieldName = file_post.FieldName, FileName = file_post.FileName } }, MyWebClient.RequestContentTypes.MultipartFormData); }); return(http_response_raw); }