public Task Post() { using var reader = new StreamReader(Request.Body); string body = reader.ReadToEnd(); var aliceRequest = JsonConvert.DeserializeObject <AliceRequest>(body, ConverterSettings); if (aliceRequest?.IsPing() == true) { AliceResponseBase <UserState, SessionState> pongResponse = new AliceResponse(aliceRequest).ToPong(); string stringPong = JsonConvert.SerializeObject(pongResponse, ConverterSettings); return(Response.WriteAsync(stringPong)); } string userId = aliceRequest.Session.UserId; string token = ExtractToken(Request); Console.WriteLine($"REQUEST FROM {userId}:\n{body}\n"); AliceResponse aliceResponse = _aliceService.HandleRequest(aliceRequest, token); string stringResponse = JsonConvert.SerializeObject(aliceResponse, ConverterSettings); Console.WriteLine($"RESPONSE:\n{stringResponse}\n"); return(Response.WriteAsync(stringResponse)); }
public Task Post() { using var reader = new StreamReader(Request.Body); var body = reader.ReadToEnd(); var request = JsonConvert.DeserializeObject<AliceRequest>(body, Utils.ConverterSettings); if (request == null) { Console.WriteLine("Request is null:"); Console.WriteLine(body); return Response.WriteAsync("Request is null"); } if (request.IsPing()) { var pong = new AliceResponse(request).ToPong(); var pongResponse = JsonConvert.SerializeObject(pong, Utils.ConverterSettings); return Response.WriteAsync(pongResponse); } Console.WriteLine($"REQUEST:\n{JsonConvert.SerializeObject(request, Utils.ConverterSettings)}\n"); var response = _aliceService.HandleRequest(request); var stringResponse = JsonConvert.SerializeObject(response, Utils.ConverterSettings); Console.WriteLine($"RESPONSE:\n{stringResponse}\n"); return Response.WriteAsync(stringResponse); }
public Task Post() { using var reader = new StreamReader(Request.Body); string body = reader.ReadToEnd(); var request = JsonConvert.DeserializeObject <AliceRequest>(body, ConverterSettings); if (request == null) { Console.WriteLine("Request is null:"); Console.WriteLine(body); return(Response.WriteAsync("Request is null")); } if (request.IsPing()) { AliceResponseBase <UserState, SessionState> pong = new AliceResponse(request).ToPong(); string pongResponse = JsonConvert.SerializeObject(pong, ConverterSettings); return(Response.WriteAsync(pongResponse)); } Console.WriteLine($"REQUEST:\n{JsonConvert.SerializeObject(request, ConverterSettings)}\n"); try { AliceResponse response = _aliceService.HandleRequest(request); string stringResponse = JsonConvert.SerializeObject(response, ConverterSettings); Console.WriteLine($"RESPONSE:\n{stringResponse}\n"); return(Response.WriteAsync(stringResponse)); } catch (Exception e) { Console.WriteLine(e); return(Response.WriteAsync( JsonConvert.SerializeObject( new Phrase("Возникла какая-то ошибка, разработчик уже уведомлён").Generate(request), ConverterSettings ) )); } }