Can I make Dialogflow intents require atleast one of the trained entities? - chatbot

I know how to make intents require any parameter value, after which the intent will force to get the value; but is it possible to make it force to get atleast one of the given entity parameters ?

You could enable webhook fulfillment for that intent and if no entities were provided, reprompt the user for at least one of a list of entities.

Related

Dialogflow agent entities to be contacted through REST APIs

I am developing an agent, and have an entity within the agent.
now what i need is to add some new details to the entity, but not by opening dialogflow.
I want to make a REST API to add it for me.
Is it possible?
It sounds like you're looking for the API to either create or patch entities.
From reading the docs, it doesn't look like this is possible via HTTP requests.
You could try automated expansion:
Automated expansion of developer entities allows an agent to recognize
values that have not been explicitly listed in the entity.
If a user's request includes an item that isn't listed in the entity,
automatic expansion recognizes the undefined item as a parameter in
the entity. The agent sees the user's request is similar to the
examples provided, so it can derive what the item is in the request.
For example, consider a shopping list with items to buy:
If a user says "I need to buy some vegetables", "vegetables" will be
picked up as a value, even though it's not included in the #item
entity. With automated expansion enabled, the agent sees the user's
query is similar to the training phrases provided in the intent and
can pick out what should be extracted as a new value.
The closer the user's input is to the examples provided in the
training phrases section, the better the results the automated
expansion feature provides. This is another reason to provide as many
examples as possible.

Do Google Actions have unique ids?

When developing for Alexa, every skill has a unique Id. This allows me to develop multiple skills, using the same lambda / codebase, that return unique info based on the skill id.
However, from what I've seen with Google Assistant, Actions don't have ids. Requests include a unique userId and the conversationId. And Responses include an intent id -- but there's no way to identify the action itself.
Any ideas / pointers to things I may have missed?
There are a few ways you can approach this, depending on what platform you're using for your webhook.
For both Dialogflow and the Action SDK, you can always specify a unique query parameter as part of the webhook or even have different path portions of the webhook go to the same lambda and examine either the query value or the path. This has the benefit that you're in full control of what the possible values are.
If you're using Dialogflow, there is a unique IntentID for each Intent that comes through. This might be one way to track which one has been invoked. But this seems somewhat kludgy.
Also for Dialogflow, you can set unique headers in the Dialogflow console, and then examine the value of these headers in your webhook. Again, this has the advantage of giving you control of the value.
The Action SDK doesn't have that feature, but it does transmit a JWT token in the Authorization header. This token is for verifying it has come from the correct project (and from Google), but once you've decoded it (and verified it), the aud field should contain the same project ID as the project in the Action Console.

Is there an API for api.ai which can be used to add intents and train the model?

I couldn't find an API for api.ai. The requirement is to add intents and train the model programmatically through an ajax API call.
Yes, API.AI has a REST-like API that lets you manipulate Intents, Entities, user specific and session Entities, Contexts, and even execute Queries.
You'll need to read details about the developer token and the version string to use, but documentation about getting, creating, updating, and deleting intents, as well as the layout for the intent object, are available at https://api.ai/docs/reference/agent/intents
If you're familiar with REST-like APIs, it is pretty straightforward.

Updating something in REST

Philosophically, I had questions about some examples on how to tackle the following REST scenarios:
1) A user who is signed in wants to 'favorite' someone's blog posting. The user id is a guid and the blog posting is a guid. Should this be a PUT because user/blog exist, or POST because there is no entry in the 'favorites' table?
2) A security row in the DB consists of 10+ properties, but I'd only want to update one part of the entity (# of failed login attempts for a user). What should the call be? Pass the entire data transfer object in JSON? Or just add a new api route for the specific action to update? I.e. a PUT with just one parameter (the # of login attempts) and pass the id of the user.
3) Similar to #2, a user class (consisting of 25+ properties) but I'd only like the user to update a specific part of the class, not the whole thing. Philosophically do I need to pass the entire user object over? Or is it OK to just update one thing. It seems I could get crazy and make lots of specific calls for specific properties, but the reality is I will probably only update 2-3 specific parts of the user (as well as obviously updating the whole thing in other cases). What's the approach here for updating specific parts of an entity in the DB?
Thanks so much
Use a POST if you don't have an ID/UUID yet.
The resource is the security record. Do a PUT on that ID, and pass a block of the properties to be changed.
Ditto (2). You should get whatever parameters will help you identify that record in the DB. If it's unsavory to send these in the POST request and you're doing AJAX, just stash them in the session.
With REST, everything is about updating discrete resources ("nouns"). It's up to you how you want to assign these, but a simple interface that uses verbs ("PUT", "GET", "DELETE", etc..) sensibly, returns relevant HTTP codes, and is easy for others to implement is the best way to go.
So, just ask yourself, "What nouns do I want to give CRUD to, and am I going to exhaust people who wish to consume my API?"

Restful Api: User id in each repository method?

I am new to both .Net & RESTful services.
Here is the object hierarchy I have in the database: Users->Folders->Notes.
The API: GET /api/note/{noteid}
would get mapped to the repository call
NoteRepository::GetNote(userId, noteId)
Notice that I am passing on the userId to make sure that the note belongs to the logged in user for security purpose.
Is this the right approach? Meaning, every repository call would have the first parameter as the userId to check if the object being accessed belongs to the user.
Is there any better approach?
You don't need the User Id since the
GET /api/note/{noteid}
is indeed unique.
A valid scenario for adding the id would be:
GET /api/{userId}/notes
And then if you want a specific note you can:
GET /api/{userId}/notes/{noteId}
I would implement security at the entry level. whether the user has rights to perform a method on that specific resource. A role model approach would be fine.
Regards.
I would also introduce the user id in the API, because of Stateless and Cacheable constraints described in the Wikipedia REST article.
However, if I check Google Tasks REST API, they don't include the user id, same thing for Twitter API, so it seems a trend not to include the user id. If someone can shed some light I would be grateful.
UPDATE: Thinking more about it, if the noteid is unique across all users, there is no need to include the user id, so a GET /api/note/{noteid} is fine.
However, the logical parent in a restful interface would be GET /api/note/ to get a list of all notes, and here I've the objection, since the list would differ according to the user requesting it, making it non cacheable.
As for your dot net part I think that passing the userid among dot net methods is perfectly fine.