/// <inheritdoc /> public async Task <ApiResponseDtoModel <MessageDtoModel> > SendMessage(SendMessageDtoModel message) { using (var httpClient = GetHttpClient()) { var requestUri = new Uri( $"{_telegramBotHelperConfig.BaseUrl}{_telegramBotHelperConfig.Token}/sendmessage"); var jsonContent = JsonConvert.SerializeObject( message, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var requestContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync(requestUri, requestContent)) { var responseObject = await GetResponseObject <ApiResponseDtoModel <MessageDtoModel> >( response); return(responseObject); } } }
private SendMessageDtoModel GetSendMessageDtoModel(string chatId, string text, string parseMode, int?replyToMessageId = null, bool?disableNotification = null) { var message = new SendMessageDtoModel { ChatId = chatId, Message = text, ParseMode = parseMode, ReplyToMessageId = replyToMessageId, DisableNotification = disableNotification }; return(message); }
/// <inheritdoc /> public async Task <ApiResponseDtoModel <MessageDtoModel> > SendMessage(SendMessageDtoModel message) { using (var httpClient = GetHttpClient()) { var requestUri = new Uri( $"{_telegramBotHelperConfig.BaseUrl}{_telegramBotHelperConfig.Token}/sendmessage"); var jsonContent = JsonConvert.SerializeObject( message, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var requestContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); using (var request = await httpClient.PostAsync(requestUri, requestContent)) { var responseContent = request.Content.ReadAsStringAsync().Result; if (!request.IsSuccessStatusCode) { throw new Exception( $"Server error response:\n{request.StatusCode} {request.ReasonPhrase}\n{responseContent}"); } var responseObject = JsonConvert.DeserializeObject <ApiResponseDtoModel <MessageDtoModel> >( responseContent, new UnixDateTimeConverter()); return(responseObject); } } }