Exemplo n.º 1
0
        /**
         * Creates and returns the visual and spoken response with shouldEndSession flag
         *
         * @param title
         *            title for the companion application home card
         * @param output
         *            output content for speech and companion application home card
         * @param shouldEndSession
         *            should the session be closed
         * @return SpeechletResponse spoken and visual response for the given input
         */

        private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            // Create the Simple card content.
            var card = new SimpleCard
            {
                Title = "Unidesk Dishwasher",
                //Subtitle = "Unidesk Dishwasher - Sub Title",
                Content = $"Unidesk Diskwasher - {output}"
            };

            // Create the plain text output.
            var speech = new PlainTextOutputSpeech {
                Text = output
            };

            // Create the speechlet response.
            var response = new SpeechletResponse
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = speech,
                Card             = card
            };

            return(response);
        }
        public void RenderTemplateDirective_BodyTemplate1()
        {
            const string TestDataFile       = @"TestData\ResponseWithRenderTemplateDirectiveAndBodyTemplate1.json";
            var          expectedJSONObject = JObject.Parse(File.ReadAllText(TestDataFile));

            var renderTemplateDirective = new RenderTemplateDirective();

            renderTemplateDirective.Template = new BodyTemplate1
            {
                Title       = "Body Template Title",
                TextContent = new TextContent
                {
                    PrimaryText = new TextContentItem
                    {
                        Text = "Hello world"
                    }
                }
            };

            var testResponse = new SpeechletResponse();

            testResponse.Directives.Add(renderTemplateDirective);

            var responseEnvelope = new SpeechletResponseEnvelope();

            responseEnvelope.Response = testResponse;
            var jsonResponse = responseEnvelope.ToJson();

            Assert.Equal(JsonConvert.SerializeObject(expectedJSONObject), jsonResponse);
        }
Exemplo n.º 3
0
        private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession, LaunchRequest launchRequest, IntentRequest intentRequest, Session session)
        {
            _logService.LogRequest(intentRequest, session, output);

            // Create the Simple card content.
            SimpleCard card = new SimpleCard();

            card.Title   = title;
            card.Content = output;

            SsmlOutputSpeech ssml = new SsmlOutputSpeech()
            {
                Ssml = "<speak>" + output + " </speak>"
            };

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse()
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = ssml,
                Card             = card
            };

            //response.Card = card;
            return(response);
        }
        private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            // Create the Simple card content.
            SimpleCard card = new SimpleCard();

            card.Title = title;
            TextInfo textInfo = new CultureInfo("en-GB", false).TextInfo;

            card.Content = textInfo.ToTitleCase(output);

            // Create the plain text output.
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();

            speech.Text = output;

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;
            response.OutputSpeech     = speech;
            response.Card             = card;
            Reprompt reprompt = new Reprompt()
            {
                OutputSpeech = speech
            };

            response.Reprompt = reprompt;
            return(response);
        }
Exemplo n.º 5
0
        /**
         * Creates and returns the visual and spoken response with shouldEndSession flag
         *
         * @param title
         *            title for the companion application home card
         * @param output
         *            output content for speech and companion application home card
         * @param shouldEndSession
         *            should the session be closed
         * @return SpeechletResponse spoken and visual response for the given input
         */
        private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            // Create the Simple card content.
            var consentCard = new AskForPermissionsConsentCard();

            consentCard.PermissionType = PermissionType.CountryAndPostalCode;


            SimpleCard card = new SimpleCard();

            card.Title    = String.Format("SessionSpeechlet - {0}", title);
            card.Subtitle = String.Format("SessionSpeechlet - Sub Title");
            card.Content  = String.Format("SessionSpeechlet - {0}", output);

            // Create the plain text output.
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();

            speech.Text = output;

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;
            response.OutputSpeech     = speech;
            response.Card             = card;
            return(response);
        }
        public async Task <SpeechletResponse> RespondAsync()
        {
            // it's empty or emptying so update status to dirty.
            await this._service.UpdateStatusAsync(this._session.User.Id, new DirtyStatus());

            // build message
            var salutations = new List <string>()
            {
                "Don't forget to put any existing dirty dishes into the dishwasher.",
                "If you see any dirty dishes, why not put those in too.",
                "Why not fill it up while you're at it."
            };

            string text = $"Thanks! {salutations.Random()}";

            // respond back
            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = text
                },
                Card = new SimpleCard()
                {
                    Title   = "Dishwasher Unload",
                    Content = text
                },
                ShouldEndSession = false
            };

            return(response);
        }
        public void RenderTemplateDirective_ListTemplate1()
        {
            const string TestDataFile       = @"TestData\ResponseWithRenderTemplateDirectiveAndListTemplate1.json";
            var          expectedJSONObject = JObject.Parse(File.ReadAllText(TestDataFile));

            var renderTemplateDirective = new RenderTemplateDirective();
            var listTemplate            = new ListTemplate1
            {
                Title = "List Template 1 Title",
                Token = "listtemplate1token"
            };

            AddListItemPlaceHolder(listTemplate, 1);
            AddListItemPlaceHolder(listTemplate, 2);
            AddListItemPlaceHolder(listTemplate, 3);
            renderTemplateDirective.Template = listTemplate;

            var testResponse = new SpeechletResponse();

            testResponse.Directives.Add(renderTemplateDirective);

            var responseEnvelope = new SpeechletResponseEnvelope();

            responseEnvelope.Response = testResponse;
            var jsonResponse = responseEnvelope.ToJson();

            Assert.Equal(JsonConvert.SerializeObject(expectedJSONObject), jsonResponse);
        }
Exemplo n.º 8
0
        public static SpeechletResponse CompileResponse(string output)
        {
            //var response = new SpeechletResponse
            //{
            //    OutputSpeech = new PlainTextOutputSpeech { Text = output },
            //    ShouldEndSession = true
            //};
            //return response;

            var card = new SimpleCard {
                Title = "Home Tips"
            };

            var textInfo = new CultureInfo("en-US", false).TextInfo;

            card.Content = textInfo.ToTitleCase(output);

            // Create the plain text output.
            var speech = new PlainTextOutputSpeech {
                Text = output
            };

            // Create the speechlet response.
            var response = new SpeechletResponse
            {
                ShouldEndSession = true,
                OutputSpeech     = speech,
                Card             = card
            };

            return(response);
        }
        public async Task <SpeechletResponse> RespondAsync()
        {
            // it's full and/or running so update status
            await this._service.UpdateStatusAsync(this._session.User.Id, new RunningStatus());

            // build message
            var salutations = new List <string>()
            {
                "Thanks for letting me know.",
                "Don't be shy when it's time to unload!",
                "Splish-splash your dishes are taking a bath."
            };

            string text = $"Got it. {salutations.Random()}";

            // respond back
            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = text
                },
                Card = new SimpleCard()
                {
                    Title   = "Dishwasher Start",
                    Content = text
                },
                ShouldEndSession = false
            };

            return(response);
        }
Exemplo n.º 10
0
        public async Task <SpeechletResponse> RespondAsync()
        {
            this._intent.Slots.TryGetValue("State", out var stateSlot);
            string text;

            // update status
            var requestedStatus = stateSlot?.Value;

            await this._service.UpdateStatusAsync(this._session.User.Id, Status.FromText(requestedStatus));

            // build message
            text = $"Dishwasher is now set to {requestedStatus}";

            // respond back
            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = text
                },
                Card = new SimpleCard()
                {
                    Title   = "Dishwasher Status Update",
                    Content = text
                },
                ShouldEndSession = false
            };

            return(response);
        }
        private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession, LaunchRequest launchRequest, IntentRequest intentRequest, Session session)
        {
            _logService.LogRequest(launchRequest, session, output);
            _logService.LogRequest(intentRequest, session, output);

            // Create the Simple card content.
            SimpleCard card = new SimpleCard()
            {
                Title   = title,
                Content = output
            };

            // Create the plain text output.
            SsmlOutputSpeech speech = new SsmlOutputSpeech();

            speech.Ssml = "<speak>" + output + " </speak>";

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;
            response.OutputSpeech     = speech;
            if (String.IsNullOrWhiteSpace(output))
            {
                //response.Card = card;
            }

            return(response);
        }
Exemplo n.º 12
0
        protected SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            // Create the Simple card content.
            var card = new SimpleCard
            {
                Title   = String.Format("SessionSpeechlet - {0}", title),
                Content = String.Format("SessionSpeechlet - {0}", output)
            };

            // Create the plain text output.
            var speech = new PlainTextOutputSpeech
            {
                Text = output
            };

            // Create the speechlet response.
            var response = new SpeechletResponse
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = speech,
                Card             = card
            };

            return(response);
        }
Exemplo n.º 13
0
        /**
         * Creates and returns the visual and spoken response with shouldEndSession flag
         *
         * @param title
         *            title for the companion application home card
         * @param output
         *            output content for speech and companion application home card
         * @param shouldEndSession
         *            should the session be closed
         * @return SpeechletResponse spoken and visual response for the given input
         */
        private SpeechletResponse BuildSpeechletResponse(string title, string output, string reprompt_out, bool shouldEndSession)
        {
            // Create the Simple card content.
            SimpleCard card = new SimpleCard();

            card.Title    = String.Format(title);
            card.Subtitle = String.Format("Star Citizen");
            card.Content  = String.Format(output);

            // Create the plain text output.
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();

            speech.Text = output;

            PlainTextOutputSpeech reprompt_speech = new PlainTextOutputSpeech();

            reprompt_speech.Text = reprompt_out;



            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;
            response.OutputSpeech     = speech;
            response.Card             = card;
            //if (!shouldEndSession)
            //{
            response.Reprompt.OutputSpeech = reprompt_speech;
            //    return response;
            //}

            return(response);
        }
        private async Task <SpeechletResponse> BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            //Create a standard card
            var image = new Image()
            {
                SmallImageUrl = "https://samman.hopto.org/rokusmall.png",
                LargeImageUrl = "https://samman.hopto.org/rokubig.png"
            };

            var card = new StandardCard()
            {
                Title = String.Format("RokuControl - {0}", title),
                Text  = String.Format("{0}", output),
                Image = image
            };

            // Create the plain text output.
            var speech = new PlainTextOutputSpeech()
            {
                Text = output
            };

            // Create the speechlet response.
            var response = new SpeechletResponse()
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = speech,
                Card             = card
            };

            return(response);
        }
Exemplo n.º 15
0
        public async Task <SpeechletResponse> RespondAsync()
        {
            var sampleUtterances = new List <string>()
            {
                "Set the dishwasher status to dirty",
                "Are the dishes clean?",
                "What is the status?"
            };

            string text = "Sorry! I don't know how to handle that. Try saying something like " + sampleUtterances.Random();

            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = text
                },
                Card = new SimpleCard()
                {
                    Title = "Dishwasher Whoops!", Content = text
                },
                ShouldEndSession = false
            };

            return(response);
        }
Exemplo n.º 16
0
        private async Task <SpeechletResponse> BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            // Create the Simple card content.

            SimpleCard card = new SimpleCard();

            card.Title = String.Format("SessionSpeechlet - {0}", title);

            card.Subtitle = String.Format("SessionSpeechlet - Sub Title");

            card.Content = String.Format("SessionSpeechlet - {0}", output);



            // Create the plain text output.

            //PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            SsmlOutputSpeech speech = new SsmlOutputSpeech();

            speech.Ssml = string.Format("<speak>{0}</speak>", output);



            // Create the speechlet response.

            SpeechletResponse response = new SpeechletResponse();


            response.ShouldEndSession = shouldEndSession;

            response.OutputSpeech = speech;

            response.Card = card;
            return(response);
        }
Exemplo n.º 17
0
        private void AssertIsPlainTextResponse(SpeechletResponse response, string expectedText)
        {
            Assert.That(response.OutputSpeech, Is.TypeOf <PlainTextOutputSpeech>());

            var output = (PlainTextOutputSpeech)response.OutputSpeech;

            Assert.That(output.Text, Is.EqualTo(expectedText));
        }
Exemplo n.º 18
0
        public static SpeechletResponse BuildSpeechletResponse(SimpleIntentResponse simpleIntentResponse, bool shouldEndSession)
        {
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;

            // Create the speechlet response from SimpleIntentResponse.
            // If there's an ssmlString use that as the spoken reply
            // If ssmlString is empty, speak cardText

            if (simpleIntentResponse.ssmlString != "")
            {
                SsmlOutputSpeech speech = new SsmlOutputSpeech();
                speech.Ssml           = simpleIntentResponse.ssmlString;
                response.OutputSpeech = speech;
            }
            else
            {
                PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
                speech.Text           = simpleIntentResponse.cardText;
                response.OutputSpeech = speech;
            }


            // if images are passed, then assume a standard card is wanted
            // images should be stored in the ~/Images/ folder and follow these requirements

            // JPEG or PNG supported, no larger than 2MB
            // 720x480 - small size recommendation
            // 1200x800 - large size recommendation

            if (simpleIntentResponse.smallImage != "" && simpleIntentResponse.largeImage != "")
            {
                StandardCard card = new StandardCard();
                card.Title = AlexaConstants.AppName;
                card.Text  = simpleIntentResponse.cardText;

                // The trailing slash after the image name is required because we're serving off the image through a Web API controller and
                // don't want to change the default web project settings

                card.Image = new Image()
                {
                    LargeImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.largeImage + "/",
                    SmallImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.smallImage + "/",
                };

                response.Card = card;
            }
            else
            {
                SimpleCard card = new SimpleCard();
                card.Title    = AlexaConstants.AppName;
                card.Content  = simpleIntentResponse.cardText;
                response.Card = card;
            }

            return(response);
        }
Exemplo n.º 19
0
        public override SpeechletResponse OnIntent(IntentRequest request, Session session)
        {
            this.log.Info(String.Format("BeginOnIntent requestId={0}, sessionId={1}, intent={2}", request.RequestId, session.SessionId, request.Intent.Name));
            SpeechletResponse speech = null;

            switch (request.Intent.Name.ToLower())
            {
            case "amazon.helpintent":
                speech = new SpeechletResponse()
                {
                    ShouldEndSession = false,
                    OutputSpeech     = new SsmlOutputSpeech()
                    {
                        Ssml = "<speak><p>Ask me to find you events with free food or drinks</p><p>For example</p> Alexa, open Find Mooch, find an event in Seattle </speak>"
                    }
                };
                break;

            case "amazon.cancelintent":
            case "amazon.stopintent":
                speech = new SpeechletResponse()
                {
                    ShouldEndSession = true
                };
                break;

            case "givedetails":
                break;

            case "moreevents":
                var start = session.Attributes["startIndex"];
                int startIndex;
                if (!session.IsNew && int.TryParse(start, out startIndex))
                {
                    speech = GetAndWaitForEvents(request, startIndex);
                }
                else
                {
                    speech = new SpeechletResponse()
                    {
                        ShouldEndSession = false,
                        OutputSpeech     = new SsmlOutputSpeech()
                        {
                            Ssml = "<speak><p>Sorry, I couldn't understand</p><p>Please ask me to find you events</p><p>For example</p> Alexa, open Find Mooch, find an event in Seattle </speak>"
                        }
                    };
                }
                break;

            case "findmooch":
            default:
                speech = GetAndWaitForEvents(request);
                break;
            }

            this.log.Info(String.Format("EndOnIntent requestId={0}, sessionId={1}, intent={2}", request.RequestId, session.SessionId, request.Intent));
            return(speech);
        }
Exemplo n.º 20
0
        public Task <SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session, Context context)
        {
            var resp = new SpeechletResponse();

            resp.ShouldEndSession = false;
            resp.OutputSpeech     = new PlainTextOutputSpeech()
            {
                Text = "Welcome to the Couchbase booth. Ask me about Couchbase."
            };
            return(Task.FromResult(resp));
        }
Exemplo n.º 21
0
        public Task <SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session, Context context)
        {
            var response = new SpeechletResponse()
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = "Would you like to know this weeks, last weeks or next weeks?"
                }
            };

            return(Task.FromResult(response));
        }
        protected async Task <SpeechletResponse> CreatePlainTextSpeechletReponseAsync(string text, bool shouldEndSession = false)
        {
            var resp = new SpeechletResponse
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = new PlainTextOutputSpeech
                {
                    Text = text
                }
            };

            return(await Task.FromResult(resp));
        }
        protected async Task <SpeechletResponse> CreateErrorResponseAsync()
        {
            var resp = new SpeechletResponse
            {
                ShouldEndSession = true,
                OutputSpeech     = new PlainTextOutputSpeech
                {
                    Text = "Something went wrong. Please try again later."
                }
            };

            return(await Task.FromResult(resp));
        }
        public async Task <SpeechletResponse> RespondAsync()
        {
            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = string.Empty
                },
                ShouldEndSession = true
            };

            return(response);
        }
        private SpeechletResponse BuildSpeechletResponse(string output, bool shouldEndSession)
        {
            // Create the plain text output.
            PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
            speech.Text = output;

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse();
            response.ShouldEndSession = shouldEndSession;
            response.OutputSpeech = speech;

            return response;
        }
Exemplo n.º 26
0
        /// <summary>
        /// </summary>
        /// <param name="requestEnvelope"></param>
        /// <returns></returns>
        private string DoProcessRequest(SpeechletRequestEnvelope requestEnvelope)
        {
            var 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());
        }
Exemplo n.º 27
0
        public override SpeechletResponse OnLaunch(LaunchRequest request, Session session)
        {
            this.log.Info(String.Format("OnLaunch requestId={0}, sessionId={1}", request.RequestId, session.SessionId));

            var response = new SpeechletResponse();

            response.ShouldEndSession = false;
            response.OutputSpeech     = new SsmlOutputSpeech()
            {
                Ssml = @"<speak>Welcome to Find Mooch. Ask me <break strength=""medium""/> <emphasis level=""strong""> find free events </emphasis></speak>"
            };

            return(response);
        }
Exemplo n.º 28
0
        private void AssertSsmlContentContainsText(SpeechletResponse response, string expectedText)
        {
            Assert.That(response.OutputSpeech, Is.TypeOf <SsmlOutputSpeech>());

            var output     = (SsmlOutputSpeech)response.OutputSpeech;
            var outputText = StripXmlTags(output.Ssml);

            Assert.That(outputText, Does.Contain(expectedText));

            string StripXmlTags(string input)
            {
                return(Regex.Replace(input, "<.*?>", string.Empty));
            }
        }
        public async Task <SpeechletResponse> RespondAsync()
        {
            string text = "Welcome to dishwasher. I help you track if the dishes are clean or dirty.";

            var response = new SpeechletResponse
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = text
                },
                ShouldEndSession = false
            };

            return(response);
        }
Exemplo n.º 30
0
        private SpeechletResponse BuildAudioResponse(string uri)
        {
            // Create the plain text output.
            SsmlOutputSpeech speech = new SsmlOutputSpeech
            {
                Ssml = $"<speak><audio src=\"{uri}\" /></speak>"
            };

            // Create the speechlet response.
            SpeechletResponse response = new SpeechletResponse
            {
                ShouldEndSession = true,
                OutputSpeech     = speech
            };

            return(response);
        }