public SendReplyResponse SendReply(string conversationId, SendReplyRequest message) { _baseRoute = "conversations/{conversation_id}/messages"; var request = base.BuildRequest(Method.POST); request.AddParameter("conversation_id", conversationId, ParameterType.UrlSegment); if (message.HasAttachments()) { var parameters = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(Mapper.Map <SendReplyMultipartFormRequest>(message), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); foreach (var p in parameters) { request.AddParameter(p.Key.ToString(), p.Value); } for (int i = 0; i < message.Attachments.Count(); i++) { var attach = message.Attachments[i]; var file = File.ReadAllBytes(attach.Path); var fileParam = FileParameter.Create($"attachments[{i}]", file, attach.Name, attach.ContentType); request.Files.Add(fileParam); } request.AlwaysMultipartFormData = true; return(_client.Execute <SendReplyResponse>(request)); } else { return(_client.Execute <SendReplyResponse>(request, message)); } }
public async Task <IActionResult> SendReply([FromForm] SendReplyRequest request) { var response = await mediator.Send(request); logger.LogResponse( $"User #{HttpContext.GetCurrentUserId()} sent reply #{response?.Reply?.Id} to report #{request.ReportId}", response.Error); return(this.CreateResponse(response)); }
public SendReplyResponse SendReply(string conversationId, SendReplyRequest message) { _baseRoute = "conversations/{conversation_id}/messages"; var request = base.BuildRequest(Method.POST); request.AddParameter("conversation_id", conversationId, ParameterType.UrlSegment); if (message.HasAttachments()) { // Manually map SendReplyRequest to SendReplyMultipartFormRequest (AutoMapper broke w 3.1 update) SendReplyMultipartFormRequest sendReplyMultipartFormRequest = new SendReplyMultipartFormRequest { AuthorId = message.AuthorId, SenderName = message.SenderName, Subject = message.Subject, Body = message.Body, Text = message.Text, Attachments = message.Attachments, Options = message.Options, To = message.To, Cc = message.Cc, Bcc = message.Bcc, }; var parameters = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(sendReplyMultipartFormRequest, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); foreach (var p in parameters) { request.AddParameter(p.Key.ToString(), p.Value); } for (int i = 0; i < message.Attachments.Count(); i++) { var attach = message.Attachments[i]; var file = File.ReadAllBytes(attach.Path); var fileParam = FileParameter.Create($"attachments[{i}]", file, attach.Name, attach.ContentType); request.Files.Add(fileParam); } request.AlwaysMultipartFormData = true; return(_client.Execute <SendReplyResponse>(request)); } else { return(_client.Execute <SendReplyResponse>(request, message)); } }