Dialogflow loses context unexplainably - dialogflow-es

I don't understand what happens with my bot, at some point during the conversation it loses some context variables.
In the following screenshot, you can see that the variables school and campus are empty. That's weird because the reply the bot does is
Voici les bourses disponibles pour IDRAC Paris
Where IDRAC is the school variable, and Paris is the campus.
I don't understand how the bot can both display the proper value (set previously by different Intents), and not have the value set.
Here is the Diagnostic Info
{
"responseId": "759621b6-58cc-417e-a635-46df7627d279",
"queryResult": {
"queryText": "bourses",
"parameters": {
"type": "Bourses",
"school": "",
"campus": ""
},
"allRequiredParamsPresent": true,
"fulfillmentText": "Voici les Bourses disponibles pour IDRAC Paris",
"fulfillmentMessages": [
{
"text": {
"text": [
"Voici les Bourses disponibles pour IDRAC Paris"
]
}
},
{
"text": {
"text": [
"Vous pouvez me demander des détails sur celles qui vous intéressent"
]
}
}
],
"outputContexts": [
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/school_campus_set",
"lifespanCount": 249,
"parameters": {
"school.original": "",
"type": "Bourses",
"school": "",
"type.original": "bourses",
"campus.original": "",
"campus": ""
}
},
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/awaiting_solution_id",
"lifespanCount": 1,
"parameters": {
"school.original": "",
"type": "Bourses",
"school": "",
"campus.original": "",
"type.original": "bourses",
"campus": ""
}
},
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/awaiting_campus",
"lifespanCount": 1,
"parameters": {
"type": "Bourses",
"school": "",
"campus.original": "",
"type.original": "bourses",
"campus": "",
"school.original": ""
}
},
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/current_session",
"lifespanCount": 250,
"parameters": {
"type": "Bourses",
"school": "",
"campus.original": "",
"type.original": "bourses",
"campus": "",
"school.original": ""
}
},
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/type_set",
"lifespanCount": 15,
"parameters": {
"type": "Bourses",
"school": "",
"campus.original": "",
"type.original": "bourses",
"campus": "",
"school.original": ""
}
},
{
"name": "projects/hep-playground/agent/sessions/f69b9423-25d0-bc30-bfff-5f71da18f62d/contexts/school_set",
"lifespanCount": 23,
"parameters": {
"type": "Bourses",
"school": "",
"campus.original": "",
"type.original": "bourses",
"campus": "",
"school.original": ""
}
}
],
"intent": {
"name": "projects/hep-playground/agent/intents/e3236893-676e-4e53-8c87-5b1aa974411e",
"displayName": "UserSetsType"
},
"intentDetectionConfidence": 1,
"languageCode": "fr"
}
}
I don't understand why the same keys are repeated over and over in every contexts, it doesn't make sense.
We tried to put a current_session as output of every intent, hoping that it would keep the context alive somehow (following this guide: https://miningbusinessdata.com/better-dialogflow-bots-part-4-session-variables/)
More of the bot's configuration:

The issue is that your UserSetsType Intent has all three parameters defined. The school and campus parameters are empty strings if the user doesn't say anything that would fill them, and most of your responses don't include a way for them to be filled.
All Contexts active (both specified in the GUI and defined by you) capture the parameters that are defined for the Intents that are triggered, even if they are not filled by the user. They're filled with the empty string, to indicate they weren't specifically filled Even if they previously had values, indicating that you're attempting to get the value from a particular Intent will replace them with the empty string, indicating you didn't get them from that Intent.
So even if school and campus were set in a previous Intent. The fact that you specified them in the UserSetsType Intent means that those values will be replaced with whatever matched for that Intent, and those new values will be put in the current_session Context.
While you are on the right track to store the accumulated state in a Context, if you have parameters that may be specified by multiple Intents, then you should be adding them to that session Context under a different parameter name that will be non-conflicting. (So you might map school to savedSchool.)

Related

Slack bot not allowing users to submit, "We had some trouble connecting. Try again?"

I'm trying to get a slack bot to create a modal which is then responded to by app.views. I use socket mode. Whenever you press submit, it says "We had some trouble connecting. Try again?" and does not allow the user to submit. Does anyone have any fixes for this? I have attempted to also use ProcessBeforeResponse to rectify the issue, but it seems that it does not change the result.
app.command("/bugreport", async ({ command, ack, say}) => { try {
app.client.dialog.open(
{
"trigger_id": command.trigger_id,
"dialog": {
"callback_id": "bug-report",
"title": "Make an issue",
"submit_label": "Request",
"notify_on_cancel": true,
"state": "idk",
"elements": [
{
"type": "text",
"label": "Your Name",
"name": "username"
},
{
"type": "select",
"label": "Issue Severity",
"name": "severity",
"options": [
{
"label": "Minor",
"value": "minor"
},
{
"label": "Moderate",
"value": "moderate"
},
{
"label": "Urgent",
"value": "urgent"
},
{
"label": "Critical",
"value": "critical"
}
]
},
{
"label": "Description",
"name": "description",
"type": "textarea",
"hint": "Describe the bug in this section. Be thorough and explain the exact cause of the bug"
},
{
"label": "Bug timeline",
"name": "timeline",
"type": "text",
"placeholder": "When did this issue first appear"
},
{
"label": "Expected Behaviour",
"name": "excpectedBehaviour",
"type": "textarea",
"hint": "Detail what you expected the code to do. Just what it was meant to do."
},
{
"label": "Actual Behaviour",
"name": "actualBehaviour",
"type": "textarea",
"hint": "What actually happened, what was different."
},
{
"label": "Steps to reproduce",
"name": "steps",
"type": "textarea",
"placeholder": "1. [First Step]...\n 2. [Second Step]... \n 3. [And so on]... \n"
},
{
"label": "Additional Information",
"name": "additionalInformation",
"type": "textarea",
"hint": "Anything extra to include."
}
]
}
}
)
await ack();
} catch (error) {
console.log("err")
console.error(error); } });

I am getting invalid_blocks_format while trying to post a message to slack

I am trying to post a message to slack using node.js but I got invalid_blocks_format error. In the slack API reference says that: this error occurs because of invalid JSON or wrong Block KIT syntax. I have checked both and everything seems correct. An example of my payload:
{
"channel": "CHANNELID",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Someone* just replied"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Email:*\n<https://example.com/some-url?query-param=value|someone#email.com>"
},
{
"type": "mrkdwn",
"text": "*Campaign:*\n<https://example.com/some-url|Name - Some value>"
},
{
"type": "mrkdwn",
"text": "*Replying To:*\nanotheremail.com"
},
{
"type": "mrkdwn",
"text": "*Assigned To:*\nName Surname"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ">Stop\n>\n>On Aug 8, 2022, at 6:40 PM, Sender <sender#email.com> wrote:\n>\n> Hi Someone,\n>\n>My name is Name from A company.\n>\n>Some content\n> \n>Content continues(https://blog.example.com/ulr?query-param=value) Content. \n>Would you like to book a demo?(https://example.com/url) \n>Let me know and I’ll schedule it.\n>\n>\n>Name Surname\n>Customer Success Manager\n>Company Name\n>\n> \n>\n>\n>\n>CONFIDENTIALITY NOTICE: This message, including any attachments, is the property of Company name Ltd., its affiliates and/or subs"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Recipient"
},
"action_id": "view",
"url": "https://example.com/view?query=asd",
"style": "primary"
},
{
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Set lead status"
},
"action_id": "set-lead-status",
"options": [
{
"text": {
"type": "plain_text",
"text": "Open Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Open"
},
{
"text": {
"type": "plain_text",
"text": "Ignore Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Ignored"
},
{
"text": {
"type": "plain_text",
"text": "Lost Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Lost"
},
{
"text": {
"type": "plain_text",
"text": "Won Lead"
},
"value": "env=prod;recipientID=1234567;leadStatus=Closed"
}
]
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Pause Recipient"
},
"action_id": "pause",
"value": "env=prod;recipientID=1234567;"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Unsubscribe"
},
"action_id": "unsubscribe",
"value": "env=prod;recipientID=1234567;",
"style": "danger",
"confirm": {
"title": {
"type": "plain_text",
"text": "Unsubscribe recipient"
},
"text": {
"type": "plain_text",
"text": "Are you sure you want to unsubscribe email#address.com?"
},
"confirm": {
"type": "plain_text",
"text": "Yes"
},
"deny": {
"type": "plain_text",
"text": "Cancel"
}
}
}
]
}
],
"token": "token-value"
}
Also when I try to post this over https://app.slack.com/block-kit-builder, message posted without any problem. What can be the problem and how can I fix it?
Thanks for any help/suggestion.
UPDATE
I figured out the problem but not the solution.
Problem is url's with more than one query parameters. If any text has a link like;
https://example.com/url?param1=value1&param2=value2
Sources suggested to encode texts but if I do that, slack prints it without decode it. So sent message is not readable. I am still open to suggestions.
Channel should not be inside the block but as a property while using the Slack API.
Exemple using Slack WebClient in node.js:
client.chat.postMessage({
channel: 'channelId',
blocks: 'yourBlock',
});
I was using an old version of slack lib on node and messages contain ampersand (&) caused the problem like links with more than one query parameters. Updating library solved my problem.

How to create 3 option buttons in adaptive/hero card in bot farmework without post back

I have run into a use case where I need to design a card with 3 option buttons which are clickable but do not Postbank directly. Only when user clicks on submit button, the selected option button values are posted back.
how to achieve it in azure bot framework using rich cards?
This is possible and please find the code below, you can always pass data property inside your Submit button. In my case it is for the msteams channel, and it is available for different channel too. The data property contains another key called Value, which contains object of different key value pairs that you can pass. This will pass the data to the channel and you can always set a display text for the message or you can leave blank.
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "Container",
"$data": "${$root}",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "You can click here to search KB article for this topic on ServiceNow",
"wrap": true
}
]
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "278px",
"items": [
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Search KB articles",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "",
"text": "search-kb-article",
"value": {
"id": "search-kb-article",
"action": "searchKBArticleAction",
"keyword": "${$data.LastMessage}"
}
}
}
}
]
}
]
},
{
"type": "Column",
"width": "30px",
"items": [
{
"type": "Image",
"url": "https://ipnq4wdas01.azurewebsites.net/Images/home.png",
"selectAction": {
"type": "Action.Submit",
"data": {
"msteams": {
"type": "messageBack",
"displayText": "",
"text": "Home",
"value": {
"id": "Home",
"action": "menuAction",
"value": "Home"
}
}
}
}
}
]
}
]
}
],
"style": "emphasis",
"bleed": true
}
]
}

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;

Resources