How to display a file when a user requires it in Watson-Conversation? - ibm-watson

I would like to know how to display a file when a user types something.
Ex: Show me the course details
Output: The file(pdf format) which is on my PC gets displayed.

Basically, you need to know how to work conversation: is one API for creating Intents, Entities and your Dialog flow.
Your application will access all nodes with the return from the API, and you will create conditions to get something for know if the user asked something about "Show me the course details".
I recommend to you create one intent like #aboutCourse and show examples to Watson know if the user will ask something with this purpose.
Something like:
Watson says: Hi! How can I help you?
User: Please show me the course details
Watson will recognize your intent and response what you paste within the node with the Intent condition #aboutCourse.
Make sure if the user really want this with:
Watson says: You really want to know details about the course?
User: yes / ok // or something to confirm
Or you can add some Intent confidence level for this node condition like: intents[0].confidence >= 0.75
And your code will check if the Intent is #aboutCourse and the entity is #yes, and do something in your application.
Or, you can create one context variable too, because, depends on your node flow, the intents will modify within your flow because every time Watson try to recognize what the user wants.
With your dialog flow, you will create one context variable and check if user says yes, like:
{
"context": {
"courseConfirm": "<? #yes ?>" //create one intent with confirm examples and value equal yes
},
"output": {
"text": {
"values": [
"Ok, you say #yes. I'll check, one moment."
],
"selection_policy": "sequential"
}
}
}
And within your application:
function updateMessage(input, response) {
if (response.context.courseConfirm == 'yes') {
//do something with code with code
}
}
Or you can create one function inside my example, like this answer.
Obs.: This code example is with conversation-simple project, from IBM Developers, but you will do something like my example with the same logic:get the return from API and do something within your application.

Related

Google Smart Home Toggles Trait mysterious utterances

I'm struggling to complete the development for a SmartHome action on our security panels, involving different trait implementations (including ArmDisarm, Power, Thermostats, etc.).
One specific problem is related to Toggles Trait.
I need to accept commands to enable or disable intrusion sensor bypass/exclusion.
I've added to the SYNC response the following block, for instance, for a window sensor in the kitchen:
{
'id': '...some device id...',
'name': {'name': 'Window Sensor'},
'roomHint': 'Kitchen',
'type': 'action.devices.types.SENSOR',
'traits': 'action.devices.traits.Toggles',
'willReportState': true,
'attributes': {
'commandOnlyToggles': false,
'queryOnlyToggles': false,
'availableToggles': [
{
'name': 'bypass',
'name_values': {
{ 'name_synonym': ['bypass', 'bypassed', 'exclusion'}, 'lang': 'en'],
{ 'name_synonym': ['escluso', 'bypass', 'esclusa', 'esclusione'], 'lang': 'it'}
},
}
]
}
}
I was able to trigger the EXECUTE intent by saying
"Turn on bypass on Window Sensor" (although very unnatural).
I was able to trigger the QUERY intent by saying
"Is bypass on Window Sensor?" (even more unnatural).
These two utterances where found somewhere in a remote corner of a blog.
My problem is with Italian language (and also other western EU languages such as French/Spanish/German).
The EXECUTE Intent seems to be triggered by this utterance (I bet no Italian guy will ever say anything like that):
"Attiva escluso su Sensore Finestra"
(in this example the name provided in the SYNC request was translated from "Window Sensor" to "Sensore Finestra" when running in the context of an Italian linked account).
However I was not able to find the utterance for the QUERY request, I've tried everything that could make some sense, but the QUERY intent never gets triggered, and the assistant redirects me to a simple search on the web.
Why is there such a mistery over utterances? The sample English utterances in assistant docs are very limited, and most of the times it's difficult to guess their counterpart in specific languages; furthermore no one from AOG has ever been able to give me any piece of information on this topic.
It's been more than a year now for me, trying to create a reference guide for utterances to be included in our device user manual, but still with no luck.
Can any one of you point me to some reference?
Or is there anything wrong with my SYNC data?
You can file a bug on the public tracker and include the QUERYs you have attempted. Since the execution intents seem to work, it may just be a bug in the backend grammar that isn't triggering.

Errors with multi turn dialog in alexa skills

I have created a skill with name "BuyDog" and its invocation name is "dog app"
So that should mean, I can use the intents defined inside only after the invocation name is heard. (is that correct?)
Then I have defined the Intents with slots as:
"what is {dog} price."
"Tell me the price of {dog}."
where the slot {dog} is of slot type "DogType". I have marked this slot as required to fulfill
Then I have added the endpoint to AWS lambda function where I have used the blueprint code of factskills project in node.js, and done few minor changes just to see the working.
const GET_DOG_PRICE_MESSAGE = "Here's your pricing: ";
const data = [
'You need to pay $2000.',
'You need to pay Rs2000.',
'You need to pay $5000.',
'You need to pay INR 3000.',
];
const handlers = {
//some handlers.......................
'DogIntent': function () {
const factArr = data;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = GET_DOG_PRICE_MESSAGE + randomFact;
}
//some handlers.......................
};
As per the about code I was expecting when
I say: "Alexa open dog app"
It should just be ready to listen to the intent "what is {dog} price." and the other one. Instead it says a random string from the node.js code's data[] array. I was expecting this response after the Intent was spoken as the slot was required for intent to complete.
And when
I say: "open the dog app and Tell me the price of XXXX."
It asks for "which breed" (that is my defined question) But it just works fine and show the pricing
Alexa says: "Here's your pricing: You need to pay $5000."
(or other value from the data array) for any XXXX (i.e. dog or not dog type).
Why is alexa not confirming the word is in slot set or not?
And when
I say: "open the dog bark".
I expected alexa to not understand the question but it gave me a fact about barking. WHY? How did that happen?
Does alexa have a default set of skills? like search google/amazon etc...
I am so confused. Please help me understand what is going on?
Without having your full code to see exactly what is happening and provide code answers, I hope just an explanation for your problems/questions will point you in the right direction.
1. Launching Skill
I say: "Alexa open dog app"
It should just be ready to listen to the intent...
You are expecting Alexa to just listen, but actually, Alexa opens your skill and is expecting you to have a generic welcome response at this point. Alexa will send a Launch Request to your Lambda. This is different from an IntentRequest and so you can determine this by checking request.type. Usually found with:
this.event.request.type === 'LaunchRequest'
I suggest you add some logging to your Lambda, and use CloudWatch to see the incoming request from Alexa:
console.log("ALEXA REQUEST= " + event)
2. Slot Value Recognition
I say: "open the dog app and Tell me the price of XXXX."
Why is alexa not confirming the word is in slot set or not?
Alexa does not limit a slot to the slot values set in the slotType. The values you give the slotType are used as a guide, but other values are also accepted.
It is up to you, in your Lambda Function, to validate those slot values to make sure they are set to a value you accept. There are many ways to do this, so just start by detecting what the slot has been filled with. Usually found with:
this.event.request.intent.slots.{slotName}.value;
If you choose to set up synonyms in the slotType, then Alexa will also provide her recommended slot value resolutions. For example you could inlcude "Rotty" as a synonym for "Rottweiler", and Alexa will fill the slot with "Rotty" but also suggest you to resolve that to "Rottweiler".
var resolutionsArray = this.event.request.intent.slots.{slotName}.resolutions.resolutionsPerAuthority;
Again, use console.log and CloudWatch to view the slot values that Alexa accepts and fills.
3. Purposefully Fail to Launch Skill
I say: "open the dog bark".
I expected alexa to not understand the question but it gave me a fact about barking.
You must be doing this outside of your Skill, where Alexa will take any inputs and try to recognize an enabled skill, or handle with her best guess of default abilities.
Alexa does have default built-in abilities (not skills really) to answer general questions, and just be fun and friendly. You can see what she can do on her own here: Alexa - Things To Try
So my guess is, Alexa figured you were asking something about dog barks, and so provided an answer. You can try to ask her "What is a dog bark" and see if she responds with the exact same as "open the dog bark", just to confirm these suspicions.
To really understand developing an Alexa skill you should spend the time to get very familiar with this documentation:
Alexa Request and Response JSON Formats
You didn't post a lot of your code so it's hard to tell exactly what you meant but usually to handle incomplete events you can have an incomplete even handler like this:
const IncompleteDogsIntentHandler = {
// Occurs when the required slots are not filled
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'DogIntent'
&& handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
},
async handle(handlerInput) {
return handlerInput.responseBuilder
.addDelegateDirective(handlerInput.requestEnvelope.request.intent)
.getResponse();
}
you add this handler right above your actual handler usually in the index.js file of your lambda
This might not fix all your issues, but it will help you handle the event when a user doesn't mention a dog.

How watson conversation should say good afternon based on time zone?

If the user logins to the website in morning, watson would say Good Morning!
If the user logins to the website in afternoon, watson would say Good afternoon!
If the user logins to the website in evening, watson would say Good Evening!
I've written like this
{
"conditions": "now().before('12:00:00')",
"output": {
"text": {
"values": [ "Good morning!" ]
}
}
}
But after closing the json editor the code is changing to like this:
{
"output": {
"text": {
"values": [
"Good morning!"
]
}
}
}
Can anyone please say what the solution is? Please provide the entire code for
["good morning,good afternoon,good evening"]
`
You can't define conditions in the JSON editor. So it deletes any field that is not part of the schema.
You can set the condition within the tooling UI at the IF statement section. Just paste in your condition part. As the functionality has recently changed, you will need to do the following.
On the Welcome node, click the "Customise" Cog. Select "Allow multiple responses".
Set your conditions now at each response part.
If you are using the workspace API, then I recommend to export your workspace to see how a node block is correctly structured. Alternatively you can check the API spec.
https://www.ibm.com/watson/developercloud/conversation/api/v1/#create_workspace

IBM Watson - How to get login from user with Regex

I'm working with IBM Watson API's a few months ago.
I want to know more about Regex inside the Conversation Service. And how to get the login from the user, if they type some like:
My login is sayuri.mizuguchi!
My login? ooh, is sayuri.mizuguchi
The default is always firstname.lastname.
I want use input.text.find to get the login, and with one context variable I'll save the login, like:
{
"context": {
"loginUser": <? input.text ?>
},
Simon did the same but with other data, 11 numbers and works amazingly.
In this case I'll use just input.text because my input.text.find inside the node with IF condition will extract my data.
I find this solution with regex, #revo help with one example.
Try this inside the if condition:
input.text.find('\w+\.\w')
And only if user types login, the conversation will flow.

Securing system-generated nodes in firebase

I've been going through the rules guide but haven't found an answer to this.
App users are able to submit "scores" of different types, which are then processed in JS and written to a "ranking" node. I have it set up so that every time a new score is submitted, the rankings are automatically recalculated and a new child is written if the user doesn't exist or updated if the user exists.
My question is how to secure this "ranking" node. Everyone should be able to read it, nobody except the system should be able to write it. This would prevent people from submitting their own rankings and aggregate scores.
EDIT
This is the operation:
Ref.child('rankings').child(uid).once('value', function (snapshot) {
if (snapshot.exists()) {
snapshot.ref().update(user); //user object created upstream
} else {
var payload = {};
payload[uid] = user;
snapshot.ref().parent().update(payload);
}
});
How would I add custom authentication to this call? Also, since I'm using AngularJS, is there any way to hide this custom token or would I have to route it through a backend server?
The key part of your problem definition is:
only the system should be able to write it.
This requires that you are able to recognize "the system" in your security rules. Since Firebase security is user-based, you'll have to make your "system" into a user. You can do this by either recording the uid from a regular user account or by minting a custom token for your "system".
Once you have that, the security for your ranking node becomes:
".read": true,
".write": "auth.uid == 'thesystem'"
In the above I assume you mint a custom token and specify thesystem as the uid.

Resources