Using Watson conversation, how to handle customer, account number etc - ibm-watson

I'm creating sample application using Watson conversation API in nodejs. I'm trying to get username and send them to Watson and then I want to say hello "$username", also I want to keep that throughout the conversation so that I can if the user ask if I remember the name, Watson can say "yes, "$username"".
Can someone help me with sample code, how to use intent in this use case.
// Start conversation with Hello message.
conversation.message({
input: { text: "Hello" },
}, processResponse);
// Process the conversation response.
function processResponse(err, response) {
if (err) {
console.error(err); // something went wrong
return;
}
// If an intent was detected, log it out to the console.
if (response.intents.length > 0) {
//console.log('Detected intent: #' + response.intents[0].intent);
console.log(response.context)
}
// Display the output from dialog, if any.
if (response.output.text.length != 0) {
console.log("Watson : "+response.output.text[0]);
}
// Prompt for the next round of input.
var newMessageFromUser = prompt('Me : ');
// Send back the context to maintain state.
conversation.message({
input: { text: newMessageFromUser },
context : response.context,
}, processResponse)
}

You can use context variables for that.
To extract the name, request the name in 1º node, and in the next node, add this JSON:
{
"context": {
"name": "<? input.text ?>"
},
"output": {
"text": {
"values": [
"Hello $name."
],
"selection_policy": "sequential"
}
}
}
The input.text capture all user has typed.
You can use $ for set and get the context variable with the name: $name will show what user has typed.
In other case, if user typed my name is XXXXX, you can use regex inside your context variable. Check this example for use REGEX inside context variables:
"name" : "<? input.text.extract('^[A-Z][-a-zA-Z]+$') ?>"
#MichelBida did one example with regex, but with another request for user, check this link.
EDIT:
Use:
context.myproperty = "Hello World";
And now have the System Entity #sys-person, this entity extracts names from the user's input. Names are not normalized by the system, so "Will" is not treated as "William", nor vice versa, see official documentation. This entity can be active within Entity -> System Entities -> #sys-person

Related

How to set firebase real;time database rules according to the data?

I want to make my chat data private and only accessible by the logged-in user.
I don't have any idea to set the firebase rules.
My data structure looks like follows.
{
"chat" : {
"-L1223434cI8qG1eLQUyj" : {
"User" : {
"_id" : "66b2-4bac-abe1-fe89a0e29a28",
"name" : "aaaabbbccc"
},
"friendID" : "8bcd-4b62-bb4e-25b7c1df4ca2",
"text" : "hello",
"timestamp" : 1573113592492
}
I want to compare _id to all the authenticated users I have under my application and want to provide access to the user where only his/her id is being used.
You can achieve the desired outcome with the following security rules that make use of the built-in auth variable that holds information about the currently logged in user:
{
"rules": {
"chat": {
"$msg_id": {
// grants write access to the owner of this message
// whose uid must exactly match the value of _id
".write": "data.child("User/_id").val() === auth.uid",
// grants read access to the owner or recipient of this
// message whose uid must exactly match the saved uids
".read": "data.child("User/_id").val() === auth.uid || data.child("friendID").val() === auth.uid"
}
}
}
}
I recommend reading the Securing Data and User Based Security documentation for further details which explain the concepts in a better fashion than repeating here.

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

passing selected button value from fb messenger to dialog flow

I am failing to understand the simple passing of parameters to and fro via webhook. i am trying to build a simple bot using dialog flow and fb messenger. i have requirement to show two buttons to the end user to pick a cake type. i am able to show the options using the below custom response:
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "What kind of cake would you like?",
"buttons": [
{
"type": "postback",
"payload": "witheggs",
"title": "Contain Eggs"
},
{
"type": "postback",
"payload": "noeggs",
"title": "Eggless"
}
]
}
}
}
}
once user tap one of the two buttons then how do i set it to some variable in dialog flow and then ask next set of question?
I guess you're missing few steps here. Before, I explain you what to do, be sure to know what a postback is! Postback, when tapped, the text is sent as a user query to dialogflow.com.
Step-1: I created an intent with custom payload as follows:
Step-2: Now, I created a new intent where I have entered user says as noeggs which is of type postback & payload as noeggs the in previous image.
Step-3: Save & test it in FB Messenger.
So basically, what has happened here is, when you click on Eggless button, postback as noeggs is sent as user query to dialogflow.com where there is an intent which matches user says with noeggs & sends response back.

Multiple answers for a node in IBM Watson Conversation service

How I can specify multiple answers for a specific dialog node? For example, when user asks “What is your name”, my VA should reply “My name is Alexander”, or “You can call me Alexander”, or “Friends call me Alex”.
Maybe Conversation service must return a code and application checks the code and choose a random answer from answer's db.
For the application node that gives the response, select advanced mode and change to this:
{
"output": {
"text": {
"values": [
"My name is Alexander.",
"You can call me Alexander",
"Friends call me Alex"
],
"selection_policy": "random",
"append": false
}
}
}

good way for my database app RESTful hierarchy and push to array

I use firebase with ionic (angularJS) and its my first utilisation of firebase. Im thinking about my database hierarchy and I am i bit confused.
myapp {
"gyms": {
"0": {},
"1": {},
"2": {}
},
"users" : {
"0" : {},
"1": {},
"2": {}
},
"sessions" : {
"0" : {
"user_id": {
"session_id": {
"routes": {
"0": {
},
"1": {
},
"2": {
},
}
}
}
},
"1": {},
"2": {}
},
}
What i need with RESTful :
// GYMS
gyms/
GET all gym objects
POST : I put manually a new gym with id: 0, 1, 2 ...
gyms/:gym_id
GET the gym corresponding to the id
exemple : gyms/0
gyms/:gym_id/users
GET all users from a specific gym
// USERS
users/
GET all users
POST create a new user, i would have a user_id numeric like id 0, 1, 2...
users/:user_id
GET the user corresponding to the id
// SESSIONS
sessions/
GET all sessions objects
sessions/:user_id
GET all sessions from a specific user
POST create a new session for the user
sessions/:user_id/:session_id
GET a specific session from a specific user
sessions/:user_id/:session_id/routes
GET all routes from a specific session and user
POST create a new route for the session
sessions/:user_id/:session_id/routes/:route_id
GET a specific route from a specific session and user
for resume, gyms contains users who have sessions. Each sessions contains routes. Each user is associated to a gym, and each session is at a user. Each session contains some routes. First time i make a JSON database, so, it is good ?
I said higher i want id like 0, 1, 2 for having a RESTful url like sessions/12/4/routes/8. But i seen the article for array and push with uniqueID generated from firebase like "-JyNAzZHIoMEpBe39a55" but what is the function for pushing an object to an array and have a id like 0, 1, 2? Because url like sessions/JyNAzZHIoMEpBe39a55/JyNAzZHIoMEpBe39a57/routes/JyNAzZHIoMEpBe39a57 are less human readable no ?
sorry for my bad english !
Sequential indices may be more readable. Whether they are better, depends on your aims. Firebase was designed for highly scalable multi-user systems, where indices are likely to become a bottleneck as users are adding items to the database.
From the Firebase blog post on our push ids:
We created push IDs for collaborative, multi-user applications to handle situations where many clients are adding to a list at the same time. We needed IDs that could be generated client-side so that they wouldn’t need to wait for a round-trip to the server. And we needed them to be unique so that many clients could append data to the same location at the same time without worrying about conflicts.
You're free to come up with your own scheme of course, but this summarizes why Firebase recommends using push ids.

Resources