private BotUpdateRequest getUpdateObject(Stream streamBody) { BotUpdateRequest result = new BotUpdateRequest(); var streamBodyLength = streamBody.CanRead; logger.LogWarning("CanRead Value: {0}", streamBodyLength); var bodyStream = new StreamReader(streamBody); string jsonString = String.Empty; try { bodyStream = new StreamReader(streamBody); jsonString = bodyStream.ReadToEnd(); logger.LogWarning("JSON String: {0}", jsonString); // Debug: Should be converted to a test jsonString = getJSONFromFile(); JsonConvert.PopulateObject(jsonString, result); } catch (Exception ex) { string exception = ex.Message; logger.LogWarning("Error Message: {0}", exception); } finally { if (bodyStream != null) { bodyStream.Close(); } } return(result); }
public async Task <IActionResult> HandleBotUpdate([FromNewtonsoftJsonBody] Update update, CancellationToken cancellation = default) { var request = new BotUpdateRequest(update); await _mediator.Send(request, cancellation); return(Ok()); }
public IActionResult PostJSON() { logger.LogInformation("Starting PostJSON Logging", null); var requestBody = HttpContext.Request.Body; var requestLength = HttpContext.Request.ContentLength; Task <string> jsonContentAsync = getJSONContent(requestBody); var jsonContent = jsonContentAsync.Result; logger.LogInformation("JSON Content: " + jsonContent); logger.LogInformation("Body Length: " + requestLength.ToString()); BotUpdateRequest allRequests = new BotUpdateRequest(); Result result = new Result(); UpdateResultHandler updateResultHandler = new UpdateResultHandler(); var returnString = "Hello from Chuckbot"; if (jsonContent.Contains("result")) { logger.LogInformation("JSON Contains RESULT! Total Results: " + allRequests.result.Count.ToString()); JsonConvert.PopulateObject(jsonContent, allRequests); foreach (Result currentResult in allRequests.result) { var currentMessage = currentResult.message; updateResultHandler.ProcessUpdateRequest(currentMessage); } } else { try { logger.LogInformation("Simple Update Request - Attempting to Serialize JSON"); JsonConvert.PopulateObject(jsonContent, result); updateResultHandler.ProcessUpdateRequest(result.message); } catch (JsonException ex) { returnString = ex.Message; logger.LogError("Error Serializing SimpleJSON: " + ex.Message); } } return(Ok(returnString)); }