/// <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(); }
/// <summary> /// /// </summary> /// <param name="requestEnvelope"></param> /// <returns></returns> private string DoProcessRequest(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) { 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(); }
/// <summary> /// Opportunity to set policy for handling requests with invalid signatures and/or timestamps /// </summary> /// <returns>true if request processing should continue, otherwise false</returns> public virtual bool OnRequestValidation( SpeechletRequestValidationResult result, DateTime referenceTimeUtc, SpeechletRequestEnvelope requestEnvelope) { return result == SpeechletRequestValidationResult.OK; }
/// <summary> /// Verifies request timestamp /// </summary> public static bool VerifyRequestTimestamp(SpeechletRequestEnvelope requestEnvelope, DateTime referenceTimeUtc) { // verify timestamp is within tolerance var diff = referenceTimeUtc - requestEnvelope.Request.Timestamp; Debug.WriteLine("Request was timestamped {0:0.00} seconds ago.", diff.TotalSeconds); return (Math.Abs((decimal)diff.TotalSeconds) <= Sdk.TIMESTAMP_TOLERANCE_SEC); }