Dialogflow V2: Attach user metadata with detect_intent - artificial-intelligence

Usecase: Using Dialogflow v2 APIs a text based chat bot is need to build for placing orders over SMS.
Sample incoming sms:
I want to order 2 pairs of Product #1234
Add 10 pairs of Product #22 to my cart
Each order is associated with the phonenumber and the quality of a product. So how to pass this phonenumber to the Dialogflow, detect intent api call, so it can be passed along with the fullfillment call, to finally make an api call to the backend server.

The easiest way to attach any additional information you want to provide to fulfillment would be to send a Context along with the request. Contexts can have their own parameters, so you would provide the additional information you want to send in these parameters. Your fulfillment can get the Context and the parameters set in it.

Related

Alexa Out -of- session - Skill Messaging API

I’m trying to create an Alexa capability that creates reminders without user voice invocation. To achieve this Alexa suggested to use “Out of session” interaction event i.e Skill Messaging API (https://api.amazonalexa.com/v1/skillmessages/users/{userId}), as you can see in the API we need to pass the user Id, In order to get the user Id Alexa suggest to do first account-linking, once linking is done we’ll get the user profile access including userId. Now, after hitting the Skill Messaging API with received userId, it returns
{type:”not_found”, a message ”invalid user Id”}.
Not sure where am I going wrong. Has anyone phase the same problem.
In the request shown next, set HOST to one of the following, depending on the user's region: api.amazonalexa.com, api.eu.amazonalexa.com, or api.fe.amazonalexa.com

How to get all unique email recipients python gmail api

I want to do a search for all unique email recipients from gmail. But I'm really struggling with API. If I was interacting with a SQL database I would want something like:
SELECT DISTINCT EmailRecipient FROM MyHypotheticalGmailTable;
But I'm not sure how to translate this into a gmail API call.
I suggest you start by taking a look at the Gmail API Quickstart with Python here.
Afterwards you may want to take a look at threads.list in order to list all the threads available and then for each one use threads.get. Since there is no direct method of retrieving the unique email recipients, you will have to handle this separately from the API calls and filter the results programmatically.
Reference
Gmail API Python Quickstart;
Gmail API messages.list;
Gmail API messages.get.

How to store a Correlation ID (X-Correlation-ID) in the application that is responsible for generating it

I'm implementing a correlation ID within my applications and would like some feedback on the design for it. The primary concern is that the correlation ID should be available for all logs.
Lets say I have a web (front-end) application which is serving pages to my users. It talks with two API's which provide data. The API's are not exposed to the user, and so all requests 'begin' in the front-end app.
The API's job is simple, they consume the correlation ID as provided in all headers from the front-end app (X-Correlation-ID) and print it in any logs.
The front-end app has to generate the ID, add it to the headers for outgoing requests, but it must also consume the ID.
My question is this: How does the front-end app store the correlation ID?
My first thought was that it would modify the incoming request and add the header if it did not exist, however this would make the incoming request somewhat 'unreliable' as it is now modified.
Another thought is perhaps it is stored as some kind of application global that is cleared per request.
Correlation ids i.e. ids typically attached to headers like Request-ID, X-Request-ID, X-Trace-ID, X-Correlation-ID are typically issued per request.
You seem to want to store it locally on the client though. What you describe sounds more like a “session id” that gets reset when the client “restarts”. If that is the case, then you simply use local/session storage or cookies to store and clear it when needed.
Do keep in mind that first sentence above though. Correlation ids are typically used per request. What I usually do:
Generate an id on the client per request
Pass it to the API via one of the aforementioned headers
Whoever gets the request first (some API gateway, HA Proxy etc) checks for the existence of the header and proxies it further downstream. So do any services calling other services. This is usually provided as a service:tool to most services/teams so that they don’t forget to do it.
Profit?
That’s what heroku does for example. Same for many other services / companies.
Goes without saying, you can combine the two ids, the “session” one you refer to plus the ones generated per request to get a better view of what is going on in logs etc
As per my design, I'd suggest to always check (intercept using middlewares/filters on backend) each request from the client at the first point of contact at the backend (load balancer/ gateway / controller) and check for the Trace-ID/Correlation-ID at the request header, if present then forward the request as it is, if not present (because this is the first call from that new client), then generate the random ID (as Trace-ID) and attach that newly generated random ID to the Request Header and reroute/pass on the request further down the application.
One more thing, while sending back the response, make sure to again add this ID generated earlier to the Response Header, so that the client can receive this unqiue ID and save it on localstorage/cookie for further calls so that the client could easily be traced using that trace ID.
As you requested for logs, now since you have that correlation ID/trace ID, you can log them anywhere you want and you can easily determine the complete flow of the client's request in case of any issues using this unique ID.
Steps:
Check for the Correlation ID in the Request Header (at Backend)
If already present, allow the request to pass through to the required service.
If not present, generate a unique random ID and add a custom Header in the Request Header.
Again, before sending the response, again add this custom Header to the Response header for client.
I hope that answers your query.

how to add middleware/intercepter for every request in on dialogflow webhook server

how to add middleware/intercepter for every request in on dialogflow webhook server while using Action-on-google library and working with dialogflow application,
the purpose is i want to authenticate on every request that key is still valid or not, and also i want to check if that user is already managing a group then get all members of group and put in /userEntity,
now i'm doing this in wellcome intent, so when user say talk to xyz app in wellcome intent i check in database if user is managing a group then get all members of that specific group and put in user entity,
but this logic become trash when user directly say a command such as if user don't say talk to my xyz app and instead he says ask my xyz app john wink is present or not then app is unable to recognize this name, note that i cannot user system name entity because in my case these are not english names
for now i have restricted direct commands with context combination but it is not good e.g: user cannot say direct command unless WELCOME_DONE context which is context out of wellcome intent
The "direct command" you mention (ask my xyz app john wink is present or not) is what we call an "action invocation phrase". Since you're depending on a user entity in order to extract a name from the action phrase, you'll only be able to do this successfully if another intent has recently been matched, since the user entities you add are only available for 30 minutes.
One way around this might be the following. We are going to do something clever to run the user query through Dialogflow a second time, after adding the user entity.
In the intent that handles your "action invocation", use #sys.any (which is essentially a wildcard entity) to capture the name. Enable the webhook for this intent.
Create another intent with User says examples that match the expected "action phrase", similar to the first intent, but don't add it to your "Additional triggering intents". Enable the webhook for this intent.
Create a function in your webhook that handles the intent from Step 1.
In this function, look up the user and their group and add the members via /userEntity.
Now that the user entity has been created, call the Dialogflow /query API with whatever the user said.
Since the user entity has now been created, the intent created in Step 2 will be matched, so the /query API response will contain the name from the entity you created in Step 4.
Use the name to generate whatever response you wanted to generate.

Is it possible to update/delete User by externalId

We are trying to develop a SCIM enabled Provisioning system for provisioning data from an Enterprise Cloud Subscriber(ECS) to Salesforce(Cloud Service Provider-CSP). We are following SCIM 1.1 standard.
What are we able to do:
We are able to perform CRUD operations on User object using Salesforce auto-generated userId field
Exact Problem:
We are not able to update/delete User object using externalId provided by ECS.
Tried something as below... But it is not working, Unknown_Exception is thrown...
XXX/my.salesforce.com/services/scim/v1/Users/701984?fields=externalId
Please note that it is not possible to store Salesforce userId in ECS's database due to some compliance reasons. So we have to completely depend upon externalId only.
Possible Workaround:
Step1: Read the userId based on externalId from Salesforce
Step2: Update the User object using the salesforce UserId obtained in Step1.
But this two step process would definitely degrade the performance.
Is there any way to update/delete the User by externalId
Could you please guide us on this..
Thanks so much....
I realize this is old thread but wanted to note that you CAN update Users from REST using an external ID. The endpoint in above question is incorrect. Following is how it should be set, send as a PATCH request:
[instance]/services/data/v37.0/sobjects/user/[external_id__c]/[external id value]
Instance = your instance i.e. https://test.salesforce.com/
external_id__c = API name of your custom external Id field on User
external id value = whatever the value of the user's external Id
NOTES:
Salesforce responds with an HTTP 204 status code with No Content in the body, this isn't usual for patch requests, but it is 'success' response
The external id on user has to be a custom field, make sure it is set
as UNIQUE
Ensure the profile/permission set of the user that is making the call
has the Manage Users permission & has access to the external id field
It is pretty common pattern for other applications, too, to search first and then perform on update on the returned object. Your workaround seems fine to me. What performance problem are you concerned about? Are you concerned about Salesforce not being able to process more requests or are you concerned about the higher response time in your application because you need to make multiple requests? Have you actually measured how much an extra call costs?

Resources