public override async Task OnSessionStartedAsync(SessionStartedRequest request, Session session)
        {
            Task t = AskTeenageQueue.AddAsync(JsonConvert.SerializeObject(request));

            Logger.Info($"OnSessionStarted requestId={request.RequestId}, sessionId={session.SessionId}");
            await t;
        }
        /// <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"))
            });
        }
        //#endif

        public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
        {
            if (AlexaUtils.IsRequestInvalid(session))
            {
                return(Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
            }
            return(Task.Delay(0));
        }
Example #4
0
        public async override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
        {
            //Ensure service and conversation are already started
            EnsureServiceCreated(session.User.Id);

            if (!_botFrameworkService.IsConversationStarted)
            {
                await _botFrameworkService.StartConversationAsync();
            }
        }
        /// <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")
            });
        }
        //#endif

        public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
        {
            // this function is invoked when a user begins a session with your skill
            // this is a chance to load user data at the start 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));
        }
Example #7
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")
            });
        }
 public override void OnSessionStarted(SessionStartedRequest request, Session session)
 {
     //_logService.LogRequest(request, session);
 }
 public void OnSessionStarted(SessionStartedRequest request, Session session, Context context)
 {
     Log.Info("OnSessionStarted requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
 public override async Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     Log.Info("OnSessionStarted requestId={0}, sessionId={1}", sessionStartedRequest.RequestId, session.SessionId);
 }
Example #11
0
 public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     return(Task.FromResult(0));
 }
 public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     return(Task.CompletedTask);
 }
 public override void OnSessionStarted(SessionStartedRequest sessionStartedRequest, Session session)
 {
     logger.Log($"OnSessionStarted called for session {session.SessionId}");
 }
 public Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session, Context context)
 {
     return(Task.Delay(0)); // nothing to do (yet)
 }
Example #15
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")
            });
        }
Example #16
0
 public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     return(Task.Run(() => { }));
 }
Example #17
0
 public void LogRequest(SessionStartedRequest request, Session session, string resultMessage)
 {
     //LogRequestToDb(AlexaRequestType.SessionStartedRequest, session.Application.Id, session.User.Id, null);
 }
 public void SessionStart(SessionStartedRequest request, Session session)
 {
     this.LogWriter.Info("Session started.");
 }
Example #19
0
 public override void OnSessionStarted(SessionStartedRequest request, Session session)
 {
     this.log.Info(String.Format("OnSessionStarted requestId={0}, sessionId={1}", request.RequestId, session.SessionId));
 }
Example #20
0
 public Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session, Context context)
 {
     return(Task.CompletedTask);
 }
Example #21
0
 public override void OnSessionStarted(SessionStartedRequest request, Session session)
 {
     //Log.Info("OnSessionStarted requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
        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);
        }
 public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     return(Task.Delay(0));
 }
Example #24
0
 public override Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session)
 {
     Log.Info(string.Format("OnSessionStartedAsync requestId={0}, sessionId={1}", sessionStartedRequest.RequestId, session.SessionId));
     return(Task.CompletedTask);
 }
 public override void OnSessionStarted(SessionStartedRequest sessionStartedRequest, Session session)
 {
 }
 public override void OnSessionStarted(SessionStartedRequest request, Session session)
 {
     Console.WriteLine("OnSessionStarted requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
Example #27
0
 public abstract void OnSessionStarted(SessionStartedRequest sessionStartedRequest, Session session);
Example #28
0
 public async Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session, Context context)
 {
     await logHelper.Log($"User {session.User.Id} started session {session.SessionId}");
 }
Example #29
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"))
            });
        }
Example #30
0
 public override async Task OnSessionStartedAsync(SessionStartedRequest request, Session session)
 {
     Logger.Info($"OnSessionStarted requestId={request.RequestId}, sessionId={session.SessionId}");
 }