I worked on Dialogflow where I have set the context for my intent but don't know how to set the context in Alexa
user: open demo bot
alexa: welcome! How can I help you?
User: update my name
Alexa: What's your name?
User: Jason
Alexa: your name is updated as Jason, Anything else?
user: John
Alexa: your name is updated as John, Anything else?
it should give an error but it directly updates the name (John).
example 2
user: open demo bot
alexa: welcome! How can I help you? (WelcomeIntent)
user: order food
alexa: We offer item1, item2. What you would like to have? (FoodItemIntent)
user: item2
alexa: you have ordered item2, your order will be served soon. (OrderFoodIntent)
food ordering session completed here
now if user again says any food item like
user: item1
alexa: you have ordered item1, your order will be served soon. (OrderFoodIntent)
it should not directly update the ordered item it should prompt an error message like "I didn't get that, you can ask me to order food or update name"
as the food order session has been completed.
In Alexa, it currently not possible as easily as it is in Dialogflow. But you can play with the server-side, where you can simulate context.
For example, in Alexa's response/request, you will store intent history and values. Based on that you can build context on the server-side. Like when you receive intent that doesn't fit the context, you will send user reprompt to say whatever you need. For that, I recommend some general intents like text_intent which matches the text, or number_intent for numbers and so...
Or if you can put it to a different level when you somehow get what have user asked (not intent), then the sentence will be sent do dialogflow NLU API, and based on the sentence you will get context answer.
Related
i am building a small web app with MERN, i have a collection that holds "name, email, password, avatar url, and date" and i am going to add to the users some info like a "bio, hobbies(array), "visited countries(array), and another array"
question is, should i create a diffrent model for the users info, and add owner field that refers to the other model?. or should i put all of them there,
also i might add the following and followers option in the future.
The user's info should be in the user collection, I could see there is no reason to have a separate collection for it. If you want to reduce the responses from listing users, you could use populate to remove unnecessary fields.
Regards to the following and followers, I think there are 2 approaches:
Adding a new field which used to store id and necessary metadata (name, avatar) of users to the existing collection
Create a new collection which is a combination of users and users they are following, or are followed. You then could use Virtual to get this information from the User collection.
Personally, I prefer the first approach although it requires more effort to maintain the list to be accurate. E.g remove an item out of the list when your follower stops following you.
Under the category of User I have two entries that have the same synonym. If this synonym is the same for two of the entries is it possible for the dialogflow to ask which entry I want?
DialogFlow Entity Entry Screen
When the chat bot prompts for the User and John is said the bot will then answer with something like Which John? 123 or 321?
i don't think what you are doing now will work. dialog flow wont be able to detect which entity you want to use. that you should do with your business logic. one thing you can do is you can create a intent for
Which John? 123 or 321?
and invoke that from the Response of your webhook using followupEventInput.
"followupEventInput": {
"name": "event name",
"languageCode": "en-US",
"parameters": {
"param": "param value"
}
}
https://dialogflow.com/docs/fulfillment#sample_response_from_the_service
or you can use events. events is a feature that allows you to invoke intents by an event name instead of a user query.
https://dialogflow.com/docs/events
This is not possible with Dialogflow alone. You could implement this in your backend, but then you would loose the benefit of the Developer Mapping Entity, which is to give you a primary key (the reference value) without requiring further processing on your part. It might then be simpler to just get the user input with a #sys.any parameter and to do all the id matching in your backend.
I am having a welcome intent and it allows user to select three different actions. Ex: Welcome! you can print your firstname, you can print your lastname or you can print your zipcode. If User select or enter last name then it should call the last name intent. So we are providing multiple options at welcome intent itself and user can choose any one of them.
Based on the action selected by user, the conversation should occur.
Please help me how to achieve this.
You are giving the user the option of proceeding by providing their first name, their last name or their zip code.
To capture their response, you will need to create three intents:
Capture First Name
Capture Last Name
Capture Zip Code
For each intent, you would provide a series of example phrases showing how the user might express each thing. For example, "Capture First Name" might contain examples like:
"My first name is Dan"
"Dan"
"Dan is my first name"
I'd recommend providing around 10 examples for each intent.
Dialogflow provides a system entity for zip codes, so it will be able to automatically extract the zip code from the "Capture Zip Code" intent.
However, to make the first and last name intents work, you'll need to create entities to represent the first and last names of all your users. Assuming you know these values ahead of time, you should first create each entity and then write a script to populate it from your datastore using the Dialogflow API's /entities endpoint.
Once you've created and populated these entities, add some examples that make use of them to your intents. Ensure that you highlight and annotate any entity values that are not automatically identified.
When your intents are complete, you can use Dialogflow's fulfillment to send the information they capture to your back-end.
Normally when the welcome intent triggered it will send a request to your backend through webhook,from backend you can send responses as templates or buttons and user can choose one of them ,if you are using backend here
Else in welcome intent response,use a response like you can print firstname ,you can print second name and configure intents for those and use contexts for proper flow.
In the second intent,keep one entity containing some values for first name and use a output context like frstname_output_context
In the another intent,keep one entity containing some values for last name as entity and use a output context like lsttname_output_context
Hope it clarifies using webhook and without webhook.
I am classical developer who is normally developing relational DBs form my web applications.
I want to learn the new way and build an application with mean.js and mongoDB. I used yo generator from the meanjs.org to get started.
When I model my data I always fall back into the classic relational modeling. And I think this is not what the “new way” of app building is all about.
So my question is: What is he best practice to model my data model sample?
My learning sample is an app in which you have a specific given list of music albums (like best 50 Jazz albums of all times) and the user checks in and rate the music.
I have a CRUD module for adding and editing albums the user should listen to. This ends in an ordered list of albums.
I have a CRUD module for users, generated by the yo generator.
A user now can see the list and mark the albums which he already heard. He should be able to give a rating and a comment.
So the question is: where to store the user listenTo info? In the relational world I would introduce a new foreign key table which has a relation from user to album and model the properties like rating and comment in the foreign key table. I don’t think this is how things should work in mongo DB world, does it?
I could add the user listenTo information to each album. I would have a list of users and comments on each album. Then, I need to ensure that if the list is requested, only the information of the current user is present. So I would have to filter on property on a sub-sub-document. Feels strange.
Or, I could copy the album list for each newly created user but then I need to write code that changes the user’s object when I edit the original list.
What would you recommend?
When I think of Data Modeling, I break things down into the following relationships:
1 <--> 1
1 <--> Few/Many (A finite number, say a list of user's phone numbers)
1 <--> Very Many
The general rule of thumb with MongoDB is you should embed wherever possible. So for 1 <--> 1 and 1 <--> Few/Many if the document size is something small, you should embed the collection inside the user document.
It's important to think about the use case here. If we want to track all songs that the user likes or listens to, this could potentially be hundreds or thousands, so we probably want to store this information in a separate collection and contain an indexed reference to the user there.
In the case of tracking if a user listens to the song, I would probably structure it like this in your use case:
{
_id: ObjectID, // The identifier of the document
user_id: ObjectID, // The user who listened to the song
song_id: ObjectID, // The id of the song
count: number, // The number of times the user listened
rating: number, // The number of stars the user rated the song
favorite: boolean, // If the user marked the song as a favorite
last_listened: Date // The last time the user listened
}
With an index on { user_id: 1, song_id: 1 }.
Here is a really good reference on how to approach your problem:
https://docs.mongodb.com/manual/applications/data-models-relationships/
I've read some interesting tutorials about RESTful API design and the concepts behind it is quite clear... but let's put it into practice with Play now.
Suppose we want to implement a RESTful API that provides functionality for dealing with users. Let's start with the model. Here is the Address class:
case class Address(
id: Int,
street: String,
zip: String,
city: String,
country: String
)
... here the User class:
case class User(
id: Int,
email: String,
firstName: String,
lastName: String,
addresses: Array[Int]
// addresses: Array[Address] would this option be better?
)
... and finally the routes:
# Creates a new user
POST /users controllers.users.create
# Gets the user identified by the specified id
GET /users/:userId controllers.users.find(userId)
# Modifies the user identified by the specified id
PUT /users/:userId controllers.users.update(userId)
# Deletes the user identified by the specified id
DELETE /users/:userId controllers.users.delete(userId)
The first question is: how do I retrieve an user by email keeping my API complaint with the REST rules? The following wouldn't work because it conflicts with GET users/:userId:
# Gets the user identified by the specified email address
GET /users/:email controllers.users.findByEmail(email)
The two options I've in mind so far are:
GET /users controllers.users.list(Option[email])
or
GET /users/:email/xxx controllers.users.findByEmail(email)
where xxx should be a kind of virtual resource. Any suggestion for that?
My second and last question is: how should I manage user addresses? Should I get an User, add the new Address to User.addresses, and then update the User with PUT?
PUT /users/:userId controllers.users.update(userId)
... or should I create a specific controller for managing user addresses like this?
POST /users/:userId/addresses/ controllers.addresses.create(userId)
Personally I prefer the second option... but maybe there are better ones.
From your question is not clear whether you want to implement "get" or "find". Usually "get" returns 404 if an user with that email doesn't exist, but I would expect that "find" returns 200 with no results. Personally I would use this:
GET /users/find controllers.users.find(email: Option[String])
Answer to the second question depends on whether you plan to be able to update an address only or you are going to always update an user as a whole. For example you can have a web page with one huge form with all user details & address and you save it all with one HTTP request.
Or another point of view might be whether an address is a standalone resource or is always used (create/read/update/delete) together with an user.
The first question is: how do I retrieve an user by email keeping my API complaint with the REST rules?
I would say simply GET /users/email/:email controllers.users.findByEmail(email) which returns a 200 if a user with the given E-mail exists and a 404 otherwise.
I can see the attraction, but I would arm wrestle #Robin on his idea. It is technically feasible, but it doesn't feel RESTful to me because of my interpretation of the Identification of Resources element of REST. Also, merging two or more possibilities for identifiers to be disambiguated on the server strikes me as brittle code that will force me to work on weekends eventually because user identifiers will come and go as requirements change--forcing me to modify the controller endpoint over and over. I may also be biased by seeing canonical method names like findByName, findByEmail, etc. but never findByYourGuessIsAsGoodAsMine.
My second and last question is: how should I manage user addresses? Should I get an User, add the new Address to User.addresses, and then update the User with PUT?... or should I create a specific controller for managing user addresses like this?
It's clear that the user is the interesting resource rather than an email (Note I am using email where you use address to distinguish from physical address in my mind). My routes would look something like users/:userId/emails/ as you have essentially and to manage them in the Users controller. I see no reason--from either software engineering perspective or a ideological REST perspective--to add the overhead of an extra class.
The following wouldn't work because it conflicts with GET users/:userId
It could still work if your user IDs are never going to be valid email addresses (during the lifetime of this version of the REST API!), so your code can distinguish between them - which is the case with your current types. Of course you can always introduce a new REST API version if you want to relax that assumption in future (e.g. if you wanted to make the user ids arbitrary strings), or if you decide you don't like combining the two types of queries like that.
Should I get an User, add the new Address to User.addresses, and then update the User with PUT?
By default, that's not transactional. However, if you use ETags, you can reject the User update if something else has changed the User in the meantime.