public InteractionInternalModel Process(
            InteractionInternalModel interaction
            )
        {
            try
            {
                if (interaction.Request.State == null ||
                    interaction.Request.State == RequestStates.Completed ||
                    interaction.Request.ConfirmationStatus == ConfirmationStatus.Confirmed)
                {
                    interaction = GetIntentHandler(interaction.Request.Intent).Process(interaction);
                }
            }
            catch (Exception ex)
            {
                // LOG ERROR TO APP INSIGHTS PERHAPS.
            }
            finally
            {
                if (string.IsNullOrWhiteSpace(interaction.Response.Text))
                {
                    interaction.Response.Text      = Speech.UnknownIntentReply;
                    interaction.Session.EndSession = true;
                }
            }

            return(interaction);
        }
コード例 #2
0
        public InteractionInternalModel Process(
            InteractionInternalModel interaction
            )
        {
            interaction.Response.Text      = Speech.WelcomeReply;
            interaction.Response.Prompt    = Speech.WelcomePrompt;
            interaction.Session.EndSession = false;

            return(interaction);
        }
コード例 #3
0
        public InteractionInternalModel Process(
            InteractionInternalModel interaction
            )
        {
            string travelMode = interaction.Request.Parameters
                                .Find(p => p.Key.Equals("travelModel"))
                                .Value;
            string fromCity = interaction.Request.Parameters
                              .Find(p => p.Key.Equals("fromCity"))
                              .Value;
            string toCity = interaction.Request.Parameters
                            .Find(p => p.Key.Equals("toCity"))
                            .Value;
            string travelDate = interaction.Request.Parameters
                                .Find(p => p.Key.Equals("travelDate"))
                                .Value;
            string activity = interaction.Request.Parameters
                              .Find(p => p.Key.Equals("activity"))
                              .Value;

            StringBuilder finalResponse = new StringBuilder();

            finalResponse.Append(Speech.TripIntro);

            if (!string.IsNullOrEmpty(travelMode))
            {
                finalResponse.Append(travelMode);
            }
            else
            {
                finalResponse.Append("You'll go ");
            }

            finalResponse.Append($"from {fromCity} to {toCity} on {travelDate}");

            if (!string.IsNullOrEmpty(activity))
            {
                finalResponse.Append($" to go {activity}");
            }

            interaction.Response.Text      = finalResponse.ToString();
            interaction.Session.EndSession = true;

            return(interaction);
        }
コード例 #4
0
        internal static InteractionInternalModel FromAlexaRequest(
            SkillRequest skillRequest
            )
        {
            InteractionInternalModel interactionModel = new InteractionInternalModel
            {
                Id = skillRequest.Request.RequestId
            };

            Type requestType = skillRequest.GetRequestType();

            interactionModel.Request.Channel = "alexa";

            if (requestType == typeof(IntentRequest))
            {
                IntentRequest intentRequest = skillRequest.Request as IntentRequest;
                interactionModel.Request.Intent             = intentRequest.Intent.Name;
                interactionModel.Request.State              = intentRequest.DialogState;
                interactionModel.Request.ConfirmationStatus = intentRequest.Intent.ConfirmationStatus;

                if (intentRequest.Intent.Slots != null)
                {
                    interactionModel.Request.Parameters = intentRequest.Intent.Slots.ToList()
                                                          .ConvertAll(s => new KeyValuePair <string, string>(s.Value.Name, s.Value.Value));
                }
            }
            else if (requestType == typeof(LaunchRequest))
            {
                interactionModel.Request.Intent = "DefaultWelcomeIntent";
            }
            else if (requestType == typeof(SessionEndedRequest))
            {
                return(null);
            }

            return(interactionModel);
        }
コード例 #5
0
        internal static SkillResponse ToAlexaResponse(
            InteractionInternalModel commonModel
            )
        {
            SkillResponse response = new SkillResponse
            {
                Version  = "1.0",
                Response = new ResponseBody()
            };

            if (commonModel.Request.State == RequestStates.Started || commonModel.Request.State == RequestStates.InProgress)
            {
                DialogDelegate directive = new DialogDelegate
                {
                    UpdatedIntent = new Intent
                    {
                        Name  = commonModel.Request.Intent,
                        Slots = commonModel.Request.Parameters?.ToDictionary(p => p.Key, p => new Slot {
                            Name = p.Key, Value = p.Value
                        })
                    }
                };

                response.Response.Directives.Add(directive);
                response.Response.ShouldEndSession = false;

                return(response);
            }

            if (string.IsNullOrWhiteSpace(commonModel.Response.Ssml))
            {
                response.Response.OutputSpeech = new PlainTextOutputSpeech
                {
                    Text = commonModel.Response.Text
                };
            }
            else
            {
                response.Response.OutputSpeech = new SsmlOutputSpeech {
                    Ssml = "<speak>" + commonModel.Response.Ssml + "</speak>"
                };
            }

            if (commonModel.Response.Card != null)
            {
                response.Response.Card = new SimpleCard
                {
                    Title   = commonModel.Response.Card.Title,
                    Content = commonModel.Response.Card.Text
                };
            }

            if (!string.IsNullOrWhiteSpace(commonModel.Response.Prompt))
            {
                response.Response.Reprompt = new Reprompt
                {
                    OutputSpeech = new PlainTextOutputSpeech
                    {
                        Text = commonModel.Response.Prompt
                    }
                }
            }
            ;

            response.Response.ShouldEndSession = commonModel.Session.EndSession;

            return(response);
        }
    }