public override SpeechletResponse OnIntent(IntentRequest request, Session session)
        {
            // Get intent from the request object.
            var intent = request.Intent;
            var intentName = intent?.Name;

            // Note: If the session is started with an intent, no welcome message will be rendered;
            // rather, the intent specific response will be returned.
            if ("MyNameIsIntent".Equals(intentName))
                return SetNameInSessionAndSayHello(intent, session);

            if ("WhatsMyNameIntent".Equals(intentName))
                return GetNameFromSessionAndSayHello(intent, session);
            
            throw new SpeechletException("Invalid Intent");
        }
        public override SpeechletResponse OnIntent(IntentRequest request, Session session) {
            Log.Info("OnIntent requestId={0}, sessionId={1}", request.RequestId, session.SessionId);

            // Get intent from the request object.
            Intent intent = request.Intent;
            string intentName = (intent != null) ? intent.Name : null;

            // Note: If the session is started with an intent, no welcome message will be rendered;
            // rather, the intent specific response will be returned.
            if ("MyNameIsIntent".Equals(intentName)) {
                return SetNameInSessionAndSayHello(intent, session);
            } 
            else if ("WhatsMyNameIntent".Equals(intentName)) {
                return GetNameFromSessionAndSayHello(intent, session);
            } 
            else {
                throw new SpeechletException("Invalid Intent");
            }
        }
        /// <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>
        private void DoSessionManagement(IntentRequest request, Session session)
        {
            if (request == null)
            {
                return;
            }

            if (session.Attributes == null)
            {
                session.Attributes = new Dictionary <string, string>();
            }

            if (session.IsNew)
            {
                session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
            }
            else
            {
                // if the session was started as a result of a launch request
                // a first intent isn't yet set, so set it to the current intent
                if (!session.Attributes.ContainsKey(Session.INTENT_SEQUENCE))
                {
                    session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
                }
                else
                {
                    session.Attributes[Session.INTENT_SEQUENCE] += Session.SEPARATOR + request.Intent.Name;
                }
            }

            // Auto-session management: copy all slot values from current intent into session
            foreach (var slot in request.Intent.Slots.Values)
            {
                session.Attributes[slot.Name] = slot.Value;
            }
        }
        /// <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")
            };
        }
Beispiel #6
0
 public abstract SpeechletResponse OnIntent(IntentRequest intentRequest, Session session);
 public async Task <SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session, Context context)
 {
     return(speechlet.OnIntent(intentRequest, session, context));
 }
 public abstract Task <SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session);
 public abstract Task<SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session);
        /// <summary>
        /// 
        /// </summary>
        private void DoSessionManagement(IntentRequest request, Session session) {
            if (session.IsNew) {
                session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
            }
            else {
                // if the session was started as a result of a launch request 
                // a first intent isn't yet set, so set it to the current intent
                if (!session.Attributes.ContainsKey(Session.INTENT_SEQUENCE)) {
                    session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
                }
                else {
                    session.Attributes[Session.INTENT_SEQUENCE] += Session.SEPARATOR + request.Intent.Name;
                }
            }

            // Auto-session management: copy all slot values from current intent into session
            foreach (var slot in request.Intent.Slots.Values) {
                if (!String.IsNullOrEmpty(slot.Value)) session.Attributes[slot.Name] = slot.Value;
            }
        }
 public abstract SpeechletResponse OnIntent(IntentRequest intentRequest, Session session);
        public override SpeechletResponse OnIntent(IntentRequest request, Session session)
        {
            var response = new SpeechletResponse();

            return response;
        }