Lex bot getting value only in digit representation not from words - bots

I am a newbie to Amazon Lex, I have created a bot that offers several services:
open a case
check status
status via email
when a user checks the status, he is forced to provide a "case number." The issue I am facing is that it only gets value from digits such as digit representation.
When the user uses "nine" instead of 9, it doesn't work. You can see it here.
Guide me on that issue, I would be very thankful to you.

It seems an AWS Lambda will be best suited to assist you with what you're trying to achieve.
When testing via the AWS Lex console, click the "Inspect" button and view the JSON-formatted requests and responses.
What you will find is that when the user enters a numeric value in words - as in your example "nine" instead of "9" - Lex will provide you with the original input as well as the numeric form of the input.
Take a look at the JSON payload below that I've extracted from my own example:
{
"messages":[
{
"content":"Well done!",
"contentType":"PlainText"
}
],
"sessionState":{
"dialogAction":{
"type":"Close"
},
"intent":{
"name":"MainIntent",
"slots":{
"quantity":{
"value":{
"originalValue":"two",
"interpretedValue":"2",
"resolvedValues":[
"2"
]
}
}
},
"state":"ReadyForFulfillment",
"confirmationState":"None"
},
"originatingRequestId":"e309a92b-124b-4250-bbd3-2fb8891aa90f"
},
"interpretations":[
{
"nluConfidence":{
"score":1
},
"intent":{
"name":"MainIntent",
"slots":{
"quantity":{
"value":{
"originalValue":"two",
"interpretedValue":"2",
"resolvedValues":[
"2"
]
}
}
},
"state":"ReadyForFulfillment",
"confirmationState":"None"
}
},
{
"intent":{
"name":"FallbackIntent",
"slots":{
}
}
}
],
"sessionId":"858917309331613"
}
Have a look at the interpretedValue field in the payload. This is the numeric value that you're looking for.
Using a Lambda function, you can extract this value and perform any validation that you may need before continuing with the rest of the flow or user journey.
You can find out more about integrating Lambda functions into Lex from the developer guide:
https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html

Related

Lex V1 group message

I am working on chat bot in Amazon lex v1 ,In that I want to display two messages when the client invoke the bot. But I am facing issue .with lambda
var messageToUse = {
contentType : "Composite",
content :{"messages":[{"type":"PlainText","group":1,"value":"welcome"},{"type":"PlainText","group":2,"value":"To GAC"}]}
};
const response = {
"dialogAction":
{"type": "Close",
"fulfillmentState": "Fulfilled",
"message": messageToUse
}
};
callback(response);
Expected Result should be this
Lex V1 is limited when it comes to working with the API for message groups. The tutorial you were following was able to get multiple messages by using message groups in the content designer (Lex's designer UI). This is different than returning multiple messages through a Lambda function.
Adding the responses in the content designer
A preview of how the responses will look
Unfortunately, the JSON for messages was not a list/array in Lex V1. It only supported key value pairs. This means that a Lex V1 Bot only expects a single message from the Lambda and you cannot return more than one at a time.
The only way you can make Lex V1 appear like it is returning multiple messages is to use a custom front end. If you plan on using a custom front end, you can parse the message.content JSON into different message bubbles yourself.
If you would like to be able to set message groups through a lambda function, I recommend you try using Lex V2. The JSON for messages in Lex V2 expects a list, meaning that you can return multiple messages at once and they will appear in separate bubbles in the Lex V2 test console.
Here is an example of how to do this in Lex V2:
return {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"confirmationState": "None",
"name": "TestIntent",
"state": "Fulfilled"
}
},
"messages": [
{ "contentType": "PlainText", "content": "Hi" },
{ "contentType": "PlainText", "content": "How are you?" },
{ "contentType": "PlainText", "content": "How may I help?" }
]};
And also how they appear in the test console.
I'm sorry this isn't the answer you were hoping for but I hope it helps anyway.

How can I create localized message in Joi from context?

Here is the scenario of what I want to achieve:
User input data is validated in frontend using Joi.
Data is validated in backend, also using Joi.
Potential validation errors are returned to frontend, which can handle those since the same validation framework is being used.
In the frontend, we have translated messages for some errors, and fallbacks to Joi default messages for the rest. In the backend, we have no translations.
My problems come when I'm trying to recreate the error message. How can I:
1) Access a "template string"
In the Joi library each value type has it's own set of template messages:
const messages = {
// ...
'string.min': '{{#label}} length must be at least {{#limit}} characters long',
// ...
};
I can't find out how to access these in an easy way. And I also want to add translated messages, and use these before falling back to the default ones. Is there anything like Joi.getTemplate('string.min')?
2) Recreate the error message
When I get the array with Joi errors from the backend, I want to recreate the error messages, localized if available. The errors look like this:
"details": [
{
"message": "\"name\" length must be at least 10 characters long",
"path": [
"name"
],
"type": "string.min",
"context": {
"limit": 10,
"value": "Joe",
"label": "name",
"key": "name"
}
}
]
Is there some way of doing something like this:
Joi.generateMessageFromTemplate('string.any', details[0].context) or Joi.generateMessage('{{#label}} length must be at least {{#limit}} characters long', details[0].context)
I also need to load the translated message before I do that, in some way.
My feeling is that there should be ways to achieve what I want, but I can't find in the documentation (or the source code) exactly how I should proceed. Please help me :)
const Joi = require('joi').defaults(schema => schema.options({ messages: {
ar:{
'string.empty': 'لا يمكن ان يكون فارغ {{#label}}',
'number.base': 'يجب ان يكون رقم {{#label}}',
'any.invalid': 'قمية غير صالحة {{#label}}',
'phoneNumber.invalid': 'رقم غير صالح {{#label}}',
'array.unique': 'قيمة متكررة {{#label}}',
},
en:{
'string.empty': '{{#error}} Cannot be empty',
'number.base': '{{#label}} Must be a number',
'any.invalid': '{{#label}} Value not valid',
'phoneNumber.invalid': 'Phone Number not valid',
'array.unique': '{{#label}} contains a duplicate value',
}
} }));
and on validate you can select your prefered language like so:
const result = yourSchema.validate({mydatafield:"val"}, {
errors:{language: 'ar'} //en or ar
});

How do I extract JSON Property Value based on Key in Logic Apps?

In Logic Apps I have an "HTTP Receive" which receives the information below.
How do I extract the value from key Location in the Properties?
Note I have >100 Properties
{
"Firstname":"Alice",
"Lastname":"Smith",
"Properties":[
{
"Key":"Age",
"Value":"39"
},
{
"Key":"Location",
"Value":"London"
},
{
"Key":"Id",
"Value":"93405435"
}
]
}
You can refer to the process design of the following Azure logic app:
Then you can get the value based on the filtered result.

IBM Bluemix Discovery - query parameter

I have created a Discovery service on my bluemix account. I want to query my documents from a nodejs application.
I have built a query with some aggregation, tested it using the bluemix online tool and it's working well.
Now when I query the collection from my code, whatever my parameters are, I always receive all of my documents with the enriched text and so on. I think I am missing how to send the query attributes to the service (like filters and aggregations).
Here is my code:
var queryParams = {
query:'CHLOE RICHARDS',
return:'title',
count:1,
aggregations:'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)'
};
discovery.query({environment_id:that.environment_id, collection_id:that.collection_id, query_options:queryParams }, function(error, data) {
if(error){
console.error(error);
reject(error);
}
else{
console.log(JSON.stringify(data, null, 2));
resolve(data.matching_results);
}
});
And the result is always:
{
"matching_results": 28,
"results": [
{
"id": "fe5e2a38e6cccfbd97dbdd0c33c9c8fd",
"score": 1,
"extracted_metadata": {
"publicationdate": "2016-01-05",
"sha1": "28434b0a7e2a94dd62cabe9b5a82e98766584dd412",
"author": "Richardson, Heather S",
"filename": "whatever.docx",
"file_type": "word",
"title": "no title"
},
"text": "......
Independantly of the value of the query_optionparameter. Can you help me?
EDIT
Instead of the query_options:queryParams, I have used query:"text:CHLOE RICHARDS" and it's working well. Now my problem still remains to find the right parameter format to add the aggregations I want
EDIT 2
So I have looked at IBM's example on Github more carefully, and the parameters are now formatted like this:
const queryParams = {
count: 5,
return: 'title,enrichedTitle.text',
query: '"CHLOE RICHARDS"',
aggregations: [ 'nested(enriched_text.entities).filter(enriched_text.entities.type:Person).term(enriched_text.entities.text, count:5)' ],
environment_id: '1111111111',
collection_id: '11111111111'
};
It works well if I use only the query attribute. Now if I only use the aggregations one, all the documents are sent back as a result (which is understandable) but I have no aggregation part, so I can not access the list of proper name in my documents.
Your query does not look right. I you are going to use query then you will need to construct a query search like text:"CHLOE RICHARDS"
If you want to perform a natural language query then you should be setting the parameter natural_language_query.

Actions on Google API v2 using c# webhook

I currently have an app running on actions on google using API.AI. I have modified all the response members to be camelCase as suggested and got it working. Now I am trying to return a basic card, but I can not figure out how to properly return it.
Does anyone have the most basic JSON response, returning a basic card to the Google assistant?
currently, the most basic v2 API response I can have is the following:
{
speech: "",
displayText: "",
data: {
google: {
expectUserResponse: true,
isSsml: true,
permissionsRequest: null
}
},
contextOut: [ ],
source: "webhook"
}
I have some Gists showing the JSON responses here.
Right now, it includes Lists, Basic Card and Carousel, but I will add Transactions hopefully soon. Hope it might help somehow
This is what I use for Voice Tic Tac Toe
"google": {
"expect_user_response": true,
"rich_response": {
"items": [
{
"simple_response": {
"text_to_speech": "Your move was top. I moved left"
}
},
{
"basic_card": {
"image": {
"url": "https://server/010200000.png",
"accessibility_text": "Tic Tac Toe game board"
}
}
}
]
}
}
I ran the facts about google action and looked at the fulfillment JSON output to learn how to do this.
https://github.com/actions-on-google/apiai-facts-about-google-nodejs
Note that all responses must include at least one, and no more than two, simple_response items.

Resources