question

Kalakonda avatar image
Kalakonda asked ·

alexa Intent not working

Hello I used azure Function as endpoint for Alexa skill. But the intents are not returning any value. If I use invocation name it works, but then the intent doesnt work. Im trying to get contacts from dynamics Nav through Azure function

Following is my azure function:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "get me dynamics contacts",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": [
                        "can you stop"
                    ]
                },
                {
                    "name": "HelloByName",
                    "slots": [
                        {
                            "name": "contactname",
                            "type": "AMAZON.DE_FIRST_NAME"
                        }
                    ],
                    "samples": [
                        "who is {contactname}"
                    ]
                }
            ],
            "types": []
        },
        "dialog": {
            "intents": [
                {
                    "name": "HelloByName",
                    "confirmationRequired": false,
                    "prompts": {},
                    "slots": [
                        {
                            "name": "contactname",
                            "type": "AMAZON.DE_FIRST_NAME",
                            "confirmationRequired": false,
                            "elicitationRequired": true,
                            "prompts": {
                                "elicitation": "Elicit.Slot.371356169264.1174616877629"
                            }
                        }
                    ]
                }
            ]
        },
        "prompts": [
            {
                "id": "Elicit.Slot.371356169264.1174616877629",
                "variations": [
                    {
                        "type": "PlainText",
                        "value": "what is your contactname ?"
                    }
                ]
            }
        ]
    }
}
namespace AlexaNAVSkills
{
    public static class AskNAV
    {
        [FunctionName("AskNAV")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {


            dynamic data = await req.Content?.ReadAsAsync<object>();


            log.Info($"Content = {data}");
            log.Info("C# HTTP trigger function processed a request.");


            string contactName = req.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "contactName", true) == 0)
                .Value;
            
            string contactNo = req.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "contactNo", true) == 0)
             .Value;



                
            if (data?.request.type == "LaunchRequest")
            {
                // default launch request, let's just let them know what you can do
                log.Info($"Default LaunchRequest made");
                return DefaultRequest(req);


            }

            else if (data?.request.type == "IntentRequest")
            {
                string intentName = data.request.intent.name;
                log.Info($"intentName = {intentName}");


                switch (intentName)
                {
                    case "AddIntent":


                        var name =
                        Convert.ToString(data.request.slots["contactname"].value);




                        return req.CreateResponse(HttpStatusCode.OK, new
                        {
                            version = "1.0",
                            sessionAttributes = new { },
                            response = new
                            {
                                outputSpeech = new
                                {
                                    type = "PlainText",
                                    text = $"The result is {name.ToString()}."
                                },


                                card = new
                                {
                                    type = "Simple",
                                    title = "Alexa Azure function",
                                    content = $" the result is {contactName.ToString()}."
                                },


                                shouldEndSession = true




                            }
                        });




                    default:
                        Console.WriteLine("Test");
                        break;






                }
            


            }
                string company = "'GOB'";
                string entity = "Contact";
                string selectedFields = "No,Name";
                string filterName = string.Empty;


                IEnumerable<dynamic> contacts = new Array[] { };
                if (!string.IsNullOrEmpty(contactName))
                {
                    filterName = $"substringof('{contactName}',Name) eq true";
                    contacts = await FetchNAVEntities(company, entity, selectedFields, filterName, null);
                }


                /*
                string filterNo = string.Empty;
                IEnumerable<dynamic> contactsNo = new Array[] { };
                if (!string.IsNullOrEmpty(contactNo))
                {
                    filterNo += $"No eq '{contactNo}'";
                    contactsNo = await FetchNAVEntities(company, entity, selectedFields, filterNo, null);
                }
                */


            // IEnumerable<dynamic> allContacts = contacts.Concat(contactsNo).Distinct();


             IEnumerable<dynamic> allContacts = contacts.Distinct();


            return req.CreateResponse(HttpStatusCode.OK, allContacts);




            
        }


        
        public static HttpResponseMessage DefaultRequest(HttpRequestMessage req)
        {
            return req.CreateResponse(HttpStatusCode.OK, new
            {
                version = "1.0",
                sessionAttributes = new { },
                response = new
                {
                    outputSpeech = new
                    {
                        type = "PlainText",
                        text = "Welcome to the azure skills portal that only knows how to say your name"
                    },


                    card = new
                    {
                        type = "Simple",
                        title = "Alexa Azure Nav",
                        content = "Welcome to Azure voice service"
                    },


                    shouldEndsession = true
                }
            });
        }




        internal static async Task<IEnumerable<dynamic>> FetchNAVEntities(string company, string entity, string selectedFields, string filter, string orderBy) {
            string request = $"/Company({company})/{entity}?";


            if (!string.IsNullOrEmpty(filter))
            {
                request += $"$filter={filter}";
            }
            if (!string.IsNullOrEmpty(selectedFields))
            {
                request += $"&$select={selectedFields}";
            }
            if (!string.IsNullOrEmpty(orderBy))
            {
                request += $"&$orderby={orderBy}";
            }


            ODataClientSettings osettings = new ODataClientSettings("######################################") {
                Credentials = new NetworkCredential("###################################")
            };


            ODataClient naviGOBClient = new ODataClient(osettings);


            var annotations = new ODataFeedAnnotations();
            IEnumerable<dynamic> results = await naviGOBClient.FindEntriesAsync(request, annotations);


            while (annotations.NextPageLink != null)
            {
                IEnumerable<dynamic> nextResults = await naviGOBClient.FindEntriesAsync(annotations.NextPageLink.AbsoluteUri, annotations);
                results = results.Concat(nextResults);
            }


            return results;
        }


    }
}

alexa skills kitapijavainteraction modelazure
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nikko avatar image
Nikko answered ·

Hi! I'm with the same problem but using Python on Lambda. Although I think the JSON format has changed, and the examples used before using the old UI is old.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KAIYIN@AMAZON.COM avatar image
KAIYIN@AMAZON.COM answered ·

Are you able to see the information showing in the logs?

1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

any information on it ?

0 Likes 0 ·
Kalakonda avatar image
Kalakonda answered ·
log Information
2018-06-28T06:55:54  Welcome, you are now connected to log-streaming service.
2018-06-28T06:55:58.157 [Info] Function started (Id=df814a71-bb66-41bf-8c92-315ea57091ce)
2018-06-28T06:55:58.157 [Info] Content =
2018-06-28T06:55:58.157 [Info] C# HTTP trigger function processed a request.
2018-06-28T06:55:58.172 [Info] Function completed (Success, Id=df814a71-bb66-41bf-8c92-315ea57091ce, Duration=14ms)
2018-06-28T06:57:06.994 [Info] Function started (Id=976049ed-9408-4e74-be74-b7b8391f1eb1)
2018-06-28T06:57:06.994 [Info] Content = {
  "version": "1.0",
  "session": {
    "new": true,
    "sessionId": "amzn1.echo-api.session.199bdb7c-ca6e-4ca3-b865-72f9af3ca814",
    "application": {
      "applicationId": "amzn1.ask.skill.adde8ce4-9f44-4984-a678-50e8cde9ab4e"
    },
    "user": {
      "userId": "amzn1.ask.account.AGAALA5FALAYQDZCVS3G6QWGBXKYYKZUHAXGT3BS6WUDFYZFSTXWWQLJS5XTL2PAR476QV3HQNR4CC6NGHXDP7SFSDRP4XO55L7IAJTCL25VYPS35G7PNR53EO444CI2BGAXAB3JBFZRDBI56OXMMYGX2T6MQVFILWDJNIBC5CIVT2R756HSFD4HHYRLPYVQ55Q4SJ4VYSR5P4I"
    }
  },
  "context": {
    "System": {
      "application": {
        "applicationId": "amzn1.ask.skill.adde8ce4-9f44-4984-a678-50e8cde9ab4e"
      },
      "user": {
        "userId": "amzn1.ask.account.AGAALA5FALAYQDZCVS3G6QWGBXKYYKZUHAXGT3BS6WUDFYZFSTXWWQLJS5XTL2PAR476QV3HQNR4CC6NGHXDP7SFSDRP4XO55L7IAJTCL25VYPS35G7PNR53EO444CI2BGAXAB3JBFZRDBI56OXMMYGX2T6MQVFILWDJNIBC5CIVT2R756HSFD4HHYRLPYVQ55Q4SJ4VYSR5P4I"
      },
      "device": {
        "deviceId": "amzn1.ask.device.AHDKQNQEVQVXKNNTEL5WHP2TC6D65U4WRDPEFWRPEFX3OACSXXWUNHT46BK5QSP4GYWBOJ63VZDWBR3MTXIT4BGOB7X55O653FDAPM6WC5VOB2T3LXUKQVVAISHREFBYCR6UKLGMUIU33GHKB2JGQAWRVCXQ",
        "supportedInterfaces": {}
      },
      "apiEndpoint": "https://api.eu.amazonalexa.com",
      "apiAccessToken":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ktZd_9-H-Bwc1vk51TyptWvgh8RG5hXmZ_uqSQJ3aUS8BmZffWDUoL9eG_D9BjCZe-Ry1cy61pCHPvbo4VnWkJD9yaw2A_5KEU4N9AL9xh_nZ1XK4aVNWbucUSsCVutMk79zttGzH7NJi17sEz5WB_iM3n0iPfNwS2Kbq_UsKo3cA"
    }
  },
  "request": {
    "type": "LaunchRequest",
    "requestId": "amzn1.echo-api.request.96a2d7f8-2983-4a70-86c4-3c66acec8365",
    "timestamp": "2018-06-28T06:57:06Z",
    "locale": "en-US",
    "shouldLinkResultBeReturned": false
  }
}
2018-06-28T06:57:06.994 [Info] C# HTTP trigger function processed a request.
2018-06-28T06:57:06.994 [Info] Default LaunchRequest made
2018-06-28T06:57:06.994 [Info] Function completed (Success, Id=976049ed-9408-4e74-be74-b7b8391f1eb1, Duration=1ms)
2018-06-28T06:58:54  No new trace in the past 1 min(s).
2018-06-28T06:59:54  No new trace in the past 2 min(s).
2018-06-28T07:00:54  No new trace in the past 3 min(s).
2018-06-28T07:01:54  No new trace in the past 4 min(s).
2018-06-28T07:02:54  No new trace in the past 5 min(s).
2018-06-28T07:03:54  No new trace in the past 6 min(s).
2018-06-28T07:04:18.247 [Info] Function started (Id=adc4575d-5a63-4145-8c9c-5e713acbaaf0)
2018-06-28T07:04:18.263 [Info] Content = {
  "version": "1.0",
  "session": {
    "new": true,
    "sessionId": "amzn1.echo-api.session.07d56ac8-38cd-4fdb-b5fb-273bea785559",
    "application": {
      "applicationId": "amzn1.ask.skill.adde8ce4-9f44-4984-a678-50e8cde9ab4e"
    },
    "user": {
      "userId": "amzn1.ask.account.AGAALA5FALAYQDZCVS3G6QWGBXKYYKZUHAXGT3BS6WUDFYZFSTXWWQLJS5XTL2PAR476QV3HQNR4CC6NGHXDP7SFSDRP4XO55L7IAJTCL25VYPS35G7PNR53EO444CI2BGAXAB3JBFZRDBI56OXMMYGX2T6MQVFILWDJNIBC5CIVT2R756HSFD4HHYRLPYVQ55Q4SJ4VYSR5P4I"
    }
  },
  "context": {
    "System": {
      "application": {
        "applicationId": "amzn1.ask.skill.adde8ce4-9f44-4984-a678-50e8cde9ab4e"
      },
      "user": {
        "userId": "amzn1.ask.account.AGAALA5FALAYQDZCVS3G6QWGBXKYYKZUHAXGT3BS6WUDFYZFSTXWWQLJS5XTL2PAR476QV3HQNR4CC6NGHXDP7SFSDRP4XO55L7IAJTCL25VYPS35G7PNR53EO444CI2BGAXAB3JBFZRDBI56OXMMYGX2T6MQVFILWDJNIBC5CIVT2R756HSFD4HHYRLPYVQ55Q4SJ4VYSR5P4I"
      },
      "device": {
        "deviceId": "amzn1.ask.device.AHDKQNQEVQVXKNNTEL5WHP2TC6D65U4WRDPEFWRPEFX3OACSXXWUNHT46BK5QSP4GYWBOJ63VZDWBR3MTXIT4BGOB7X55O653FDAPM6WC5VOB2T3LXUKQVVAISHREFBYCR6UKLGMUIU33GHKB2JGQAWRVCXQ",
        "supportedInterfaces": {}
      },
      "apiEndpoint": "https://api.eu.amazonalexa.com",
      "apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2l0Iiwic3ViIjoiYW16bjEuYXNrLnNraWxsLmFkZGU4Y2U0LTlmNDQtNDk4NC1hNjc4LTUwZThjZGU5YWI0ZSIsImV4cCI6MTUzMDE3MzA1NywiaWF0IjoxNTMwMTY5NDU3LCJuYmYiOjE1MzAxNjk0NTcsInByaXZhdGVDbGFpbXMiOnsiY29uc2VudFRva2VuIjpudWxsLCJkZXZpY2VJZCI6ImFtem4xLmFzay5kZXZpY2UuQUhES1FOUUVWUVZYS05OVEVMNVdIUDJUQzZENjVVNFdSRFBFRldSUEVGWDNPQUNTWFhXVU5IVDQ2Qks1UVNQNEdZV0JPSjYzVlpEV0JSM01UWElUNEJHT0I3WDU1TzY1M0ZEQVBNNldDNVZPQjJUM0xYVUtRVlZBSVNIUkVGQllDUjZVS0xHTVVJVTMzR0hLQjJKR1FBV1JWQ1hRIiwidXNlcklkIjoiYW16bjEuYXNrLmFjY291bnQuQUdBQUxBNUZBTEFZUURaQ1ZTM0c2UVdHQlhLWVlLWlVIQVhHVDNCUzZXVURGWVpGU1RYV1dRTEpTNVhUTDJQQVI0NzZRVjNIUU5SNENDNk5HSFhEUDdTRlNEUlA0WE81NUw3SUFKVENMMjVWWVBTMzVHN1BOUjUzRU80NDRDSTJCR0FYQUIzSkJGWlJEQkk1Nk9YTU1ZR1gyVDZNUVZGSUxXREpOSUJDNUNJVlQyUjc1NkhTRkQ0SEhZUkxQWVZRNTVRNFNKNFZZU1I1UDRJIn19.V_1KkISZFcnv0r3kAd29BVZpj64Fg-b_Du3pcaPEfwJHa-2PquHnqBndg6lzaEc3hrem3TV0ucWXgp70sDBRnYcMtSknAQmjuvYJCNAaUhu-BO91bOZQVJxkqCWGCSJWLIJJLbvDbbMLm0sAA76EBPOpgvxfnf8MNcnBHQNnX47su0Nxk_Fm68-cN74RVg_6NID4fguQBG_sTF6LGkSyoC-vbEMArqxBXVSHLColKT5LGtsamHZ8UlinJoDWCHPze88Mnk3sfV1DxeJl-IxDs-SqBY_pqVRIA1iu1U4DpJbfP3RsP8KC3oDBCI6uMw-aJDXXW_HgtaoQjJj1_cx4xw"
    }
  },
  "request": {
    "type": "LaunchRequest",
    "requestId": "amzn1.echo-api.request.e299bcdb-3601-468d-8768-78ac1c06d27b",
    "timestamp": "2018-06-28T07:04:17Z",
    "locale": "en-US",
    "shouldLinkResultBeReturned": false
  }
}
2018-06-28T07:04:18.263 [Info] C# HTTP trigger function processed a request.
2018-06-28T07:04:18.263 [Info] Default LaunchRequest made
2018-06-28T07:04:18.263 [Info] Function completed (Success, Id=adc4575d-5a63-4145-8c9c-5e713acbaaf0, Duration=7ms)
2018-06-28T07:05:54  No new trace in the past 1 min(s).
2018-06-28T07:06:55  No new trace in the past 2 min(s).
2018-06-28T07:07:55  No new trace in the past 3 min(s).

1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

{
	"body": {
		"version": "1.0",
		"response": {
			"outputSpeech": {
				"type": "PlainText",
				"text": "Welcome to the azure skills portal from GOB that only knows how to say your Firstname and Lastname"
			},
			"card": {
				"type": "Simple",
				"title": "Alexa Azure Nav",
				"content": "Welcome to Azure voice service"
			}
		},
		"sessionAttributes": {}
	}
}

0 Likes 0 ·
KAIYIN@AMAZON.COM avatar image
KAIYIN@AMAZON.COM answered ·

It looks correct to me that you get IntentRequest by setting

elseif(data?.request.type =="IntentRequest") {

string intentName = data.request.intent.name;

log.Info($"intentName = {intentName}");

}

Can you log the entire request when you trigger the intent? To see if you receive a request from Alexa or not. And also, go to alexa.amazon.com and check under settings/history to see what utterances have been recognized. If utterance for the intent can be recognized in a right way, there should be a request sent out by Alexa.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.