/// <summary> /// Process the calling request and returns <see cref="ParsedCallingRequest"/>. /// </summary> /// <param name="callType"> The type of calling request.</param> /// <returns> the parsed calling request.</returns> public virtual async Task<ParsedCallingRequest> ProcessRequest(CallRequestType callType) { ParsedCallingRequest parsedRequest; switch (callType) { case CallRequestType.IncomingCall: parsedRequest = await ProcessIncomingCallAsync(); break; case CallRequestType.CallingEvent: parsedRequest = await ProcessCallingEventAsync(); break; default: parsedRequest = GenerateParsedResults(HttpStatusCode.InternalServerError); break; } parsedRequest.SkypeChaindId = ExtractSkypeChainId(); return parsedRequest; }
/// <summary> /// Process a calling request within the calling conversaion. /// </summary> /// <param name="toBot"> The calling request sent to the bot.</param> /// <param name="callRequestType"> The type of calling request.</param> /// <returns> The response from the bot.</returns> public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage toBot, CallRequestType callRequestType) { using (var scope = CallingModule.BeginLifetimeScope(Container, toBot)) { var bot = scope.Resolve<ICallingBot>(); var context = scope.Resolve<CallingContext>(); var parsedRequest = await context.ProcessRequest(callRequestType); Trace.TraceInformation($"Processing X-Microsoft-Skype-Chain-ID: {parsedRequest.SkypeChaindId}"); if (parsedRequest.Faulted()) { return context.Request.CreateResponse(parsedRequest.ParseStatusCode); } else { try { string res = string.Empty; switch (callRequestType) { case CallRequestType.IncomingCall: res = await bot.CallingBotService.ProcessIncomingCallAsync(parsedRequest.Content); break; case CallRequestType.CallingEvent: res = await bot.CallingBotService.ProcessCallbackAsync(parsedRequest.Content, parsedRequest.AdditionalData); break; default: throw new Exception($"Unsupported call request type: {callRequestType}"); } return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(res, Encoding.UTF8, "application/json") }; } catch (Exception e) { return context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e); } } } }
/// <summary> /// Process the calling request and returns <see cref="ParsedCallingRequest"/>. /// </summary> /// <param name="callType"> The type of calling request.</param> /// <returns> the parsed calling request.</returns> public virtual async Task <ParsedCallingRequest> ProcessRequest(CallRequestType callType) { ParsedCallingRequest parsedRequest; switch (callType) { case CallRequestType.IncomingCall: parsedRequest = await ProcessIncomingCallAsync(); break; case CallRequestType.CallingEvent: parsedRequest = await ProcessCallingEventAsync(); break; default: parsedRequest = GenerateParsedResults(HttpStatusCode.BadRequest, $"{callType} not accepted"); break; } parsedRequest.SkypeChainId = ExtractSkypeChainId(this.Request); return(parsedRequest); }
public static async Task <IActionResult> SendAsync(HttpRequest toBot, CallRequestType callRequestType) #endif { using (var scope = CallingModule.BeginLifetimeScope(Container, toBot)) { var bot = scope.Resolve <ICallingBot>(); var context = scope.Resolve <CallingContext>(); var parsedRequest = await context.ProcessRequest(callRequestType); Trace.TraceInformation($"Processing X-Microsoft-Skype-Chain-ID: {parsedRequest.SkypeChainId}"); if (parsedRequest.Faulted()) { #if NET46 return(context.Request.CreateResponse(parsedRequest.ParseStatusCode)); #else return(new StatusCodeResult((int)parsedRequest.ParseStatusCode)); #endif } else { try { string res = string.Empty; switch (callRequestType) { case CallRequestType.IncomingCall: res = await bot.CallingBotService.ProcessIncomingCallAsync(parsedRequest.Content); break; case CallRequestType.CallingEvent: res = await bot.CallingBotService.ProcessCallbackAsync(parsedRequest.Content, parsedRequest.AdditionalData); break; default: throw new Exception($"Unsupported call request type: {callRequestType}"); } #if NET46 return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(res, Encoding.UTF8, "application/json") }); #else return(new ContentResult { Content = res, ContentType = "application/json", StatusCode = 200 }); #endif } catch (Exception e) { #if NET46 return(context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); #else // TODO show exception in some more salient way e.g. in logs. // Because an exception will be thrown for invalid CallbackUrl. return(new ObjectResult(new { Type = e.GetType().FullName, Message = e.Message }) { StatusCode = 500 }); #endif } } } }
/// <summary> /// Process a calling request within the calling conversaion. /// </summary> /// <param name="toBot"> The calling request sent to the bot.</param> /// <param name="callRequestType"> The type of calling request.</param> /// <returns> The response from the bot.</returns> #if NET46 public static async Task <HttpResponseMessage> SendAsync(HttpRequestMessage toBot, CallRequestType callRequestType)
/// <summary> /// Process a calling request within the calling conversaion. /// </summary> /// <param name="toBot"> The calling request sent to the bot.</param> /// <param name="callRequestType"> The type of calling request.</param> /// <returns> The response from the bot.</returns> public static async Task <HttpResponseMessage> SendAsync(HttpRequestMessage toBot, CallRequestType callRequestType) { using (var scope = CallingModule.BeginLifetimeScope(Container, toBot)) { var bot = scope.Resolve <ICallingBot>(); var context = scope.Resolve <CallingContext>(); var parsedRequest = await context.ProcessRequest(callRequestType); Trace.TraceInformation($"Processing X-Microsoft-Skype-Chain-ID: {parsedRequest.SkypeChainId}"); if (parsedRequest.Faulted()) { return(context.Request.CreateResponse(parsedRequest.ParseStatusCode)); } else { try { string res = string.Empty; switch (callRequestType) { case CallRequestType.IncomingCall: res = await bot.CallingBotService.ProcessIncomingCallAsync(parsedRequest.Content); break; case CallRequestType.CallingEvent: res = await bot.CallingBotService.ProcessCallbackAsync(parsedRequest.Content, parsedRequest.AdditionalData); break; default: throw new Exception($"Unsupported call request type: {callRequestType}"); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(res, Encoding.UTF8, "application/json") }); } catch (Exception e) { return(context.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } } } }