/// <summary>
        /// 
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json) {
            if (json["version"] == null || json["session"] == null || json["request"] == null) {
                throw new SpeechletException("Request does not conform to schema");
            }

            if (json.Value<string>("version") != Sdk.VERSION) {
                // will still attempt to parse request content but might be useful to log a warning
            }

            SpeechletRequest request;
            JObject requestJson = json.Value<JObject>("request");
            string requestType = requestJson.Value<string>("type");
            string requestId = requestJson.Value<string>("requestId");
            DateTime timestamp = requestJson.Value<DateTime>("timestamp");
            switch (requestType) {
                case "LaunchRequest":
                    request = new LaunchRequest(requestId, timestamp);
                    break;
                case "IntentRequest":
                    request = new IntentRequest(requestId, timestamp, 
                        Intent.FromJson(requestJson.Value<JObject>("intent")));
                    break;
                case "SessionStartedRequest":
                    request = new SessionStartedRequest(requestId, timestamp);
                    break;
                case "SessionEndedRequest":
                    SessionEndedRequest.ReasonEnum reason;
                    Enum.TryParse<SessionEndedRequest.ReasonEnum>(requestJson.Value<string>("reason"), out reason);
                    request = new SessionEndedRequest(requestId, timestamp, reason);
                    break;
                default:
                    throw new ArgumentException("json");
            }

            return new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value<JObject>("session")),
                Version = json.Value<string>("version")
            };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json) {
            if (json["version"] != null && json.Value<string>("version") != Sdk.VERSION) {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            JObject requestJson = json.Value<JObject>("request");
            string requestType = requestJson.Value<string>("type");
            string requestId = requestJson.Value<string>("requestId");
            DateTime timestamp = requestJson.Value<DateTime>("timestamp");
            switch (requestType) {
                case "LaunchRequest":
                    request = new LaunchRequest(requestId, timestamp);
                    break;
                case "IntentRequest":
                    request = new IntentRequest(requestId, timestamp, 
                        Intent.FromJson(requestJson.Value<JObject>("intent")));
                    break;
                case "SessionStartedRequest":
                    request = new SessionStartedRequest(requestId, timestamp);
                    break;
                case "SessionEndedRequest":
                    SessionEndedRequest.ReasonEnum reason;
                    Enum.TryParse<SessionEndedRequest.ReasonEnum>(requestJson.Value<string>("reason"), out reason);
                    request = new SessionEndedRequest(requestId, timestamp, reason);
                    break;
                default:
                    throw new SpeechletException("Unable to determine Request Type.");
            }

            return new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value<JObject>("session")),
                Version = json.Value<string>("version")
            };
        }
Exemplo n.º 3
0
 public abstract SpeechletResponse OnLaunch(LaunchRequest launchRequest, Session session);
 public async Task <SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session, Context context)
 {
     return(speechlet.OnLaunch(launchRequest, session, context));
 }
 public abstract Task <SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session);
 public abstract Task<SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session);
Exemplo n.º 7
0
 public abstract SpeechletResponse OnLaunch(LaunchRequest launchRequest, Session session);
 public override SpeechletResponse OnLaunch(LaunchRequest request, Session session) {
     Log.Info("OnLaunch requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
     return GetWelcomeResponse();
 }
        public override SpeechletResponse OnLaunch(LaunchRequest request, Session session)
        {
            var response = new SpeechletResponse();

            return response;
        }
 public override SpeechletResponse OnLaunch(LaunchRequest request, Session session)
 {
     return GetWelcomeResponse();
 }