Пример #1
0
        public SkillResponse post(SkillRequest input)

        {
            AlexaResponse alexaResponse = new AlexaResponse(input);

            return(alexaResponse.response);
        }
        public async Task <AlexaResponse> ProcessAdventureRequestAsync(AlexaRequest request)
        {
            Stopwatch functionDuration = new Stopwatch();

            functionDuration.Start();
            AlexaResponse response       = new AlexaResponse();
            bool          isPing         = false;
            string        requestLogInfo = null;

            if (request.Version.Equals("ping"))
            {
                requestLogInfo = "Ping request";
                _logger.LogInformation(requestLogInfo);
                isPing = true;
            }
            else
            {
                switch (request.Request.Type)
                {
                case RequestType.SkillDisabled:
                    requestLogInfo = "Received skill disabled event";
                    _logger.LogInformation(requestLogInfo);
                    response = new AlexaResponse();
                    break;

                case RequestType.SkillEnabled:
                    requestLogInfo = "Received skill enabled event";
                    _logger.LogInformation(requestLogInfo);
                    response = new AlexaResponse();
                    break;

                case RequestType.LaunchRequest:
                    requestLogInfo = "Processing launch request";
                    _logger.LogInformation(requestLogInfo);
                    response = await GetLaunchResponseAsync(request);

                    break;

                case RequestType.IntentRequest:
                    requestLogInfo = "Processing intent request";
                    _logger.LogInformation(requestLogInfo);
                    response = await GetIntentResponseAsync(request);

                    break;

                case RequestType.SessionEndedRequest:
                    requestLogInfo = "Processing intent request";
                    _logger.LogInformation(requestLogInfo);
                    response = new AlexaResponse();
                    break;
                }
            }


            functionDuration.Stop();

            _logger.LogInformation($"Function duration: {functionDuration.ElapsedMilliseconds}");

            return(response);
        }
Пример #3
0
        private SkillResponse TeachTheWord(WordAttributes wordAttributes)
        {
            LOGGER.log.INFO("WordFamilies", "TeachTheWord", "WORD: " + wordAttributes.Word);

            string[] decodedWord = wordAttributes.Word.Select(x => x.ToString()).ToArray();
            string   wordFamily  = wordAttributes.WordFamily;
            string   teachModel  = QuickReply;

            teachModel += SSML.PauseFor(1);
            teachModel += " This word is spelled ";
            foreach (string sound in decodedWord)
            {
                teachModel += SSML.PauseFor(0.2) + SSML.SayExtraSlow(sound) + SSML.PauseFor(0.2);
            }
            teachModel += SSML.PauseFor(.5);
            teachModel += "The sounds are ";
            teachModel += SSML.PauseFor(0.2) + SSML.SayExtraSlow(SSML.Phoneme(decodedWord[0])) + SSML.PauseFor(0.2);
            teachModel += SSML.PauseFor(0.2) + SSML.SayExtraSlow(wordFamily) + SSML.PauseFor(1.0);

            teachModel += SSML.SayExtraSlow(wordAttributes.Word);
            teachModel += SSML.PauseFor(0.5);
            teachModel += "Now you try. Say the word. ";

            return(AlexaResponse.TeachFlashCard(wordAttributes.Word, teachModel));
        }
Пример #4
0
        public async Task <SkillResponse> HandleRequest()
        {
            LOGGER.log.INFO("LaunchRequest", "HandleRequest");

            await this.userProfile.GetUserProfileData();

            if (userProfile.RequiresPurchase())
            {
                LOGGER.log.DEBUG("LaunchRequest", "HandleRequest", "Schedule is premium content");

                await productInventory.GetAvailableProducts();

                string productName = this.userProfile.lesson.InSkillPurchaseName;

                if (productInventory.IsUnpaid(productName))
                {
                    LOGGER.log.DEBUG("LaunchRequest", "HandleRequest", "Premium content requires purchase");

                    this.sessionAttributes.ProductName = productName;
                    return(AlexaResponse.PurchaseContentUpsell(productInventory.GetProductId(productName),
                                                               CommonPhrases.Upsell(), productName));
                }
            }

            this.sessionAttributes.UpdateSessionAttributes(userProfile);
            this.sessionAttributes.SessionState = STATE.Introduction;

            WordAttributes wordAttributes = await WordAttributes.GetWordAttributes(this.sessionAttributes.CurrentWord, LOGGER.log);

            LOGGER.log.DEBUG("Launch", "HandleRequest", "Next word: " + sessionAttributes.CurrentWord);

            return(LessonFactory.GetLesson(this.sessionAttributes.LessonType).Introduction(wordAttributes));
        }
        private AlexaResponse MergeNodeResponses(AdventureNode parentNode, AdventureNode subNode, string voiceId)
        {
            AlexaResponse resp = new AlexaResponse();

            resp.Version  = "1.0";
            resp.Response = new AlexaResponseAttributes();

            List <SpeechFragement> outFragments = new List <SpeechFragement>();

            outFragments.AddRange(parentNode.OutputSpeech);

            if (subNode != null)
            {
                outFragments.AddRange(subNode.Reprompt);
            }

            resp.Response.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(
                AdventureNode.GetSpeechText(outFragments, _linkProcessor, voiceId));


            if ((subNode?.Reprompt?.Any()).GetValueOrDefault(false))
            {
                resp.Response.Reprompt = new RepromptAttributes();
                resp.Response.Reprompt.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(
                    AdventureNode.GetSpeechText(subNode.Reprompt, _linkProcessor, voiceId));
            }

            return(resp);
        }
Пример #6
0
        public async Task <AlexaResponse> GetRisk()
        {
            var apiService  = new XeroApiService();
            var riskContent = await apiService.GetRisks();

            var response = new AlexaResponse()
            {
                version  = "1.0",
                response = new Response()
                {
                    card = new Card()
                    {
                        type    = "Simple",
                        title   = "Risk",
                        content = riskContent,
                    },
                    outputSpeech = new Outputspeech()
                    {
                        type = "PlainText",
                        text = riskContent
                    },
                    reprompt = new Reprompt()
                    {
                        outputSpeech = new Outputspeech1()
                        {
                            type = "PlainText",
                            text = "Can I help you with anything else?"
                        }
                    },
                    shouldEndSession = false,
                }
            };

            return(response);
        }
Пример #7
0
 public LaunchRequest(SkillRequest skillRequest)
 {
     this.userProfile       = new UserProfileDB(skillRequest.Session.User.UserId, LOGGER.log);
     this.sessionAttributes = new SessionAttributes(LOGGER.log);
     this.productInventory  = new ProductInventory(skillRequest);
     AlexaResponse.SetSessionAttributeHandler(sessionAttributes);
 }
Пример #8
0
        private AlexaResponse FavoriteBandIntentHandler(AlexaRequest request)
        {
            var jwtEncodedString = request.Session.User.AccessToken;

            if (request.Session.User.AccessToken != null)
            {
                //Decode name and favorite band from the access token
                var token    = new JwtSecurityToken(jwtEncodedString: jwtEncodedString);
                var bandName = token.Claims.First(c => c.Type == "favoriteBand").Value;
                var name     = token.Claims.First(c => c.Type == "firstName").Value;

                var response = new AlexaResponse(
                    "Hello " + name + ", your favorite band is " + bandName + ".");
                response.Response.Card.Title       = name + "'s Favorite Band";
                response.Response.Card.Content     = bandName;
                response.Response.ShouldEndSession = true;

                return(response);
            }
            else
            {
                var response = new AlexaResponse("You are not currently linked to this skill. Please go into your Alexa app and sign in.");
                response.Response.Card.Type        = "LinkAccount";
                response.Response.ShouldEndSession = true;

                return(response);
            }
        }
Пример #9
0
        private AlexaResponse HelpIntent(AlexaRequest request)
        {
            var response = new AlexaResponse("To use the code games skill, you can say, Alexa, I want to do action 1, 2 or 3. You can also say, Alexa, stop or Alexa, cancel, at any time to exit the code games skill. For now, do you want to do one of the actions?", false);

            response.Response.Reprompt.OutputSpeech.Text = "Please select one, action 1,2 or 3?";
            return(response);
        }
        public AlexaResponse HandleRequest(AlexaRequest request)
        {
            if (request.Request.Intent.Name == "AMAZON.NoIntent" && !request.Session.New)
            {
                return(new AlexaResponse("Fine, you don't have to be such a grinch.", true));
            }
            else if (request.Request.Intent.Name == "AMAZON.YesIntent" && !request.Session.New)
            {
                return(new AlexaResponse("Good, I'm glad you're in the Christmas spirit.", true));
            }

            var unit      = request.Request.Intent.GetSlots().Single(s => s.Key == "Unit").Value;
            var shouldEnd = new Random(DateTime.Now.Millisecond).Next(4) != 1 ? true : false;
            var text      = GetChristmasResponseText(unit, shouldEnd);

            var response = new AlexaResponse(text, text);

            response.Response.Card.Title       = "🎄 Christmas Countdown 🎄";
            response.Response.ShouldEndSession = shouldEnd;
            if (!shouldEnd)
            {
                response.Session.Intent = "CountdownIntent";
            }
            return(response);
        }
        public AlexaResponse LCARS(AlexaRequest request)
        {
            //if (request.Session.Application.ApplicationId != ApplicationId)
            //    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            //var totalSeconds = (DateTime.UtcNow - request.Request.Timestamp).TotalSeconds;
            //if (totalSeconds < -15 || totalSeconds > 150)
            //    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            AlexaResponse response = null;

            if (request != null)
            {
                switch (request.Request.Type)
                {
                case "LaunchRequest":
                    response = RequestHandlers.LaunchRequestHandler(request);
                    break;

                case "IntentRequest":
                    response = RequestHandlers.IntentRequestHandler(request);
                    break;

                case "SessionEndedRequest":
                    response = RequestHandlers.SessionEndedRequestHandler(request);
                    break;
                }
            }

            return(response);
        }
Пример #12
0
        public async Task <SkillResponse> HandleIntent()
        {
            var intentRequest = (Alexa.NET.Request.Type.IntentRequest)skillRequest.Request;

            string lessonName = GetSlotValue(intentRequest);

            LOGGER.log.INFO("MakePurchase", "HandleIntent", "Lesson to purcase to: " + lessonName);
            ILesson lessonToPurchase = LessonFactory.GetLesson(lessonName);
            await base.products.GetAvailableProducts();

            if (base.products.IsUnpaid(lessonToPurchase.InSkillPurchaseName))
            {
                LOGGER.log.DEBUG("LaunchRequest", "HandleRequest", "Premium content requires purchase");

                this.sessionAttributes.ProductName = lessonToPurchase.InSkillPurchaseName;
                return(AlexaResponse.PurchaseContentUpsell(base.products.GetProductId(lessonToPurchase.InSkillPurchaseName),
                                                           CommonPhrases.Upsell(), lessonToPurchase.InSkillPurchaseName));
            }


            await base.userProfile.ChangeLesson(lessonToPurchase);

            this.sessionAttributes.SessionState = STATE.Introduction;
            // relaunch for new lesson
            return(await new LaunchRequest(base.skillRequest).HandleRequest());
        }
Пример #13
0
        private AlexaResponse IntentRequestHandler(Request request)
        {
            AlexaResponse response = null;

            switch (request.Intent)
            {
            case "Action1":
                //response = Action1(request);
                break;

            case "Action2":
                //response = Action1(request);
                break;

            case "AMAZON.CancelIntent":
            case "AMAZON.StopIntent":
                response = CancelOrStopIntentHandler(request);
                break;

            case "AMAZON.HelpIntent":
                response = HelpIntent(request);
                break;
            }

            return(response);
        }
Пример #14
0
        private AlexaResponse HelpIntent(Request request)
        {
            var response = new AlexaResponse("To use the Plural sight skill, you can say, Alexa, ask Plural sight for top courses, to retrieve the top courses or say, Alexa, ask Plural sight for the new courses, to retrieve the latest new courses. You can also say, Alexa, stop or Alexa, cancel, at any time to exit the Plural sight skill. For now, do you want to hear the Top Courses or New Courses?", false);

            response.Response.Reprompt.OutputSpeech.Text = "Please select one, top courses or new courses?";
            return(response);
        }
        private AlexaResponse HelpIntent(AlexaRequest request)
        {
            var response = new AlexaResponse("To use the Leadership Portal skill, you can say, Alexa, ask Leadership Portal for tempalte information.", false);

            response.Response.Reprompt.OutputSpeech.Text = "Please go ahead and ask your questions";
            return(response);
        }
Пример #16
0
        private AlexaResponse HelpIntent(Request request)
        {
            var response = new AlexaResponse("To use the Gorillas skill, you can say,", false);

            response.Response.Reprompt.OutputSpeech.Text = "Please select one form";
            return(response);
        }
        /// <summary>
        /// This method implements retry logic to get a word (specific method implemented in base class)
        /// This method builds the response dictionary for the word and alexa response
        /// This method ensures caching for between session logic
        /// The WordOfTheDay and AnotherWord strategies implement this abstract class with different responses and word retrival logic
        /// </summary>
        /// <param name="alexaRequest"></param>
        /// <returns></returns>
        public AlexaResponse HandleAlexaRequest(AlexaRequestPayload alexaRequest)
        {
            // initialize variables used in case of retry
            Word word         = null;                                    // what word will we get - should never be null
            int  retryCounter = 0;
            Dictionary <WordEnum, string> wordResponseDictionary = null; // this method must return populated dictionary
            string wordResponse = null;

            // get the word
            // get the response dictionary from the word
            // handle retry errors - get another word from the word service if invalid response dictionary

            try
            {
                // repeat api call and parse
                while (wordResponse == null)
                {
                    // Get the word - implemented in base class
                    if (retryCounter == 0)
                    {
                        word = GetWord();
                    }
                    // Get random word - there was an issue with the first word
                    else
                    {
                        word = _wordService.GetRandomWord();
                    }

                    try
                    {
                        wordResponseDictionary = _dictionaryService.GetWordDictionaryFromString(word.WordName);
                    }
                    catch (Exception exception)
                    {
                        return(new AlexaResponse("Unable to build response dictionary for the word: " + word + " " + exception.Message));
                    }

                    wordResponse  = wordResponseDictionary[WordEnum.Word];
                    retryCounter += 1;
                }

                AlexaResponse alexaResponse = BuildAlexaResponse(alexaRequest, wordResponseDictionary);

                // assign word to request for caching the request between intents
                alexaRequest.Session.Attributes                    = new AlexaRequestPayload.SessionCustomAttributes();
                alexaRequest.Session.Attributes.LastWord           = word.WordName; // use the word from the db as it is saved in intent slots
                alexaRequest.Session.Attributes.LastWordDefinition = wordResponseDictionary[WordEnum.WordDefinition];

                // cache the request and its above added session attributes
                _cacheService.CacheAlexaRequest(alexaRequest);

                return(alexaResponse);
            }

            catch (Exception exception)
            {
                // todo - log the exception
                return(new AlexaWordErrorResponse().GenerateCustomError());
            }
        }
        private AlexaResponse IntentRequestHandler(AlexaRequest request)
        {
            AlexaResponse response = null;

            switch (request.Request.Intent.Name)
            {
            case "AMAZON.CancelIntent":
            case "AMAZON.StopIntent":
                response = CancelOrStopIntentHandler(request);
                break;

            case "AMAZON.HelpIntent":
                response = HelpIntent(request);
                break;

            case "TemplateIntent":
                response = TemplateIntent(request);
                break;

            case "SearchIntent":
                response = SearchIntent(request);
                break;
            }

            return(response);
        }
Пример #19
0
        private AlexaResponse EndIntentHandler()
        {
            var response = new AlexaResponse("Espero ter ajudado, até logo.");

            response.Response.ShouldEndSession = true;
            return(response);
        }
Пример #20
0
        public static AlexaResponse DefaultIntentHandler(AlexaRequest request)
        {
            var response = new AlexaResponse("I didn't understand what you requested. Say help to hear a list of options or cancel to exit.");

            response.Response.Reprompt.OutputSpeech.Text = "Say help to hear a list of options or cancel to exit.";
            response.Response.ShouldEndSession           = false;
            return(response);
        }
Пример #21
0
        public AlexaResponse HandleAlexaRequest(AlexaRequestPayload alexaRequest)
        {
            var response = new AlexaResponse("Thanks for using Grammar Tool.  You can also visit Grammar Tool App dot com for more information.  I hope to see you again soon.");

            response.Response.ShouldEndSession = true;

            return(response);
        }
Пример #22
0
        public AlexaResponse HandleAlexaRequest(AlexaRequestPayload alexaRequest)
        {
            var response = new AlexaResponse("You can ask What is the Word of the Day.  You can also visit Grammar Tool App dot com for more information.");

            response.Response.ShouldEndSession = false;

            return(response);
        }
        private AlexaResponse HelpIntentHandler(Request request)
        {
            var msg      = "To use this skill, you can say, Alexa, ask " + skillName + " for a burn";
            var response = new AlexaResponse(msg, false);

            response.Response.Reprompt.OutputSpeech.Text = repromptPhrase;
            return(response);
        }
Пример #24
0
      internal static AlexaResponse ShowBioIntentHandler(Request request)
      {
          var text =
              "Sumith Parambat Damodaran ! working as Director of engineering at <emphasis level=\"strong\">THINK</emphasis>, <break time=\"1s\"/> Previously he was working with <amazon:effect name=\"whispered\">Sitecore UK </amazon:effect> Leading the Services team.";
          var response = new AlexaResponse(text, text, true);

          return(response);
      }
Пример #25
0
        private AlexaResponse MyLanguageIsHandler(AlexaRequest alexaRequest)
        {
            var lang = alexaRequest.request.intent.GetSlotValue("Language");
            var rsp  = new AlexaResponse($"I now know that your favorite language is {lang}. You can ask what is my favorite language. ", false);

            rsp.sessionAttributes.Language = lang;
            return(rsp);
        }
Пример #26
0
 private AlexaResponse ProcessHelpIntent(AlexaRequest request, AlexaResponse response)
 {
     response.Response.OutputSpeech.Text          = "Ask me a question like, who owns 411 South Fourth Street? What is my home worth? How big is 301 River Road?";
     response.Response.Reprompt.OutputSpeech.Text = response.Response.OutputSpeech.Text;
     AddHelpCard(response);
     response.Response.ShouldEndSession = false;
     return(response);
 }
Пример #27
0
 private void AddAddressCard(AlexaResponse response, string address, PvaPropertyInfo propertyInfo)
 {
     response.Response.Card.Type  = "Standard";
     response.Response.Card.Title = propertyInfo.Address.AddressDisplay;
     response.Response.Card.Text  = $"Owner: {propertyInfo.Address.Owner}\r\nAssessed Value: ${string.Format("{0:n0}", propertyInfo.Address.AssessedValue)}\r\nAcres: {propertyInfo.Address.Acreage}";
     response.Response.Card.Image.SmallImageUrl = _mapImageUrlGenerator.GetMapUrl(address, MapSize.Small);
     response.Response.Card.Image.LargeImageUrl = _mapImageUrlGenerator.GetMapUrl(address, MapSize.Large);
 }
        private AlexaResponse HelpIntent(Request request)
        {
            var speech   = "<prosody rate=\"slow\">You can say, Find All Categories or Find All Fuel Types or Find Nearest Electric stations in Virginia or Find Nearest Hybrid Stations or How many electric stations in Virginia</prosody>";
            var response = new AlexaResponse(speech, false, AddSSML(speech));

            response.Response.Reprompt.OutputSpeech.Text = "<prosody rate=\"slow\">You can say, Find All Categories or Find All Fuel Types or Find Nearest Electric stations in Virginia or Find Nearest Hybrid Stations or How many electric stations in Virginia</prosody>";
            response.Response.Reprompt.OutputSpeech.Ssml = AddSSML(speech);
            return(response);
        }
        private AlexaResponse HelloIntentHandler(Request request)
        {
            var speech   = "Hi and Welcome to Road Star, your guide to Alternative Transportation information and policy. Please issue your voice commands or say Help to get a list.";
            var response = new AlexaResponse(speech, false);

            response.Response.OutputSpeech.Ssml          = AddSSML(speech);
            response.Response.Reprompt.OutputSpeech.Text = speech;
            return(response);
        }
        public async Task SetCurrentNodeAsync(AlexaRequest req, AlexaResponse resp, string currentNodeName)
        {
            if (resp.SessionAttributes == null)
            {
                resp.SessionAttributes = new Dictionary <string, dynamic>();
            }

            resp.SessionAttributes.Add(AdventureNode.CURNODE_ATTRIB, currentNodeName);
        }