/// <summary> /// /// </summary> /// <param name="requestEnvelope"></param> /// <returns></returns> private async Task<string> DoProcessRequestAsync(SpeechletRequestEnvelope requestEnvelope) { Session session = requestEnvelope.Session; SpeechletResponse response = null; // process launch request if (requestEnvelope.Request is LaunchRequest) { var request = requestEnvelope.Request as LaunchRequest; if (requestEnvelope.Session.IsNew) { await OnSessionStartedAsync( new SessionStartedRequest(request.RequestId, request.Timestamp), session); } response = await OnLaunchAsync(request, session); } // process intent request else if (requestEnvelope.Request is IntentRequest) { var request = requestEnvelope.Request as IntentRequest; // Do session management prior to calling OnSessionStarted and OnIntentAsync // to allow dev to change session values if behavior is not desired DoSessionManagement(request, session); if (requestEnvelope.Session.IsNew) { await OnSessionStartedAsync( new SessionStartedRequest(request.RequestId, request.Timestamp), session); } response = await OnIntentAsync(request, session); } // process session ended request else if (requestEnvelope.Request is SessionEndedRequest) { var request = requestEnvelope.Request as SessionEndedRequest; await OnSessionEndedAsync(request, session); } var responseEnvelope = new SpeechletResponseEnvelope { Version = requestEnvelope.Version, Response = response, SessionAttributes = session.Attributes }; return responseEnvelope.ToJson(); }
/// <summary> /// /// </summary> /// <param name="requestEnvelope"></param> /// <returns></returns> private string DoProcessRequest(SpeechletRequestEnvelope requestEnvelope) { Session session = requestEnvelope.Session; SpeechletResponse response = null; // verify timestamp is within tolerance var diff = DateTime.UtcNow - requestEnvelope.Request.Timestamp; Debug.WriteLine("Request was timestamped {0:0.00} seconds ago.", diff.TotalSeconds); if (Math.Abs((decimal)diff.TotalSeconds) > Sdk.TIMESTAMP_TOLERANCE_SEC) { return String.Empty; } // process launch request if (requestEnvelope.Request is LaunchRequest) { var request = requestEnvelope.Request as LaunchRequest; if (requestEnvelope.Session.IsNew) { OnSessionStarted( new SessionStartedRequest(request.RequestId, request.Timestamp), session); } response = OnLaunch(request, session); } // process intent request else if (requestEnvelope.Request is IntentRequest) { var request = requestEnvelope.Request as IntentRequest; // Do session management prior to calling OnSessionStarted and OnIntentAsync // to allow dev to change session values if behavior is not desired DoSessionManagement(request, session); if (requestEnvelope.Session.IsNew) { OnSessionStarted( new SessionStartedRequest(request.RequestId, request.Timestamp), session); } response = OnIntent(request, session); } // process session ended request else if (requestEnvelope.Request is SessionEndedRequest) { var request = requestEnvelope.Request as SessionEndedRequest; OnSessionEnded(request, session); } var responseEnvelope = new SpeechletResponseEnvelope { Version = requestEnvelope.Version, Response = response, SessionAttributes = requestEnvelope.Session.Attributes }; return responseEnvelope.ToJson(); }