how to get information from user on alexa skill launch

72 Views Asked by At

I've got an Alexa app that on first launch looks for the user's id in a dynamoDB. If it isn't there I'd like it to ask the user for their ip address.

I have an intent that can collect the IP but I was wondering if I could trigger the intent from the launch request?


        private SkillResponse LaunchRequestHandler(SkillRequest input, ILambdaContext context)
        {
            // Initialise response
            var skillResponse = new SkillResponse
            {
                Version = "1.0",
                Response = new ResponseBody()
            };

            // Output speech
            SsmlOutputSpeech ssmlResponse = new SsmlOutputSpeech();

            try
            {

                try
                {
                    var strUserId = input.Session.User.UserId;

                    var request = new GetItemRequest
                    {
                        TableName = tableName,
                        Key = new Dictionary<string, AttributeValue>() { { "strUserId", new AttributeValue { S = strUserId } } },
                    };
                    var response = client.GetItemAsync(request);

                    // Check the response.
                    var result = response.Result;
                    var attributeMap = result.Item;

                    if (result.Item.Count() < 1)
                    {
                        ssmlResponse.Ssml = "<speak></speak>";

                        // Trigger intent to get IP address and port number.

                    }
                    else
                    {
                        ssmlResponse.Ssml = "<speak>Hi there. I'm not Cortana.</speak>";

                        // Give command guidance prompt.
                    }

                    
                }
                catch (AmazonDynamoDBException e) { ssmlResponse.Ssml = "<speak>" + e.InnerException.Message + "</speak>"; }
                catch (AmazonServiceException e) { ssmlResponse.Ssml = "<speak>" + e.Message + "</speak>"; }
                catch (Exception e) { ssmlResponse.Ssml = "<speak>" + e.Message + "</speak>"; }

                skillResponse.Response.OutputSpeech = ssmlResponse;
                skillResponse.Response.ShouldEndSession = true;
            }
            catch
            {
                //ssmlResponse.Ssml = "<speak><audio src='/samples/ImSorryDave'/></speak>";
                ssmlResponse.Ssml = "<speak>I'm sorry Dave. I'm afraid I can't do that.</speak>";
                skillResponse.Response.OutputSpeech = ssmlResponse;
            }

            skillResponse.Response.ShouldEndSession = true;
            return skillResponse;
        }
1

There are 1 best solutions below

0
On

Two options I can think of:

  1. Have you tried just asking for the IP address? <speak> Hi there. What is your IP address?</speak> If you make sure your IP address intent has examples of how you might expect a user to respond to that question, that intent should be the triggered and sent to your skill to process.

  2. Also look into how Alexa can handle some of the dialog management for you with intent chaining. The example there sounds very similar to your use case.