Example #1
0
        public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            string accessKey     = Environment.GetEnvironmentVariable("ACCESS_KEY");
            string secretKey     = Environment.GetEnvironmentVariable("SECRET_KEY");
            string bucketStories = Environment.GetEnvironmentVariable("BUCKET_STORIES");

            StoriesS3Service storiesService = new StoriesS3Service(accessKey, secretKey, bucketStories);

            string           audioUrl;
            string           audioToken;
            SsmlOutputSpeech ssmlResponse = new SsmlOutputSpeech();

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                ssmlResponse.Ssml = "<speak>You can't open this skill.</speak>";
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                IntentRequest intentRequest = (IntentRequest)input.Request;
                switch (intentRequest.Intent.Name)
                {
                case "TellRandomStory":
                    string randomStoryName = storiesService.GetRandomStoryName(await storiesService.ListStories());
                    audioUrl   = storiesService.GetStoryUrl(randomStoryName);
                    audioToken = "A story.";
                    return(ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioUrl, audioToken));

                default:
                    ssmlResponse.Ssml = $"<speak>An error has occurred!</speak>";
                    break;
                }
            }
            return(ResponseBuilder.Tell(ssmlResponse));
        }
Example #2
0
        private async Task <SkillResponse> GetResponse(SkillRequest request)
        {
            if (request == null)
            {
                m_logger.LogWarning("The request is malformed.");
                return(ResponseBuilder.Tell(m_messages.ErrorNotFound));
            }

            if (request.GetRequestType() == typeof(LaunchRequest))
            {
                var launchResponse = ResponseBuilder.Tell(m_messages.Launch);
                launchResponse.Response.ShouldEndSession = false;
                return(launchResponse);
            }

            if (request.GetRequestType() != typeof(IntentRequest))
            {
                m_logger.LogWarning($"The request-type {request.GetRequestType()} isn't supported.");
                return(ResponseBuilder.Tell(string.Format(m_messages.ErrorRequestTypeNotSupported, request.GetRequestType())));
            }

            var response = await m_intentHandler.GetResponseAsync(request).ConfigureAwait(false);

            return(response);
        }
Example #3
0
        public async Task <SkillResponse> HandleAlexaRequest([FromBody] SkillRequest skillRequest)
        {
            if (skillRequest.GetRequestType() == typeof(LaunchRequest))
            {
                return(ResponseBuilder.Ask(_infoResponseService.GetWelcomeMessage(), null));
            }
            else if (skillRequest.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = skillRequest.Request as IntentRequest;
                if (intentRequest.Intent.Name == "AMAZON.HelpIntent")
                {
                    return(ResponseBuilder.Ask(_infoResponseService.GetHelpMessage(), null));
                }


                if (intentRequest.Intent.Name.Contains("ZipCode"))
                {
                    var zipCode = intentRequest.Intent.Slots["ZipCode"];
                    var(response, _) = await _infoResponseService.GetResponseAsync(intentRequest.Intent.Name, zipCode.Value);

                    return(ResponseBuilder.Ask(response, null));
                }
            }

            return(ResponseBuilder.Ask(_infoResponseService.GetFallbackMessage(), null));
        }
Example #4
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            Response      response;
            AlexaResponse alexaResponse = null;

            if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.ILaunchRequest))
            {
                // default launch request, let's just let them know what you can do
                Console.WriteLine($"Default LaunchRequest made");

                alexaResponse = new AlexaResponse {
                    ResponseText = "Welcome to Noti, I can help you send quick messages to friends and family. Ask me for help to learn how to get started."
                };
            }

            else if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.IIntentRequest))
            {
                // intent request, process the intent
                Console.WriteLine($"Intent Requested {input.Request.Intent.Name}");

                alexaResponse = invokeIntent(input.Request.Intent.Name, input.Request.Intent.Slots, input.Session);
            }

            response = new Response();
            response.ShouldEndSession = alexaResponse.ShouldEndSession;
            response.OutputSpeech     = new PlainTextOutputSpeech {
                Text = alexaResponse.ResponseText
            };
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = response;
            skillResponse.Version  = "1.0";

            return(skillResponse);
        }
Example #5
0
        /// <summary>
        /// Returns bus times
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse response = new SkillResponse
            {
                Response = new ResponseBody()
            };

            response.Response.ShouldEndSession = false;
            IOutputSpeech innerResponse = null;
            var           log           = context.Logger;

            log.LogLine($"Skill Request Object:");
            log.LogLine(JsonConvert.SerializeObject(input));

            //foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
            //    log.LogLine(z.Id);

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine($"Default LaunchRequest made: 'Alexa, open Busplan");
                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text =
                    GetNextBusAnnouncement(Moltkestrasse, Uni) +
                    GetNextBusAnnouncement(Moltkestrasse, Bahnhof);
                response.Response.ShouldEndSession = true;
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;

                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                case "AMAZON.StopIntent":
                    log.LogLine($"{intentRequest.Intent.Name}: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "Stopped";
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.HelpIntent":
                    log.LogLine($"AMAZON.HelpIntent: send HelpMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "Help";
                    break;

                default:
                    log.LogLine($"default intent: " + intentRequest.Intent.Name);
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = "default";
                    break;
                }
            }

            response.Response.OutputSpeech = innerResponse;
            response.Version = "1.0";
            log.LogLine($"Skill Response Object...");
            log.LogLine(JsonConvert.SerializeObject(response));
            return(response);
        }
Example #6
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            //standard stuff
            var requestType = input.GetRequestType();

            _logger    = context.Logger;
            _alexaUser = input.Session.User.UserId;
            SetStandardResponse();

            if (requestType == typeof(LaunchRequest))
            {
                _logger.LogLine($"Default LaunchRequest made: 'Strava, open Jira");
                (_innerResponse as PlainTextOutputSpeech).Text = "Welcome to the Strava skill. Ask me some questions";
            }

            if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;


                switch (intentRequest.Intent.Name)
                {
                case "GetLastActivityIntent":
                    GetLastActivityIntent();
                    break;

                default:
                    _logger.LogLine($"Unknown intent: {intentRequest.Intent.Name}");
                    (_innerResponse as PlainTextOutputSpeech).Text = "Sorry, Strava cant answer that question yet";
                    break;
                }
            }

            return(_response);
        }
Example #7
0
        public async Task <SkillResponse> Run(SkillRequest skillRequest, ILambdaContext context)
        {
            var userId = skillRequest.Context.System.User.UserId;

            if (skillRequest.GetRequestType() == typeof(LaunchRequest))
            {
                const string msg = "Hey. What can I do for you?";
                return(ResponseBuilder.Ask(msg, new Reprompt("Sorry. I don't know what you mean.")));
            }

            if (skillRequest.GetRequestType() == typeof(SessionEndedRequest))
            {
                const string msg = "See you later";
                return(ResponseBuilder.Tell(msg));
            }

            if (skillRequest.GetRequestType() == typeof(SkillEventRequest))
            {
                // todo: check enable / disable
                var eventRequest = (SkillEventRequest)skillRequest.Request;
                if (eventRequest.Type == "AlexaSkillEvent.SkillDisabled")
                {
                }
            }

            var actualIntentRequest = (IntentRequest)skillRequest.Request;
            var handler             = _handlers.FirstOrDefault(x => x.Name == actualIntentRequest.Intent.Name);

            if (handler == null)
            {
                return(TellWithoutEnding("Sorry. I don't know what you mean."));
            }

            var user = await _userStorageService.GetAsync(userId);

            if (user == null)
            {
                user = new SpotifyUser(userId);
                await _userStorageService.SaveAsync(user);
            }

            try
            {
                await handler.VerifySession(skillRequest);

                await handler.BuildSpotifySession(skillRequest);

                return(await handler.HandleIntent(skillRequest, actualIntentRequest, context));
            }
            catch (Exception ex)
            {
                if (ex is AccessTokenMissingException)
                {
                    return(ResponseBuilder.Tell("AccessToken is missing. Please link your account"));
                }

                return(ResponseBuilder.Tell(ex.Message));
            }
        }
Example #8
0
        public Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            if (!_requestStrategy.ContainsKey(input.GetRequestType()))
            {
                throw new Exception("Unknown request type.");
            }

            return(_requestStrategy[input.GetRequestType()](input));
        }
Example #9
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            IOutputSpeech innerResponse    = null;
            var           log              = context.Logger;
            var           shouldEndSession = false;

            log.LogLine(JsonConvert.SerializeObject(input));

            if (input.GetRequestType() == typeof(ILaunchRequest))
            {
                // default launch request, let's just let them know what you can do
                log.LogLine("Default LaunchRequest made");

                innerResponse = Help;
            }
            else if (input.GetRequestType() == typeof(IIntentRequest))
            {
                // intent request, process the intent
                log.LogLine($"Intent Requested {input.Request.Intent.Name}");

                switch (input.Request.Intent.Name)
                {
                case "QuestionIntent":
                    innerResponse    = RandomAnswer;
                    shouldEndSession = true;
                    break;

                case "AMAZON.HelpIntent":
                    innerResponse = Help;
                    break;

                case "AMAZON.StopIntent":
                case "AMAZON.CancelIntent":
                    innerResponse    = End;
                    shouldEndSession = true;
                    break;

                default:
                    innerResponse = Error;
                    break;
                }
            }

            var response = new Response
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = innerResponse
            };

            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            return(skillResponse);
        }
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            IOutputSpeech innerResponse = null;
            var           result        = 0;

            if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.ILaunchRequest))
            {
                innerResponse = new PlainTextOutputSpeech();
                ((PlainTextOutputSpeech)innerResponse).Text = "Welcome to number functions.  You can ask us to add numbers!";
            }
            else if (input.GetRequestType() == typeof(Slight.Alexa.Framework.Models.Requests.RequestTypes.IIntentRequest))
            {
                Debug.WriteLine(input.Request.Intent.Name);

                var firstNumber  = Convert.ToDouble(input.Request.Intent.Slots["firstnum"].Value);
                var secondNumber = Convert.ToDouble(input.Request.Intent.Slots["secondnum"].Value);
                switch (input.Request.Intent.Name)
                {
                case "AddIntent":
                    result = (int)(firstNumber + secondNumber);
                    break;

                case "SubtractIntent":
                    result = (int)(firstNumber - secondNumber);
                    break;

                case "MultiplyIntent":
                    result = (int)(firstNumber * secondNumber);
                    break;

                case "DivideIntent":
                    result = (int)(firstNumber / secondNumber);
                    break;

                default:
                    result = 42;
                    break;

                    innerResponse = new PlainTextOutputSpeech();
                    ((PlainTextOutputSpeech)innerResponse).Text = $"The result is {result}.";
                }
            }


            var response = new Response
            {
                ShouldEndSession = true,
                OutputSpeech     = innerResponse
            };
            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            return(skillResponse);
        }
Example #11
0
        public async Task <SkillResponse> RouteRequest(SkillRequest input)
        {
            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                await _mixpanel.TrackAsync("Launch", new {});

                return(await GetLaunchRequestResponse());
            }
            if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;
                await _mixpanel.TrackAsync("Intent", new { Name = intentRequest.Intent.Name });

                if (intentRequest.Intent.Name == "InboxIntent")
                {
                    return(await GetInboxIntentResponse());
                }
                if (intentRequest.Intent.Name == "HotQuestionIntent")
                {
                    return(await GetHotQuestionIntentResponse());
                }
                if (intentRequest.Intent.Name == "HotQuestionDetailsIntent")
                {
                    return(await GetHotQuestionDetailsIntentResponse());
                }
                if (intentRequest.Intent.Name == "HotQuestionAnswersIntent")
                {
                    return(await GetHotQuestionAnswersIntentResponse());
                }
                if (intentRequest.Intent.Name == "UpvoteIntent")
                {
                    return(await GetUpvoteIntentResponse());
                }
                if (intentRequest.Intent.Name == "DownvoteIntent")
                {
                    return(await GetDownvoteIntentResponse());
                }
                if (intentRequest.Intent.Name == "FavoriteIntent")
                {
                    return(await GetFavoriteIntentResponse());
                }
                if (intentRequest.Intent.Name == "AMAZON.HelpIntent")
                {
                    return(CreateResponse(HelpText + MainMenuOptions));
                }
                if (intentRequest.Intent.Name == "AMAZON.CancelIntent")
                {
                    return(CreateResponse("Ok, bye!", true));
                }
                if (intentRequest.Intent.Name == "AMAZON.StopIntent")
                {
                    return(CreateResponse("Ok, bye!", true));
                }
            }
            return(CreateResponse("Sorry, not sure what you're saying."));
        }
Example #12
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse response = new SkillResponse
            {
                Response = new ResponseBody
                {
                    ShouldEndSession = false
                }
            };

            log = context.Logger;


            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                Log($"Default LaunchRequest made: 'Alexa, open Medicine Dosage'");
                response = MakeSkillResponse("I'm ready to help you calculate Medicine Dosing. What is the medicine you're dispensing?",
                                             false);
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = input.Request as IntentRequest;
                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                    Log($"AMAZON.CancelIntent: send StopMessage");
                    response = MakeSkillResponse("OK, Goodbye.", true);
                    break;

                case "AMAZON.StopIntent":
                    Log($"AMAZON.StopIntent: send StopMessage");
                    response = MakeSkillResponse("OK, Goodbye.", true);
                    break;

                case "AMAZON.HelpIntent":
                    Log($"AMAZON.HelpIntent: send HelpMessage");
                    response = MakeSkillResponse("I'll help you figure out how much medicine to administer, based on the animal's weight, the prescribed dose, and the medicine concentration.", false);
                    break;

                case "GetMedicineDose":
                    Log($"GetMedicineDoseIntent sent: Get the name of the medicine.");
                    response = GetMedicineDose(intentRequest, input, response);
                    break;

                default:
                    Log($"Unknown intent: " + intentRequest.Intent.Name);
                    response = MakeSkillResponse("You can say Get dosage for a medicine to get started.", false);
                    break;
                }
            }
            Log($"Skill Response Object...");
            Log(JsonConvert.SerializeObject(response));
            return(response);
        }
Example #13
0
        //This is the base function of the alexa skill. It will direct the input to the correct handler
        //as configured above.
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            AddIntentListeners();
            SetLaunchRequestHandler();
            SetAccountLinkHandler();
            SetSessionEndHandler();

            if (input.GetRequestType() == typeof(IntentRequest))
            {
                var _Request = input.Request as IntentRequest;

                foreach (IRequestHandler handler in IntentHandlers)
                {
                    if (handler.Name.ToLower() == _Request.Intent.Name.ToLower())
                    {
                        return(handler.Run(_Request));
                    }
                }

                return(new FallbackIntent().Run(null));
            }
            else if (input.GetRequestType() == typeof(LaunchRequest))
            {
                var _Request = input.Request as LaunchRequest;
                if (LaunchHandler != null)
                {
                    return(LaunchHandler.Run(_Request));
                }

                return(new FallbackIntent().Run(null));
            }
            else if (input.GetRequestType() == typeof(AccountLinkSkillEventRequest))
            {
                var _Request = input.Request as AccountLinkSkillEventRequest;
                if (AccountLinkHandler != null)
                {
                    return(AccountLinkHandler.Run(_Request));
                }

                return(new FallbackIntent().Run(null));
            }
            else if (input.GetRequestType() == typeof(SessionEndedRequest))
            {
                var _Request = input.Request as SessionEndedRequest;
                if (SessionEndHandler != null)
                {
                    return(SessionEndHandler.Run(_Request));
                }

                return(new FallbackIntent().Run(null));
            }

            return(new FallbackIntent().Run(null));
        }
Example #14
0
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse skillResponse = new SkillResponse();

            skillResponse.Response = new ResponseBody
            {
                ShouldEndSession = false
            };

            IOutputSpeech outputSpeech = null;

            var log = context.Logger;

            if (input.GetRequestType() == typeof(LaunchRequest))
            { // einfacher Aufruf des Skills ohne Aufgabenstellung ( Intent )
              //  log.LogLine("(Line:45) Der Skill " + skillName + " wurde gelaunched.");

                outputSpeech = new PlainTextOutputSpeech();
                (outputSpeech as PlainTextOutputSpeech).Text = "Ich bin bereit ";
            }
            else if (input.GetRequestType() == typeof(IntentRequest)) // hier werden alle nicht 'LaunchRequests' behandelt
            {
                var typeOfTntent = (IntentRequest)input.Request;
                log.LogLine("(Line:53)Ein " + typeOfTntent.ToString() + " wurde erkannt");
                switch (typeOfTntent.Intent.Name)
                {
                // case "CustomIntent":
                //
                //
                // break;
                case "AMAZON.CancelIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Jawohl, ich hƶre auf";
                    break;

                case   "AMAZON.StopIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Bis zum nƤchsten mal ";
                    break;

                case   "AMAZON.HelpIntent":
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = "Hilf dir selbst ";
                    break;

                default:
                    outputSpeech = new PlainTextOutputSpeech();
                    (outputSpeech as PlainTextOutputSpeech).Text = typeOfTntent.ToString() + "als " + typeOfTntent.Intent.Name + " erkannt." + " Das werde ich ignorieren "; break;
                }
            }
            skillResponse.Response.OutputSpeech = outputSpeech;
            skillResponse.Version = "1.0";
            return(skillResponse);
        }
Example #15
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var response = new SkillResponse();

            response.Response = new ResponseBody();
            response.Response.ShouldEndSession = false;
            PlainTextOutputSpeech innerResponse = null;
            var log = context.Logger;

            var allResources = GetResources();
            var resource     = allResources.FirstOrDefault();

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine("Default LaunchRequest made: Alexa, open Science Facts");
                innerResponse      = new PlainTextOutputSpeech();
                innerResponse.Text = emitNewFact(resource, true);
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = input.Request as IntentRequest;
                innerResponse = new PlainTextOutputSpeech();
                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                case "AMAZON.StopIntent":
                    log.LogLine($"{intentRequest.Intent.Name}: send StopMessage");
                    innerResponse.Text = resource.StopMessage;
                    response.Response.ShouldEndSession = true;
                    break;

                case "AMAZON.HelpIntent":
                    log.LogLine("AMAZON.HelpIntent: send HelpMessage");
                    innerResponse.Text = resource.HelpMessage;
                    break;

                case "GetFactIntent":
                case "GetNewFactIntent":
                    log.LogLine($"{intentRequest.Intent.Name}: send new fact");
                    innerResponse.Text = emitNewFact(resource, false);
                    break;

                default:
                    log.LogLine($"Unknown Intent: {intentRequest.Intent.Name}");
                    innerResponse.Text = resource.HelpReprompt;
                    break;
                }
            }

            response.Response.OutputSpeech = innerResponse as IOutputSpeech;
            response.Version = "1.0";
            return(response);
        }
        // we will have a similar method for dialog flow for google
        private string GetAlexaIntentName(SkillRequest input)
        {
            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                return("WelcomeIntent");
            }
            if (input.GetRequestType() == typeof(IntentRequest))
            {
                return((input.Request as IntentRequest).Intent.Name.Replace("AMAZON.", string.Empty));
            }

            return(null);
        }
        public SkillResponse bestil([FromBody] SkillRequest request)
        {
            Session session = request.Session;

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

            SkillResponse response = ResponseBuilder.Empty();

            _log.LogInformation("Hello, world!");
            if (request.GetRequestType() == typeof(LaunchRequest))
            {
                response = _launchRequest.Launch(session).Result;
            }
            else if (request.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)request.Request;
                switch (intentRequest.Intent.Name)
                {
                case "AddPrayerIntent":
                    response = _addPrayerIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;

                case "ClearPrayerIntent":
                    response = _clearPrayerIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;

                case "AMAZON.YesIntent":
                    response = _amazonYesIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;

                case "SavePrayerIntent":
                    response = _savePrayerIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;

                case "ArchivePrayerIntent":
                    response = _archivePrayerIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;

                case "ViewPrayerIntent":
                    response = _viewPrayerIntentHandler.HandleIntent(intentRequest, session, request).Result;
                    break;
                }
            }

            return(response);
        }
 public virtual bool CanHandle(SkillRequest request)
 {
     if (request.GetRequestType() != RequestType)
     {
         return(false);
     }
     if (request.GetRequestType() == typeof(IntentRequest))
     {
         if ((request?.Request as IntentRequest)?.Intent?.Name != IntentName)
         {
             return(false);
         }
     }
     return(true);
 }
 public async Task <SkillResponse> HandleRequestAsync(SkillRequest skillRequest)
 {
     if (skillRequest.GetRequestType() == typeof(LaunchRequest))
     {
         logger.LogDebug($"Handling {nameof(LaunchRequest)}");
         return(CreateLaunchRequestResponse());
     }
     if (skillRequest.GetRequestType() == typeof(IntentRequest))
     {
         logger.LogDebug($"Handling {nameof(IntentRequest)}");
         return(await CreateIntentRequestResponseAsync(skillRequest.Request as IntentRequest));
     }
     logger.LogWarning($"Encountered unknown {nameof(SkillRequest)}");
     return(CreateErrorResponse());
 }
Example #20
0
        public SkillResponse HandleResponse([FromBody] SkillRequest input)
        {
            var requestType = input.GetRequestType();

            // return a welcome message
            if (requestType == typeof(LaunchRequest))
            {
                return(ResponseBuilder.Ask("Welcome to animal facts, ask me about information on an animal", null));
            }

            // return information from an intent
            else if (requestType == typeof(IntentRequest))
            {
                // do some intent-based stuff
                var intentRequest = input.Request as IntentRequest;

                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("AnimalFactIntent"))
                {
                    // get the slots
                    var animal = intentRequest.Intent.Slots["Animal"].Value;
                    if (animal == null)
                    {
                        return(ResponseBuilder.Ask("You forgot to ask about an animal! Please try again.", null));
                    }

                    return(ResponseBuilder.Tell($"I would normally tell you facts about ${animal} but I'm not a real skill yet."));
                }
            }

            return(ResponseBuilder.Ask("I didn't understand that, please try again!", null));
        }
Example #21
0
        public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var requestType = input.GetRequestType();

            if (requestType == typeof(IntentRequest))
            {
                var intentRequest    = input.Request as IntentRequest;
                var countryRequested = intentRequest?.Intent?.Slots["Country"].Value;

                if (countryRequested == null)
                {
                    context.Logger.LogLine($"The country was not understood.");
                    return(MakeSkillResponse("I'm sorry, but I didn't understand the country you were asking for. Please ask again.", false));
                }
                //Just for fun..!
                //if(countryRequested == "I love you")
                //{
                //    return MakeSkillResponse("Bhag yaha se. I respect your feelings but I am sorry.", false);
                //}

                var countryInfo = await GetCountryInfo(countryRequested, context);

                var outputText = $"About {countryInfo.name}. The capitol is {countryInfo.capital}, and the population is {countryInfo.population}.";

                return(MakeSkillResponse(outputText, true));
            }
            else
            {
                return(MakeSkillResponse(
                           $"I don't know how to handle this intent. Please say something like Alexa, ask {INVOCATION_NAME} about Canada.",
                           true));
            }
        }
Example #22
0
        private async Task <IActionResult> ProcessRequest(SkillRequest skillRequest)
        {
            var           requestType = skillRequest.GetRequestType();
            SkillResponse response    = null;

            if (requestType == typeof(LaunchRequest))
            {
                response = ResponseBuilder.Tell("Welcome a Dotnet Marraia temperature. Create By Fernando Mendes");
                response.Response.ShouldEndSession = false;
            }
            else if (requestType == typeof(IntentRequest))
            {
                var intentRequest = skillRequest.Request as IntentRequest;
                if (intentRequest.Intent.Name == "AddIntent")
                {
                    var speech = new SsmlOutputSpeech();
                    var result = await GetTemperature();

                    speech.Ssml = $"<speak>The temperature in jundiaĆ­ at this moment is { result} degrees</speak>";

                    response = ResponseBuilder.TellWithCard(speech, "The answer is", $"The answer is: {result}");
                    response.Response.ShouldEndSession = false;
                }
            }
            else if (requestType == typeof(SessionEndedRequest))
            {
                var speech = new SsmlOutputSpeech();
                speech.Ssml = $"<speak>Bye Bye Marraia!!</speak>";

                response = ResponseBuilder.TellWithCard(speech, "Bye Bye Marraia", "Marraia");
                response.Response.ShouldEndSession = true;
            }
            return(new OkObjectResult(response));
        }
Example #23
0
        public SkillResponse HandleResponse([FromBody] SkillRequest input)
        {
            //test change to trigger PR2.
            var requestType = input.GetRequestType();

            // return a welcome message
            if (requestType == typeof(LaunchRequest))
            {
                return(ResponseBuilder.Ask("Welcome to the GitHub pull request count skill.", null));
            }

            // return information from an intent
            else if (requestType == typeof(IntentRequest))
            {
                // do some intent-based stuff
                var intentRequest = input.Request as IntentRequest;

                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("GitHubPullRequest"))
                {
                    // get the pull requests
                    var pullrequests = CountPullRequests();

                    if (pullrequests == 0)
                    {
                        return(ResponseBuilder.Tell("You have no pull requests at this time."));
                    }

                    return(ResponseBuilder.Tell("There are " + pullrequests.ToString() + " pull requests waiting for you at GitHub.com."));
                }
            }

            return(ResponseBuilder.Ask("I don't understand. Can you please try again?", null));
        }
        public dynamic Alexa([FromBody] SkillRequest request)
        {
            if (request.Context.System.ApiAccessToken == null)
            {
                return(new BadRequestResult());
            }

            var response    = AlexaAntwortHelfer.GibEinfacheAntwort(request, SkillTypen.Error, FehlerTypen.FehlerAnfrage.ToDescription(), "", null, DateTime.Now, null);
            var requestType = request.GetRequestType();

            if (requestType == typeof(LaunchRequest))
            {
                response = LaunchRequestHandler(request);
            }

            else if (requestType == typeof(IntentRequest))
            {
                response = IntentRequestHandler(request);
            }

            else if (requestType == typeof(SessionEndedRequest))
            {
                response = SessionEndedRequestHandler(request);
            }

            return(response);
        }
Example #25
0
        public async Task <SkillResponse> Handle(SkillRequest input, ILambdaContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Logger.LogLine($"Request type is {input.Request.GetType()} ({input.GetRequestType()})");

            switch (input.Request)
            {
            case LaunchRequest _:
                return(await HandleLaunchRequestAsync());

            case IntentRequest intentRequest:
                return(await HandleIntentRequestAsync(input, intentRequest));

            case SessionEndedRequest _:
                return(await HandleSessionEndedRequestAsync());
            }

            throw new ArgumentException("Unsupported input!");
        }
        public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var requestType = input.GetRequestType();

            if (requestType == typeof(IntentRequest))
            {
                if (input.Request is IntentRequest intentRequest)
                {
                    if (intentRequest.Intent.Slots.ContainsKey("Origin") && intentRequest.Intent.Slots.ContainsKey("Destiny"))
                    {
                        var      originCode  = CityNameCityCodeMapper.MapToCode(intentRequest.Intent.Slots["Origin"].Value.ToLower());
                        var      destinyCode = CityNameCityCodeMapper.MapToCode(intentRequest.Intent.Slots["Destiny"].Value.ToLower());
                        DateTime?date        = intentRequest.Intent.Slots.ContainsKey("Date")
                            ? DateTime.Parse(intentRequest.Intent.Slots["Date"].Value)
                            : (DateTime?)null;

                        var response = await GetItineraryInfo(originCode, destinyCode, date, context);

                        return(MakeSkillResponse(response, false));
                    }
                }
                else
                {
                    context.Logger.LogLine($"The country was not understood.");
                    return(MakeSkillResponse("I'm sorry, but I didn't understand the country you were asking for. Please ask again.", false));
                }
            }
            return(MakeSkillResponse(
                       $"I don't know how to handle this intent. Please say something like Alexa, ask {INVOCATION_NAME} from New York City to Los Angeles.",
                       true));
        }
        internal static CommonModel AlexaToCommonModel(SkillRequest skillRequest)
        {
            var commonModel = new CommonModel()
            {
                Id = skillRequest.Request.RequestId
            };

            var requestType = skillRequest.GetRequestType();

            commonModel.Request.Channel = "alexa";

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

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

            return(commonModel);
        }
Example #28
0
        public static string SwitchInput(SkillRequest data)
        {
            var requestType = data.GetRequestType().Name;

            switch (requestType.ToString())
            {
            case "IntentRequest":
                var intentRequest = data.Request as IntentRequest;

                if (intentRequest.Intent.Name == "menuitemdescription")
                {
                    var itemName = intentRequest.Intent?.Slots["item"]?.Value;

                    if (itemName == null || string.IsNullOrEmpty(itemName))
                    {
                        return("please provide a valid food item");
                    }
                    return($"Ok searching for {itemName}. {MenuItemDescription.ItemDescription(itemName)}");
                }

                return("Sorry!!!, I dont understand");

            case "LaunchRequest":
                return("Hello! Welcome to My Alex Restaurant. I can help you to order and to view the item description. Try asking: Tell me the description for the menu Kulcha Tub");

            case "SessionEndedRequest":
                return("Good bye !! see you!");

            default:
                return("Sorry!!!, I dont understand");
            }
        }
        public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var requestType = input.GetRequestType();

            if (requestType == typeof(IntentRequest))
            {
                var        inputRequest = input.Request as IntentRequest;
                DataBreach db           = new DataBreach();
                var        email        = inputRequest?.Intent.Slots["Email"].Value;

                var apiresponse = await db.CheckEMailInBreach(email);

                string speak;
                switch (apiresponse)
                {
                case Codes.Yes:
                    speak = $"{email} has been in a databreach, change any passwords now!";
                    break;

                case Codes.No:
                    speak = $"{email} has not been in a databreach";
                    break;

                default:
                    speak = $"I'm sorry, there has been an exception. Please re-try";
                    break;
                }
                return(MakeSkillResponse(
                           speak,
                           true));
            }
            return(MakeSkillResponse(
                       $"I don't know how to handle this intent. Please say something like Alexa, ask {INVOCATION_NAME} if [email protected] address was in a breach.",
                       true));
        }
Example #30
0
        //https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=52.19,51.84,0.72,1.65&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=14400&gliders=1&stats=1&selected=119f9a3c&ems=1


        //static void LoadAirportCodes


        /// <summary>
        /// Air Traffic Alexa custom skill entry point
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            try
            {
                context.Log("SkillRequest", JsonConvert.SerializeObject(input));
                context.Log("Context", JsonConvert.SerializeObject(context));

                SkillResponse response = null;

                // check what type of a request it is like an IntentRequest or a LaunchRequest
                var requestType = input.GetRequestType();

                if (requestType == typeof(IntentRequest))
                {
                    response = HandleIntentRequest(input, context);
                }
                else if (requestType == typeof(Alexa.NET.Request.Type.LaunchRequest))
                {
                    response = HandleLaunchRequest(input, context);
                }
                //else if (requestType == typeof(AudioPlayerRequest))
                //{
                //    return HandleAudioPlayerRequest(input, context);
                //}

                context.Log("ResponseBody", JsonConvert.SerializeObject(response));
                return(response);
            }
            catch (Exception ex)
            {
                context.Log("Error", "error :" + ex.Message);
            }
            return(null);
        }