/// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] != null && json.Value <string>("version") != Sdk.VERSION)
            {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            JObject          requestJson = json.Value <JObject>("request");
            string           requestType = requestJson.Value <string>("type");
            string           requestId   = requestJson.Value <string>("requestId");
            DateTime         timestamp   = requestJson.Value <DateTime>("timestamp");
            string           token       = requestJson.Value <string>("token");
            long             offset      = requestJson.Value <long>("offsetInMilliseconds");
            string           type        = requestJson.Value <string>("type");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp);
                break;

            case "IntentRequest":
                request = new IntentRequest(requestId, timestamp,
                                            Intent.FromJson(requestJson.Value <JObject>("intent")));
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason;
                Enum.TryParse <SessionEndedRequest.ReasonEnum>(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, reason);
                break;

            default:
                if (requestType.StartsWith("PlaybackController") || requestType.StartsWith("AudioPlayer"))
                {
                    request = new AudioPlayerRequest(requestId, timestamp, token, offset, type);
                }
                else if (requestType == "System.ExceptionEncountered")
                {
                    request = null;
                }
                else
                {
                    throw new ArgumentException("json");
                }
                break;
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version"),
                Context = Context.FromJson(json.Value <JObject>("context"))
            });
        }
        public override async Task OnSessionEndedAsync(SessionEndedRequest request, Session session)
        {
            Task t = AskTeenageQueue.AddAsync(JsonConvert.SerializeObject(request));

            Logger.Info($"OnSessionStarted requestId={request.RequestId}, sessionId={session.SessionId}");
            await t;
        }
Exemplo n.º 3
0
        private SkillResponse getError(SkillRequest input)
        {
            SessionEndedRequest error = input.Request as SessionEndedRequest;
            string message            = error.Error.Message;

            switch (error.Error.Type)
            {
            case ErrorType.InvalidResponse:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.DeviceCommunicationError:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.InternalError:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.MediaErrorUnknown:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.InvalidMediaRequest:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.MediaServiceUnavailable:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.InternalServerError:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            case ErrorType.InternalDeviceError:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));

            default:
                return(createAnswer("Fehler.", false, _session, "hmmm", message));
            }
        }
Exemplo n.º 4
0
        static SkillResponse HandleSessionEndedRequest(SessionEndedRequest request)
        {
            var response = ResponseBuilder.Empty();

            response.Response.ShouldEndSession = true;
            return(response);
        }
Exemplo n.º 5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            string json = await req.ReadAsStringAsync();

            var skillRequest = JsonConvert.DeserializeObject <SkillRequest>(json);

            var requestType = skillRequest.GetRequestType();

            AlexaService alexaService = new AlexaService(skillRequest);

            if (requestType == typeof(LaunchRequest))
            {
                return(new OkObjectResult(await alexaService.WelcomeMessage()));
            }
            if (requestType == typeof(SessionEndedRequest))
            {
                SessionEndedRequest sessionReq = skillRequest.Request as SessionEndedRequest;

                //log.LogError(sessionReq.Reason.ToString());
                return(new OkObjectResult(String.Empty));
            }

            if (requestType == typeof(IntentRequest))
            {
                var intentRequest = skillRequest.Request as IntentRequest;
                return(new OkObjectResult(await alexaService.ManageIntent(intentRequest)));
            }
            return(new OkObjectResult("OK"));
        }
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     if (AlexaUtils.IsRequestInvalid(session))
     {
         return(Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
     }
     return(Task.Delay(0));
 }
Exemplo n.º 7
0
        static SkillResponse HandleSessionEndedRequest(SessionEndedRequest request, ILogger log)
        {
            log.LogInformation("Session ended");
            var response = ResponseBuilder.Empty();

            response.Response.ShouldEndSession = true;

            return(response);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] == null || json["session"] == null || json["request"] == null)
            {
                throw new SpeechletException("Request does not conform to schema");
            }

            if (json.Value <string>("version") != Sdk.VERSION)
            {
                // will still attempt to parse request content but might be useful to log a warning
            }

            SpeechletRequest request;
            JObject          requestJson = json.Value <JObject>("request");
            string           requestType = requestJson.Value <string>("type");
            string           requestId   = requestJson.Value <string>("requestId");
            DateTime         timestamp   = requestJson.Value <DateTime>("timestamp");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp);
                break;

            case "IntentRequest":
                request = new IntentRequest(requestId, timestamp,
                                            Intent.FromJson(requestJson.Value <JObject>("intent")));
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason;
                Enum.TryParse <SessionEndedRequest.ReasonEnum>(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, reason);
                break;

            default:
                throw new ArgumentException("json");
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version")
            });
        }
Exemplo n.º 9
0
        public void ShouldHandleSessionEnded()
        {
            var skill = new ScienceFactsSkill();

            var request      = new SkillRequest();
            var sessionEnded = new SessionEndedRequest();

            request.Request = sessionEnded;


            var result = skill.FunctionHandler(request, null);
            var output = result.Response.OutputSpeech;

            Assert.AreEqual(result.Response.ShouldEndSession, true);
        }
Exemplo n.º 10
0
        public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
        {
            // this function is invoked when a user ends a session with your skill
            // this is a chance to save user data at the end of a session

            // if the inbound request doesn't include your Alexa Skills AppId or you haven't updated your
            // code to include the correct AppId, return a visual and vocal error and do no more
            // Update the AppId variable in AlexaConstants.cs to resolve this issue

            if (AlexaUtils.IsRequestInvalid(session))
            {
                return(Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
            }
            // to-do - up to you
            // return some sort of Task per function definition
            return(Task.Delay(0));
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] != null && json.Value <string>("version") != Sdk.VERSION)
            {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            JObject          requestJson = json.Value <JObject>("request");
            string           requestType = requestJson.Value <string>("type");
            string           requestId   = requestJson.Value <string>("requestId");
            //DateTime timestamp = requestJson.Value<DateTime>("timestamp");
            DateTime timestamp = DateTimeUtils.FromAmazonRequest(requestJson.Value <string>("timestamp"));

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp);
                break;

            case "IntentRequest":
                request = new IntentRequest(requestId, timestamp,
                                            Intent.FromJson(requestJson.Value <JObject>("intent")));
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason;
                Enum.TryParse <SessionEndedRequest.ReasonEnum>(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, reason);
                break;

            default:
                throw new ArgumentException("json");
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version")
            });
        }
Exemplo n.º 12
0
        public async Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session, Context context)
        {
            switch (sessionEndedRequest.Reason)
            {
            case SessionEndedRequest.ReasonEnum.ERROR:
                await logHelper.Log($"User {session.User.Id} ended session {session.SessionId} with error");

                break;

            case SessionEndedRequest.ReasonEnum.EXCEEDED_MAX_REPROMPTS:
                await logHelper.Log($"User {session.User.Id} ended session {session.SessionId} due to lack of matching uttenancies");

                break;

            default:
                await logHelper.Log($"User {session.User.Id} ended session {session.SessionId}");

                break;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] != null && json.Value <string>("version") != Sdk.VERSION)
            {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            JObject          requestJson = json.Value <JObject>("request");
            string           requestType = requestJson.Value <string>("type");
            string           requestId   = requestJson.Value <string>("requestId");
            DateTime         timestamp   = requestJson.Value <DateTime>("timestamp");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp);
                break;

            case "IntentRequest":
                string intentName = "";
                intentName = requestJson.Value <JObject>("intent").Value <string>("name");
                if (intentName == "AMAZON.NextIntent")
                {
                    request = new AudioIntentRequest(requestId, timestamp,
                                                     Intent.FromJson(requestJson.Value <JObject>("intent")));
                    return(new SpeechletRequestEnvelope
                    {
                        Request = request,
                        Version = json.Value <string>("version"),
                        Context = Context.FromJson(json.Value <JObject>("context"))
                    });
                }
                request = new IntentRequest(requestId, timestamp,
                                            Intent.FromJson(requestJson.Value <JObject>("intent")));
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason;
                Enum.TryParse <SessionEndedRequest.ReasonEnum>(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, reason);
                break;

            case "AudioPlayer.PlaybackNearlyFinished":
                request = new AudioPlayerRequest(requestId, timestamp);
                break;

            default:
                System.Diagnostics.Debug.WriteLine("Unhandled requestType" + requestType);
                throw new ArgumentException("json");
            }

            if (requestType == "AudioPlayer.PlaybackNearlyFinished")
            {
                return(new SpeechletRequestEnvelope
                {
                    Request = request,
                    Version = json.Value <string>("version"),
                    Context = Context.FromJson(json.Value <JObject>("context"))
                });
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version")
            });
        }
Exemplo n.º 14
0
 public override void OnSessionEnded(SessionEndedRequest sessionEndedRequest, Session session)
 {
 }
Exemplo n.º 15
0
 public Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session, Context context)
 {
     return(Task.Delay(0)); // nothing to do (yet)
 }
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     return(Task.Delay(0));
 }
Exemplo n.º 17
0
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     return(Task.Run(() => { }));
 }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] != null && json["version"].Value <string>() != Sdk.VERSION)
            {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            var requestJson      = json.Value <JObject>("request");
            var requestTypeParts = requestJson?.Value <string>("type")?.Split('.');

            if (requestTypeParts == null)
            {
                throw new ArgumentException("json");
            }

            var requestType    = requestTypeParts[0];
            var requestSubType = requestTypeParts.Length > 1 ? requestTypeParts[1] : null;

            var requestId = requestJson?.Value <string>("requestId");
            var timestamp = DateTimeHelpers.FromAlexaTimestamp(requestJson);
            var locale    = requestJson?.Value <string>("locale");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp, locale);
                break;

            case "IntentRequest":
                IntentRequest.DialogStateEnum dialogState = IntentRequest.DialogStateEnum.NONE;
                Enum.TryParse(requestJson.Value <string>("dialogState"), out dialogState);
                var intent = Intent.FromJson(requestJson.Value <JObject>("intent"));
                request = new IntentRequest(requestId, timestamp, locale, intent, dialogState);
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp, locale);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason = SessionEndedRequest.ReasonEnum.NONE;
                Enum.TryParse(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, locale, reason);
                break;

            case "AudioPlayer":
                var token                = requestJson?.Value <string>("token");
                var offset               = requestJson?.Value <long>("offsetInMilliseconds") ?? 0;
                var playbackError        = Error.FromJson(requestJson?.Value <JObject>("error"));
                var currentPlaybackState = PlaybackState.FromJson(requestJson?.Value <JObject>("currentPlaybackState"));
                switch (requestSubType)
                {
                case "PlaybackFailed":
                    request = new AudioPlayerPlaybackFailedRequest(requestId, timestamp, locale, requestSubType, token, playbackError, currentPlaybackState);
                    break;

                default:
                    request = new AudioPlayerRequest(requestId, timestamp, locale, requestSubType, token, offset);
                    break;
                }
                break;

            case "PlaybackController":
                request = new PlaybackControllerRequest(requestId, timestamp, locale, requestSubType);
                break;

            case "Display":
                var listItemToken = requestJson?.Value <string>("token");
                request = new DisplayRequest(requestId, timestamp, locale, requestSubType, listItemToken);
                break;

            case "System":
                switch (requestSubType)
                {
                case "ExceptionEncountered":
                    var error = Error.FromJson(requestJson?.Value <JObject>("error"));
                    var cause = Cause.FromJson(requestJson?.Value <JObject>("cause"));
                    request = new SystemExceptionEncounteredRequest(requestId, timestamp, locale, requestSubType, error, cause);
                    break;

                default:
                    throw new ArgumentException("json");
                }
                break;

            default:
                throw new ArgumentException("json");
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version"),
                Context = Context.FromJson(json.Value <JObject>("context"))
            });
        }
Exemplo n.º 19
0
        private SkillResponse HandleEnded(SessionEndedRequest endedRequest, ILambdaLogger logger)
        {
            logger.LogLine($"EndedRequest made");

            return(null);
        }
Exemplo n.º 20
0
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     Log.Info(string.Format("OnSessionEndedAsync requestId={0}, sessionId={1}", sessionEndedRequest.RequestId, session.SessionId));
     return(Task.CompletedTask);
 }
 public void OnSessionEnded(SessionEndedRequest request, Session session, Context context)
 {
     Log.Info("OnSessionEnded requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
 public override void OnSessionEnded(SessionEndedRequest request, Session session)
 {
     Console.WriteLine("OnSessionEnded requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
Exemplo n.º 23
0
 public override Task <SkillResponse> OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session, Context context)
 {
     return(Task.FromResult <SkillResponse>(null));
 }
Exemplo n.º 24
0
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     return(Task.FromResult(0));
 }
 public override async Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     Log.Info("OnSessionEnded requestId={0}, sessionId={1}", sessionEndedRequest.RequestId, session.SessionId);
 }
Exemplo n.º 26
0
 public abstract void OnSessionEnded(SessionEndedRequest sessionEndedRequest, Session session);
Exemplo n.º 27
0
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     return(Task.CompletedTask);
 }
        private static SpeechletRequest RequestFromJson(JObject json)
        {
            SpeechletRequest request;
            var requestTypeParts = json?.Value <string>("type")?.Split('.');

            if (requestTypeParts == null)
            {
                throw new ArgumentException("json");
            }

            var requestType    = requestTypeParts[0];
            var requestSubType = requestTypeParts.Length > 1 ? requestTypeParts[1] : null;

            var requestId = json.Value <string>("requestId");
            var timestamp = DateTimeHelpers.FromAlexaTimestamp(json);
            var locale    = json.Value <string>("locale");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp, locale);
                break;

            case "IntentRequest":
                IntentRequest.DialogStateEnum dialogState = IntentRequest.DialogStateEnum.NONE;
                Enum.TryParse(json.Value <string>("dialogState"), out dialogState);
                var intent = Intent.FromJson(json.Value <JObject>("intent"));
                request = new IntentRequest(requestId, timestamp, locale, intent, dialogState);
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp, locale);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason = SessionEndedRequest.ReasonEnum.NONE;
                Enum.TryParse(json.Value <string>("reason"), out reason);
                var sessionError = Error.FromJson(json.Value <JObject>("error"));
                request = new SessionEndedRequest(requestId, timestamp, locale, reason, sessionError);
                break;

            case "AudioPlayer":
                var token                = json.Value <string>("token");
                var offset               = json.Value <long?>("offsetInMilliseconds");
                var playbackError        = Error.FromJson(json.Value <JObject>("error"));
                var currentPlaybackState = PlaybackState.FromJson(json.Value <JObject>("currentPlaybackState"));
                switch (requestSubType)
                {
                case "PlaybackFailed":
                    request = new AudioPlayerPlaybackFailedRequest(requestId, timestamp, locale, requestSubType, token, playbackError, currentPlaybackState);
                    break;

                default:
                    request = new AudioPlayerRequest(requestId, timestamp, locale, requestSubType, token, offset);
                    break;
                }
                break;

            case "PlaybackController":
                request = new PlaybackControllerRequest(requestId, timestamp, locale, requestSubType);
                break;

            case "Display":
                var listItemToken = json.Value <string>("token");
                request = new DisplayRequest(requestId, timestamp, locale, requestSubType, listItemToken);
                break;

            case "System":
                switch (requestSubType)
                {
                case "ExceptionEncountered":
                    var systemError = Error.FromJson(json.Value <JObject>("error"));
                    var cause       = Cause.FromJson(json.Value <JObject>("cause"));
                    request = new SystemExceptionEncounteredRequest(requestId, timestamp, locale, requestSubType, systemError, cause);
                    break;

                default:
                    throw new ArgumentException("json");
                }
                break;

            default:
                throw new ArgumentException("json");
            }

            return(request);
        }
Exemplo n.º 29
0
 private SkillResponse GetResponse(SessionEndedRequest sessionEndedRequest)
 {
     return(CreateResponse("OK. Goodbye for now"));
 }
Exemplo n.º 30
0
 public override void OnSessionEnded(SessionEndedRequest request, Session session)
 {
     //Log.Info("OnSessionEnded requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }