/**
         * Creates a {@code SpeechletResponse} for the intent and stores the extracted name in the
         * Session.
         * 
         * @param intent
         *            intent for the request
         * @return SpeechletResponse spoken and visual response the given intent
         */
        private SpeechletResponse SetNameInSessionAndSayHello(Intent intent, Session session)
        {
            // Get the slots from the intent.
            var slots = intent.Slots;
            string speechOutput;

            if (!slots.Any())
            {
                speechOutput = "I'm sorry, I didn't hear your name. You can tell me your name by saying, my name is Sam";
                return BuildSpeechletResponse(intent.Name, speechOutput, false);
            }

            // Get the name slot from the list slots.
            var nameSlot = slots.Keys.Contains(NameSlot) ? slots[NameSlot] : null;

            // Check for name and create output to user.
            if (nameSlot != null)
            {
                // Store the user's name in the Session and create response.
                var name = nameSlot.Value;
                session.Attributes[NameKey] = name;
                speechOutput = $"Hello {name}, now I can remember your name, you can ask me your name by saying, whats my name?";
            }
            else
            {
                // Render an error since we don't know what the users name is.
                speechOutput = "I'm not sure what your name is, please try again";
            }

            // Here we are setting shouldEndSession to false to not end the session and
            // prompt the user for input
            return BuildSpeechletResponse(intent.Name, speechOutput, false);
        }
        /**
         * Creates a {@code SpeechletResponse} for the intent and stores the extracted name in the
         * Session.
         * 
         * @param intent
         *            intent for the request
         * @return SpeechletResponse spoken and visual response the given intent
         */
        private SpeechletResponse SetNameInSessionAndSayHello(Intent intent, Session session) {
            // Get the slots from the intent.
            Dictionary<string, Slot> slots = intent.Slots;

            // Get the name slot from the list slots.
            Slot nameSlot = slots[NAME_SLOT];
            string speechOutput = "";

            // Check for name and create output to user.
            if (nameSlot != null) {
                // Store the user's name in the Session and create response.
                string name = nameSlot.Value;
                session.Attributes[NAME_KEY] = name;
                speechOutput = String.Format(
                    "Hello {0}, now I can remember your name, you can ask me your name by saying, whats my name?", name);
            } 
            else {
                // Render an error since we don't know what the users name is.
                speechOutput = "I'm not sure what your name is, please try again";
            }

            // Here we are setting shouldEndSession to false to not end the session and
            // prompt the user for input
            return BuildSpeechletResponse(intent.Name, speechOutput, false);
        }
예제 #3
0
        public static async Task <SpeechletResponse> GetResults(Session session, decimal amount, string accountTo)
        {
            var api     = new ApiClient();
            var payment = new PaymentRequest
            {
                description = $"Payment of {amount.ToString(CultureInfo.InvariantCulture) + " pounds"} to {accountTo}",
                to          = new To
                {
                    account_id = "LeeCox",
                    bank_id    = "santander.01.uk.sanuk"
                },
                value = new Value
                {
                    amount   = amount.ToString(CultureInfo.InvariantCulture),
                    currency = "GBP"
                }
            };
            var result = await api.PostAsAsync <PaymentResponse>(Constants.ApiEndpoints.MakePayment, payment);

            var balance = await GetBalance.GetBalanceFromOpenBanking();

            var simpleIntentResponse = ParseResults(result, balance.balance.amount);

            await PostToQueue();

            return(AlexaUtils.BuildSpeechletResponse(simpleIntentResponse, true));
        }
예제 #4
0
        public static async Task <SpeechletResponse> GetResults(Session session)
        {
            var result = await GetSpendingInsight();

            var simpleIntentResponse = ParseResults(result);

            return(AlexaUtils.BuildSpeechletResponse(simpleIntentResponse, true));
        }
예제 #5
0
        public static async Task <SpeechletResponse> GetResults(Session session)
        {
            var result = await GetBalanceFromOpenBanking();

            var simpleIntentResponse = ParseResults(result);

            return(AlexaUtils.BuildSpeechletResponse(simpleIntentResponse, true));
        }
 private SpeechletResponse InvalidApplicationId(Session session)
 {
     return(AlexaUtils.BuildSpeechletResponse(new AlexaUtils.SimpleIntentResponse()
     {
         cardText = "An invalid Application ID was received from Alexa.  Please update your Visual Studio project " +
                    "to include the correct value and then re-deploy your Azure project."
     }, true));
 }
 private SpeechletResponse GetOnLaunchAsyncResult(Session session)
 {
     return(AlexaUtils.BuildSpeechletResponse(new AlexaUtils.SimpleIntentResponse
     {
         cardText = "",
         ssmlString = "<speak>Voice bot<break time=\"0.2s\" />obviously</speak>"
     }, true));
 }
        public static async Task <SpeechletResponse> GetResults(Session session, string date)
        {
            var api          = new ApiClient();
            var datetimeFrom = DateTime.Parse(date);
            var result       = await api.GetAsync <Transactions>(string.Format(Constants.ApiEndpoints.MyTransactions, datetimeFrom, datetimeFrom.AddDays(1)));

            var simpleIntentResponse = ParseResults(result);

            return(AlexaUtils.BuildSpeechletResponse(simpleIntentResponse, true));
        }
        public override SpeechletResponse OnIntent(IntentRequest request, Session session)
        {
            // Get intent from the request object.
            var intent = request.Intent;
            var intentName = intent?.Name;

            // Note: If the session is started with an intent, no welcome message will be rendered;
            // rather, the intent specific response will be returned.
            if ("MyNameIsIntent".Equals(intentName))
                return SetNameInSessionAndSayHello(intent, session);

            if ("WhatsMyNameIntent".Equals(intentName))
                return GetNameFromSessionAndSayHello(intent, session);
            
            throw new SpeechletException("Invalid Intent");
        }
        public override SpeechletResponse OnIntent(IntentRequest request, Session session) {
            Log.Info("OnIntent requestId={0}, sessionId={1}", request.RequestId, session.SessionId);

            // Get intent from the request object.
            Intent intent = request.Intent;
            string intentName = (intent != null) ? intent.Name : null;

            // Note: If the session is started with an intent, no welcome message will be rendered;
            // rather, the intent specific response will be returned.
            if ("MyNameIsIntent".Equals(intentName)) {
                return SetNameInSessionAndSayHello(intent, session);
            } 
            else if ("WhatsMyNameIntent".Equals(intentName)) {
                return GetNameFromSessionAndSayHello(intent, session);
            } 
            else {
                throw new SpeechletException("Invalid Intent");
            }
        }
        public override async Task <SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session)
        {
            if (AlexaUtils.IsRequestInvalid(session))
            {
                return(await Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
            }

            var intent     = intentRequest.Intent;
            var intentName = intent?.Name;

            switch (intentName.ToUpper())
            {
            case "BALANCE":
                return(await GetBalance.GetResults(session));

            case "TRANSACTIONS":
                return(await GetTransactions.GetResults(session, intentRequest.Intent.Slots["date"].Value));

            case "PAYMENT":
                return(await MakePayment.GetResults(session, decimal.Parse(intentRequest.Intent.Slots["amount"].Value), intentRequest.Intent.Slots["account"].Value));

            case "WINNERS":
                return(await Winners.GetResults());

            case "MORTGAGE":
                return(await Mortgage.GetResults(session));

            case "SAVINGS":
                return(await Insights.GetResults(session));

            default:
                return(await Task.FromResult <SpeechletResponse>(GetOnLaunchAsyncResult(session)));
            }
        }
        public override async Task <SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session)
        {
            if (AlexaUtils.IsRequestInvalid(session))
            {
                return(await Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
            }

            return(await Task.FromResult <SpeechletResponse>(GetOnLaunchAsyncResult(session)));
        }
 public override Task OnSessionEndedAsync(SessionEndedRequest sessionEndedRequest, Session session)
 {
     if (AlexaUtils.IsRequestInvalid(session))
     {
         return(Task.FromResult <SpeechletResponse>(InvalidApplicationId(session)));
     }
     return(Task.Delay(0));
 }
 public override void OnSessionEnded(SessionEndedRequest request, Session session) {
     Log.Info("OnSessionEnded requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
        /**
         * Creates a {@code SpeechletResponse} for the intent and get the user's name from the Session.
         *
         * @param intent
         *            intent for the request
         * @return SpeechletResponse spoken and visual response for the intent
         */
        private SpeechletResponse GetNameFromSessionAndSayHello(Intent intent, Session session)
        {
            string speechOutput = "";
            bool shouldEndSession = false;

            // Get the user's name from the session.
            string name = (String)session.Attributes[NAME_KEY];

            // Check to make sure user's name is set in the session.
            if (!String.IsNullOrEmpty(name))
            {
                speechOutput = String.Format("Your name is {0}, goodbye", name);
                shouldEndSession = true;
            }
            else
            {
                // Since the user's name is not set render an error message.
                speechOutput = "I'm not sure what your name is, you can say, my name is Sam";
            }

            return BuildSpeechletResponse(intent.Name, speechOutput, shouldEndSession);
        }
 public override SpeechletResponse OnLaunch(LaunchRequest request, Session session)
 {
     return GetWelcomeResponse();
 }
        /// <summary>
        /// 
        /// </summary>
        private void DoSessionManagement(IntentRequest request, Session session) {
            if (session.IsNew) {
                session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
            }
            else {
                // if the session was started as a result of a launch request 
                // a first intent isn't yet set, so set it to the current intent
                if (!session.Attributes.ContainsKey(Session.INTENT_SEQUENCE)) {
                    session.Attributes[Session.INTENT_SEQUENCE] = request.Intent.Name;
                }
                else {
                    session.Attributes[Session.INTENT_SEQUENCE] += Session.SEPARATOR + request.Intent.Name;
                }
            }

            // Auto-session management: copy all slot values from current intent into session
            foreach (var slot in request.Intent.Slots.Values) {
                if (!String.IsNullOrEmpty(slot.Value)) session.Attributes[slot.Name] = slot.Value;
            }
        }
예제 #18
0
 public abstract void OnSessionStarted(SessionStartedRequest sessionStartedRequest, Session session);
예제 #19
0
 public abstract SpeechletResponse OnIntent(IntentRequest intentRequest, Session session);
        public override SpeechletResponse OnLaunch(LaunchRequest request, Session session)
        {
            var response = new SpeechletResponse();

            return response;
        }
 public override void OnSessionStarted(SessionStartedRequest request, Session session)
 {
     Console.WriteLine("OnSessionStarted requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
 }
 public override void OnSessionStarted(SessionStartedRequest request, Session session) { }
 public abstract Task<SpeechletResponse> OnLaunchAsync(LaunchRequest launchRequest, Session session);
예제 #24
0
 public abstract SpeechletResponse OnLaunch(LaunchRequest launchRequest, Session session);
 public override void OnSessionEnded(SessionEndedRequest request, Session session) {  }
예제 #26
0
 public abstract void OnSessionEnded(SessionEndedRequest sessionEndedRequest, Session session);
        public override SpeechletResponse OnIntent(IntentRequest request, Session session)
        {
            var response = new SpeechletResponse();

            return response;
        }
 public abstract Task<SpeechletResponse> OnIntentAsync(IntentRequest intentRequest, Session session);
        /**
         * Creates a {@code SpeechletResponse} for the intent and get the user's name from the Session.
         * 
         * @param intent
         *            intent for the request
         * @return SpeechletResponse spoken and visual response for the intent
         */
        private SpeechletResponse GetNameFromSessionAndSayHello(Intent intent, Session session) {
            string speechOutput = "";
            bool shouldEndSession = false;

            if (!session.Attributes[Session.INTENT_SEQUENCE].Contains("MyNameIsIntent"))
            {
                speechOutput = "I'm sorry, you seem to be new here. You can tell me your name by saying, my name is Sam";
                return BuildSpeechletResponse(intent.Name, speechOutput, false);
            }

            // Get the user's name from the session.
            var name = session.Attributes.ContainsKey(NAME_KEY) ? session.Attributes[NAME_KEY] : null;

            // Check to make sure user's name is set in the session.
            if (!String.IsNullOrEmpty(name)) {
                speechOutput = String.Format("Your name is {0}, goodbye", name);
                shouldEndSession = true;
            } 
            else {
                // Since the user's name is not set render an error message.
                speechOutput = "I'm not sure what your name is, you can say, my name is Sam";
            }

            return BuildSpeechletResponse(intent.Name, speechOutput, shouldEndSession);
        }
 public abstract Task OnSessionStartedAsync(SessionStartedRequest sessionStartedRequest, Session session);
 public override SpeechletResponse OnLaunch(LaunchRequest request, Session session) {
     Log.Info("OnLaunch requestId={0}, sessionId={1}", request.RequestId, session.SessionId);
     return GetWelcomeResponse();
 }