How to get all matching intents - dialogflow-es

Is there a way to get all matching intents, not only one result with the biggest score, for example right now I get
"result": {
"source": "agent",
"resolvedQuery": "my test",
"action": "",
"actionIncomplete": false,
"parameters": {},
"contexts": [],
"metadata": {
"intentId": "",
"webhookUsed": "false",
"webhookForSlotFillingUsed": "false",
"intentName": "intentName"
},
"fulfillment": {
"speech": "test",
"messages": [
{
"type": 0,
"speech": "test"
}
]
},
"score": 0.9200000166893005
},
I want to return all intents when the score is not high to allow users to choose their intent.

It isn't possible to return all matching intents.
Given the use case described in the comments, you can just set your fallback intent to return a set of suggestions to the user. The fallback intent is triggered when none of the intents have a sufficiently high score to match.

Related

Using custom event(s) in Dialogflow to invoke an event via the detect intent API

I am sending a request to the /query per the documentation with parameter names and parameter values. However I can not get any of the parameter slots to fill within the intent itself.
Example Payload:
{
"contexts": ["member"],
"event": {
"name": "memberLookup",
"parameters": {
"baseState": "az",
"occurrenceState": "ny"
},
"languageCode": "en-US"
},
"lang": "en",
"sessionId": "1"
}
I am referencing in my parameters per the docs, i.e. #memberLookup.baseState
Response Snippet
"result": {
"source": "agent",
"resolvedQuery": "memberLookup",
"action": "",
"actionIncomplete": true,
"parameters": {
"baseState": "",
"occurrenceState": ""
},
Has anyone gotten this functionality to work?
This is really work for me. When I replace word parameters to data I received correct answer with necessary parameters:
[{'name': 'itbooking-vcs_error-followup', 'parameters': {'room_type.original':
'', 'description.original': 'test', 'room_number.original': '', 'description':
'test', 'room_number': '10.12', 'branch': 'headquarter', 'branch.original': '',
'room_type': 'meeting_room'}, 'lifespan': 1}]
V1 formatting is slightly different. Parameters in the body should be data, then the parameters will be filled. Thanks Dialogflow for reaching out and clearing this up for me.
{
"contexts": ["member"],
"event": {
"name": "memberLookup",
"data": {
"baseState": "az",
"occurrenceState": "ny"
},
"languageCode": "en-US"
},
"lang": "en",
"sessionId": "1"
}
New Result:
"result": {
"source": "agent",
"resolvedQuery": "memberLookup",
"action": "",
"actionIncomplete": true,
"parameters": {
"baseState": "az",
"occurrenceState": "ny",
},

Dialogflow - Fulfillment Webhook Response different from Documentation

I'm currently using Dialogflow in combination with fulfillment/webhooks.
In the documentation of the fulfillments there is an example POST request for webhooks:
POST body:
{
"contexts": [
string
],
"lang": string,
"query": string,
"sessionId": string,
"timezone": string
}
The request that I'm receiving on my end is different from what is defined in the documentation. Has somebody an idea why?
This is what I receive:
{
"id": "GUID",
"timestamp": "2018-01-12T12:25:32.202Z",
"lang": "de",
"result": {
"source": "agent",
"resolvedQuery": "Test",
"speech": "",
"action": "",
"actionIncomplete": false,
"parameters": {
"Nummer": ""
},
"contexts": [],
"metadata": {
"intentId": "XYZ",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"intentName": "Intent"
},
"fulfillment": {
"speech": "",
"messages": [{
"type": 0,
"speech": ""
}]
},
"score": 0.6700000166893005
},
"status": {
"code": 200,
"errorType": "success",
"webhookTimedOut": false
},
"sessionId": "GUID"
}
I've found that different invocation sources send slightly different data to the web hook.
For example the Google Action simulator will send different information in the context reply than say the test pane in an intent.
Im guessing that the answer may lie in where/how your calling the web hook.

How to determine the type of the platform in Dialogflow (API.AI)

How do to identify from which platform the message came?
I want to support different platforms like Telegram and Facebook Messenger, When my webhook receive a message, I want to reply according to the platform the message came form.
For example, if the message came from Telegram I want to return a text message but if the message came from messenger I want to return a card.
You have a property source in originalRequest object, see fulfillment docs here.
{
"lang": "en",
"status": {
"errorType": "success",
"code": 200
},
"timestamp": "2017-02-09T16:06:01.908Z",
"sessionId": "1486656220806",
"result": {
"parameters": {
"city": "Rome",
"name": "Ana"
},
"contexts": [],
"resolvedQuery": "my name is Ana and I live in Rome",
"source": "agent",
"score": 1.0,
"speech": "",
"fulfillment": {
"messages": [
{
"speech": "Hi Ana! Nice to meet you!",
"type": 0
}
],
"speech": "Hi Ana! Nice to meet you!"
},
"actionIncomplete": false,
"action": "greetings",
"metadata": {
"intentId": "9f41ef7c-82fa-42a7-9a30-49a93e2c14d0",
"webhookForSlotFillingUsed": "false",
"intentName": "greetings",
"webhookUsed": "true"
}
},
"id": "ab30d214-f4bb-4cdd-ae36-31caac7a6693",
"originalRequest": {
"source": "google",
"data": {
"inputs": [
{
"raw_inputs": [
{
"query": "my name is Ana and I live in Rome",
"input_type": 2
}
],
"intent": "assistant.intent.action.TEXT",
"arguments": [
{
"text_value": "my name is Ana and I live in Rome",
"raw_text": "my name is Ana and I live in Rome",
"name": "text"
}
]
}
],
"user": {
"user_id": "PuQndWs1OMjUYwVJMYqwJv0/KT8satJHAUQGiGPDQ7A="
},
"conversation": {
"conversation_id": "1486656220806",
"type": 2,
"conversation_token": "[]"
}
}
} }

List_card in AoG passing item title to the next query instead of key

In an app, I'm returning messages of type list_card with option key for an intent.
Here is the json of a sample query:
{
"id": "275212ef-cf97-4576-afa7-facfbc044ada",
"timestamp": "2017-07-17T17:36:03.655Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "who is Sneha",
"action": "cp.name_search",
"actionIncomplete": false,
"parameters": {
"keyword": "Sneha"
},
"contexts": [
{
"name": "cpname_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 2
},
{
"name": "cpuid_search-followup",
"parameters": {
"keyword.original": "Sneha",
"keyword": "Sneha"
},
"lifespan": 1
}
],
"metadata": {
"intentId": "86bd1a17-8e9a-4956-b270-5fb4ac952f5f",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 135,
"intentName": "cp.name_search"
},
"fulfillment": {
"speech": "Searching...",
"source": "agent",
"messages": [
{
"type": "simple_response",
"platform": "google",
"textToSpeech": "Here are the search results. \nWant anything else?"
},
{
"type": "list_card",
"platform": "google",
"title": "Search results",
"items": [
{
"optionInfo": {
"key": "uid 72",
"synonyms": []
},
"title": "Sneha Vasista",
"description": "Srinivas Institute of Technology",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2053",
"synonyms": []
},
"title": "Sneha Bhat",
"description": "Canara Engineering College",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2114",
"synonyms": []
},
"title": "Sneha Sajan",
"description": "P.A College of Engineering",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2320",
"synonyms": []
},
"title": "Sneha ",
"description": "sdit",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
},
{
"optionInfo": {
"key": "uid 2363",
"synonyms": []
},
"title": "Sneha ",
"description": "Srinivas School of Engineering, Mukka",
"image": {
"url": "//www.curlpad.com/assets/img/custom_images/user.png"
}
}
]
},
{
"type": "0",
"speech": "Here are the search results."
}
]
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "e6aa9e52-a9e1-481a-adb5-476c5b386e02"
}
Now the problem is, when I tap the list item in AoG simulator, it passes title of item to next query.
But while testing in Api.ai simulator, it behaves well and passes that key to the next query.
What can be the problem here?
Any hints?
If you're using API.AI, then it will appear in the Intent as an actions_intent_OPTION Event.
One good solution is to have the Intent that sends the list with an OutputContext. Then create a particular Fallback Intent with actions_intent_OPTION as Event and your desired action for that Context which should handle both the voice and press responses.
And you will find your option_key at ["originalRequest"]["data"]["inputs"][0]["arguments"][0]["textValue"] instead of parameter.
You can also see the response value in the actions_intent_option context.
What you need to do is set up a fallback intent directly under your current intent.
For example, if you display the list from the default welcome intent, you can do the following.
Click "Add follow-up intent" and choose fallback.
Don't forget to set the action and enable webhook in the fallback intent.
Now, you should be able to retrieve your answer from the fallback intent using the following code.
const param = app.getContextArgument('actions_intent_option','OPTION').value;

API.AI does not connect to my back-end

I'm writing an agent using API.AI I'm observing that my back-end is not called everytime. I can see that in my access logs. Any idea what can cause the issue?
Here is the response of the console:
{
"id": "c1902c75-1550-43f6-9cc8-b0461f1dfac7",
"timestamp": "2016-12-22T19:58:13.49Z",
"result": {
"source": "agent",
"resolvedQuery": "echo test",
"action": "",
"actionIncomplete": false,
"parameters": {
"myInput": "test"
},
"contexts": [],
"metadata": {
"intentId": "062b4383-06a0-40fe-bbeb-9189db49aeb8",
"webhookUsed": false,
"webhookForSlotFillingUsed": "false",
"intentName": "Response"
},
"fulfillment": {
"speech": "",
"messages": [
{
"type": 0,
"speech": ""
}
]
},
"score": 0.75
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "70be8f65-81f0-40be-a271-84a2d4960224"
}
I see there no error which explains why my backend is not called.
Here is a screenshot of my intent:
You have not given any value in the action key of the intent.Give some action name and keep this same name of your function which will accept the parameters from the api.ai
basically the flow is
1)user enters an input.
2)api.ai tries to match the user's input with the intents defined by you, if not found it will got to the fallback intent.
3)once the proper intent is matched then api.ai tries to extract the parameters from the user's sentence.
4)once all the required parameters are found it will call the action which you have defined in the intent.
NOTE: if none of the parameters are required in the intent it directly calls the action .

Resources