private SkillResponse ErrorResponse(Exception exc = null)
        {
            if (exc != null)
            {
                LogMessage(exc.Message, SeverityLevel.Error, new Dictionary <string, string>()
                {
                    { "Stack Trace", exc.StackTrace }
                });
            }

            var util = new Utils();
            // build the speech response
            var speech = new Alexa.NET.Response.SsmlOutputSpeech();

            speech.Ssml = $"<speak>{util.GetRandomMessage(Globals.IDidntUnderstand, false)}. Try saying 'What are today's threats' to list today's threats.</speak>";

            // create the speech reprompt
            var repromptMessage = new Alexa.NET.Response.PlainTextOutputSpeech();

            repromptMessage.Text = "Try saying 'What are today's threats' to list today's threats.";

            // create the reprompt
            var reprompt = new Alexa.NET.Response.Reprompt();

            reprompt.OutputSpeech = repromptMessage;

            // create the response using the ResponseBuilder
            var finalResponse = ResponseBuilder.Ask(speech, reprompt);

            return(finalResponse);
        }
예제 #2
0
        private SkillResponse ResponseReprompt(string text, string reprompt)
        {
            var speech = new Alexa.NET.Response.SsmlOutputSpeech();

            speech.Ssml = "<speak> " + text + " </speak>";

            var repromptMessage = new Alexa.NET.Response.PlainTextOutputSpeech();

            repromptMessage.Text = "<speak> " + reprompt + " </speak>";

            // create the reprompt
            var repromptBody = new Alexa.NET.Response.Reprompt();

            repromptBody.OutputSpeech = repromptMessage;
            var finalResponse = ResponseBuilder.Ask(speech, repromptBody);

            return(finalResponse);
        }
        private SkillResponse FallbackHelp()
        {
            // create the speech response - cards still need a voice response
            var speech = new Alexa.NET.Response.SsmlOutputSpeech();

            speech.Ssml = $"<speak>{_util.GetRandomMessage(Globals.IDidntUnderstand)}. You might try 'What are today's threats?'</speak>";

            // create the speech reprompt
            var repromptMessage = new Alexa.NET.Response.PlainTextOutputSpeech();

            repromptMessage.Text = "Try saying 'What are today's threats?'";

            // create the reprompt
            var repromptBody = new Alexa.NET.Response.Reprompt();

            repromptBody.OutputSpeech = repromptMessage;

            var finalResponse = ResponseBuilder.Ask(speech, repromptBody);

            return(finalResponse);
        }
        private SkillResponse Help()
        {
            // create the speech response - cards still need a voice response
            var speech = new Alexa.NET.Response.SsmlOutputSpeech();

            speech.Ssml = $"<speak>Do you worry about space-based threats to earth such as asteroids and other near earth objects? {Globals.FriendlyAppTitle} will let you know what's out there zooming towards us.</speak>";

            // create the speech reprompt
            var repromptMessage = new Alexa.NET.Response.PlainTextOutputSpeech();

            repromptMessage.Text = "Try saying 'What are today's threats?'";

            // create the reprompt
            var repromptBody = new Alexa.NET.Response.Reprompt();

            repromptBody.OutputSpeech = repromptMessage;

            var finalResponse = ResponseBuilder.Ask(speech, repromptBody);

            return(finalResponse);
        }
        private SkillResponse Usage()
        {
            var commonUsage = "You can say 'What are today's threats?' to list today's space-based threats to earth, or say Help to get more information.";

            // create the speech response - cards still need a voice response
            var speech = new Alexa.NET.Response.SsmlOutputSpeech();

            speech.Ssml = $"<speak>Welcome to {Globals.FriendlyAppTitle}. {commonUsage}</speak>";

            // create the speech reprompt
            var repromptMessage = new Alexa.NET.Response.PlainTextOutputSpeech();

            repromptMessage.Text = commonUsage;

            // create the reprompt
            var repromptBody = new Alexa.NET.Response.Reprompt();

            repromptBody.OutputSpeech = repromptMessage;

            var finalResponse = ResponseBuilder.Ask(speech, repromptBody);

            return(finalResponse);
        }
예제 #6
0
        public async Task <dynamic> Post([FromBody] SkillRequest input)
        {
            var speech        = new Alexa.NET.Response.SsmlOutputSpeech();
            var finalResponse = new SkillResponse();
            // check what type of a request it is like an IntentRequest or a LaunchRequest
            var requestType = input.GetRequestType();

            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("GetPoints"))
                {
                    long?points = 0;
                    var  client = new CustomApiClient();
                    var  result = await client.QueryPointsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, null, null, null, false, null, null, null);

                    if (result != null)
                    {
                        foreach (var wallet in result.Wallets)
                        {
                            points = points + wallet.Points;
                        }
                    }
                    // create the speech response - cards still need a voice response
                    speech.Ssml = $"<speak>You currently have {points} loyalty points available in your account.</speak>";
                    // create the card response
                    finalResponse = ResponseBuilder.TellWithCard(speech, "GetPoints", $"You currently have {points} loyalty points available in your account.");
                }
                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("GetItems"))
                {
                    string items  = string.Empty;
                    var    client = new CustomApiClient();
                    var    result = await client.QueryAvailableItemsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, null, null, null, null);

                    if (result != null)
                    {
                        items = string.Join(", ", result.Items.Select(z => z.Name));
                    }
                    // create the speech response - cards still need a voice response
                    speech.Ssml = $"<speak>Here is the list of items available for you: {items}.</speak>";
                    // create the card response
                    //finalResponse = ResponseBuilder.TellWithCard(speech, "GetItems", $"Here is the list of items available for you: {items}.");

                    // create the speech reprompt
                    var repromptMessage = new PlainTextOutputSpeech();
                    repromptMessage.Text = "Would you like to add any of these to your shoping cart?";

                    // create the reprompt
                    var repromptBody = new Alexa.NET.Response.Reprompt();
                    repromptBody.OutputSpeech = repromptMessage;

                    // create the response
                    finalResponse = ResponseBuilder.AskWithCard(speech, "GetItems", $"Here is the list of items available for you: {items}.", repromptBody);
                }
                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("AddToBasket"))
                {
                    // create the speech response - cards still need a voice response
                    speech.Ssml = "<speak>Your item was successfully added to shopping cart.</speak>";
                    // create the card response
                    finalResponse = ResponseBuilder.TellWithCard(speech, "AddToBasket", "Your item was successfully added to shopping cart.");
                }
            }
            else if (requestType == typeof(Alexa.NET.Request.Type.LaunchRequest))
            {
                // default launch path executed
            }
            else if (requestType == typeof(AudioPlayerRequest))
            {
                // do some audio response stuff
            }

            return(finalResponse);
        }
예제 #7
0
        /// <summary>
        /// A simple Amazon Skill Example which uses the Epicor REST API
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            //Get Access to the AWS Lambda Logger to see the status of our request
            var log = context.Logger;

            //Get the Request Type
            var requestType = input.GetRequestType();

            SkillResponse resp = null;

            //This will be said to the user after every response as a way to "reprompt" (continue)
            var reprompt = new Alexa.NET.Response.Reprompt
            {
                OutputSpeech = new PlainTextOutputSpeech()
                {
                    Text = "For a list of available commands say, Help!. What woudl you like to do?"
                }
            };

            //When the skill initially launches, give them some helpful info
            if (requestType == typeof(LaunchRequest))
            {
                log.LogLine("INFO: Initial Launch Request");

                var speech = new Alexa.NET.Response.SsmlOutputSpeech()
                {
                    Ssml = string.Format(@"<speak>Welcome to this sample Alexa Skill using the Epicor REST API. For a list of available commands say help. What would you like to do? </speak>")
                };

                resp = ResponseBuilder.Ask(speech, reprompt);
            }
            //If they askef for something specific, figure out what and respond accordingly.
            else if (requestType == typeof(IntentRequest))
            {
                var intent = input.Request as IntentRequest;
                log.LogLine($"INFO: Launched Intent:{intent.Intent.Name}");

                switch (intent.Intent.Name)
                {
                //If they involved the RunSampleBAQ Intent
                case "RunSampleBAQ":
                {
                    var speech = new Alexa.NET.Response.SsmlOutputSpeech();
                    log.LogLine($"INFO: Running BAQ");
                    speech.Ssml = RunSampleBAQ();
                    resp        = ResponseBuilder.Ask(speech, reprompt);
                }
                break;

                //If they involved the GetCompanyInfo intent
                case "GetCompanyInfo":
                {
                    var speech = new Alexa.NET.Response.SsmlOutputSpeech();
                    log.LogLine($"INFO: Getting Company Info");
                    speech.Ssml = GetCompanyInfo();
                    resp        = ResponseBuilder.Ask(speech, reprompt);
                }
                break;

                case "AMAZON.HelpIntent":
                {
                    try
                    {
                        log.LogLine("Launched Help intent");
                        StringBuilder sbCommandList = new StringBuilder();
                        sbCommandList.AppendLine($"<speak>Available commands are: <break strength='medium' />");
                        sbCommandList.AppendLine($"Run Sample BAQ <break strength='medium' />");
                        sbCommandList.AppendLine($"Get Company Info,<break strength='medium' />");
                        sbCommandList.AppendLine($"What would you like to do?</speak>");
                        log.LogLine("Finished building command List");
                        var speech = new SsmlOutputSpeech()
                        {
                            Ssml = sbCommandList.ToString()
                        };
                        log.LogLine("Assigned Response");
                        resp = ResponseBuilder.Ask(speech, reprompt);
                    }
                    catch (Exception e)
                    {
                        log.LogLine(e.ToString());
                    }
                }
                break;

                case "AMAZON.StopIntent":
                {
                    var speech = new SsmlOutputSpeech()
                    {
                        Ssml = "<speak>Thank you for Trying out this Sample Skill<break strength='medium' />. Good bye.</speak>"
                    };
                    resp = ResponseBuilder.Tell(speech);
                }
                break;

                case "AMAZON.CancelIntent":
                {
                    var speech = new SsmlOutputSpeech()
                    {
                        Ssml = "<speak>Good bye.</speak>"
                    };
                    resp = ResponseBuilder.Tell(speech);
                }
                break;

                case "Unhandled":
                default:
                {
                    var speech = new PlainTextOutputSpeech()
                    {
                        Text = "Ut oh, you've somehow ended in an unhandled intent... You shouldn't be here, GET OUT!"
                    };
                    resp = ResponseBuilder.Ask(speech, reprompt);
                }
                break;
                }
            }

            return(resp);
        }
        public async Task <dynamic> Post([FromBody] SkillRequest input)
        {
            var speech        = new Alexa.NET.Response.SsmlOutputSpeech();
            var finalResponse = new SkillResponse();

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

            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("GetPoints"))
                {
                    try
                    {
                        long?points = 0;
                        var  client = new CustomApiClient();
                        var  result = await client.QueryPointsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, "WALLET_DEFAULT", null, null, false, null, null, null);

                        if (result != null)
                        {
                            foreach (var wallet in result.Wallets)
                            {
                                points = points + wallet.Points;
                            }
                        }
                        //// create the speech response - cards still need a voice response
                        //speech.Ssml = $"<speak>You currently have {points} loyalty points available in your account.</speak>";
                        //// create the card response
                        //finalResponse = ResponseBuilder.TellWithCard(speech, "GetPoints", $"You currently have {points} loyalty points available in your account.");

                        //_cache.sa
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>You currently have {points} loyalty points available in your account.</speak>";

                        // create the speech reprompt
                        var repromptMessage = new PlainTextOutputSpeech();
                        repromptMessage.Text = "Anything else you might want to do?";

                        // create the reprompt
                        var repromptBody = new Alexa.NET.Response.Reprompt();
                        repromptBody.OutputSpeech = repromptMessage;

                        // create the response
                        finalResponse = ResponseBuilder.AskWithCard(speech, "GetPoints", $"You currently have {points} loyalty points available in your account.", repromptBody);
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "GetPoints Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }
                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("GetItems"))
                {
                    try
                    {
                        string      items       = string.Empty;
                        SessionData sessionData = null;
                        var         client      = new CustomApiClient();
                        var         result      = await client.QueryAvailableItemsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, null, null, null, null);

                        if (result != null)
                        {
                            //items = string.Join(", ", result.Items.Select(z => z.Name));
                            redeemableItems.AddRange(result.Items);
                            items = string.Join(", ", redeemableItems.Select(z => z.Name));
                            var value = await _cache.GetStringAsync(input.Session.SessionId);

                            if (value != null)
                            {
                                sessionData = JsonConvert.DeserializeObject <SessionData>(value);
                            }
                            if (sessionData != null)
                            {
                                sessionData.RedeemableItems = redeemableItems;
                            }
                            else
                            {
                                sessionData = new SessionData {
                                    SessionId = input.Session.SessionId, PurchaseItems = purchaseItems, RedeemableItems = redeemableItems
                                };
                            }
                            await _cache.SetStringAsync(input.Session.SessionId, JsonConvert.SerializeObject(sessionData));
                        }
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Here is the list of items available for you: {items}.</speak>";
                        // create the card response
                        //finalResponse = ResponseBuilder.TellWithCard(speech, "GetItems", $"Here is the list of items available for you: {items}.");

                        // create the speech reprompt
                        var repromptMessage = new PlainTextOutputSpeech();
                        repromptMessage.Text = "Would you like to add any of these to your shoping cart?";

                        // create the reprompt
                        var repromptBody = new Alexa.NET.Response.Reprompt();
                        repromptBody.OutputSpeech = repromptMessage;

                        // create the response
                        finalResponse = ResponseBuilder.AskWithCard(speech, "GetItems", $"Here is the list of items available for you: {items}.", repromptBody);
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "GetItems Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }
                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("AddToBasket"))
                {
                    try
                    {
                        SessionData       sessionData = null;
                        RedeemableItem    itemR       = null;
                        PurchaseOrderItem itemP       = null;
                        string            itemName    = string.Empty;
                        int itemNo = int.Parse(intentRequest.Intent.Slots["Item"].Value);


                        var value = await _cache.GetStringAsync(input.Session.SessionId);

                        if (value != null)
                        {
                            sessionData = JsonConvert.DeserializeObject <SessionData>(value);
                        }

                        if (sessionData != null)
                        {
                            if (sessionData.RedeemableItems != null && sessionData.RedeemableItems.Count > 0)
                            {
                                redeemableItems = sessionData.RedeemableItems;
                                if ((itemNo - 1) > sessionData.RedeemableItems.Count || (itemNo - 1) < 0)
                                {
                                    throw new Exception("Sorry, you don't have that item.");
                                }
                                itemR = redeemableItems[itemNo - 1];
                                if (sessionData.PurchaseItems != null)
                                {
                                    purchaseItems = sessionData.PurchaseItems;
                                    purchaseItems.Add(new PurchaseOrderItem {
                                        DeliveryChannel = null, Quantity = 1, RedeemableItemId = itemR.Id, WalletType = new WalletType {
                                            ExternalCode = "WALLET_DEFAULT"
                                        }
                                    });
                                }
                                //else
                                //{
                                //    purchaseItems.Add(new PurchaseOrderItem { DeliveryChannel = null, Quantity = 1, RedeemableItemId = itemR.Id, WalletType = null });
                                //}
                            }
                            else
                            {
                                throw new Exception("Please query for your ityems first.");
                            }
                        }
                        else
                        {
                            sessionData = new SessionData {
                                SessionId = input.Session.SessionId, PurchaseItems = purchaseItems, RedeemableItems = redeemableItems
                            };
                        }
                        await _cache.SetStringAsync(input.Session.SessionId, JsonConvert.SerializeObject(sessionData));


                        purchaseItems.Add(new PurchaseOrderItem {
                            DeliveryChannel = null, Quantity = 1, RedeemableItemId = itemR.Id, WalletType = null
                        });

                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Your item, {itemR.Name}, was successfully added to shopping cart.</speak>";

                        // create the speech reprompt
                        var repromptMessage = new PlainTextOutputSpeech();
                        repromptMessage.Text = "Shall I proceed and buy the items in the shoping cart? You can add more items as well.";

                        // create the reprompt
                        var repromptBody = new Alexa.NET.Response.Reprompt();
                        repromptBody.OutputSpeech = repromptMessage;

                        // create the response
                        finalResponse = ResponseBuilder.AskWithCard(speech, "AddToBasket", $"Your item, {itemR.Name}, was successfully added to shopping cart.", repromptBody);
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "AddToBasket Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }
                // check the name to determine what you should do
                if (intentRequest.Intent.Name.Equals("PurchaseBasket"))
                {
                    try
                    {
                        SessionData sessionData = null;
                        string      status      = string.Empty;

                        var value = await _cache.GetStringAsync(input.Session.SessionId);

                        if (value != null)
                        {
                            sessionData = JsonConvert.DeserializeObject <SessionData>(value);
                        }
                        if (sessionData != null && sessionData.PurchaseItems != null && sessionData.PurchaseItems.Count > 0)
                        {
                            purchaseItems = sessionData.PurchaseItems;
                        }
                        else
                        {
                            throw new Exception("Your shoping cart is empty. Add some items first.");
                        }

                        await _cache.RemoveAsync(input.Session.SessionId);

                        var client = new CustomApiClient();
                        // var result = await client.RedeemItemsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, purchaseItems.ToArray(), null, null, null);
                        var result = await client.RedeemItemsAsync("API", "EXTERNAL", 1, "921722255", ParamType.Msisdn, 1, null, purchaseItems.ToArray(), null, null, null);

                        if (result != null)
                        {
                            status = result.Status.ToString();
                        }

                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Your order completed with {status}. Thank you for using our services.</speak>";

                        // create the response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "PurchaseBasket", $"Your order completed with {status}. Thank you for using our services.");
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "PurchaseBasket Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }
                if (intentRequest.Intent.Name.Equals("AMAZON.CancelIntent"))
                {
                    try
                    {
                        await _cache.RemoveAsync(input.Session.SessionId);

                        List <string> myList = new List <string> {
                            "OK,I'll shut up.", "Sure, I'll cleanup everything.", "Oh boy, that escalated quickly! I'm outa here!"
                        };
                        // add items to the list
                        Random r     = new Random();
                        int    index = r.Next(myList.Count);

                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>{myList[index]}</speak>";

                        // create the response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "Cancel Exception", $"{myList[index]}");
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "Cancel Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }

                if (intentRequest.Intent.Name.Equals("Hello"))
                {
                    try
                    {
                        await _cache.RemoveAsync(input.Session.SessionId);

                        List <string> myList = new List <string> {
                            "Hi there!", "Hi, how are you.", "Hi and goodby. get back to work"
                        };
                        // add items to the list
                        Random r     = new Random();
                        int    index = r.Next(myList.Count);

                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>{myList[index]}</speak>";

                        // create the response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "Hello", $"{myList[index]}");
                    }
                    catch (Exception e)
                    {
                        // create the speech response - cards still need a voice response
                        speech.Ssml = $"<speak>Oh boy, something went very wrong. {e.Message}</speak>";
                        // create the card response
                        finalResponse = ResponseBuilder.TellWithCard(speech, "Cancel Exception", $"Oh boy, something went very wrong. {e.Message}.");
                    }
                }
            }
            else if (requestType == typeof(Alexa.NET.Request.Type.LaunchRequest))
            {
                // default launch path executed
            }
            else if (requestType == typeof(AudioPlayerRequest))
            {
                // do some audio response stuff
            }

            return(finalResponse);
        }