API.AI flow of logic - dialogflow-es

This discussion applies to any integration, but as an example I'll talk about Messenger. Also, to give context, my backend is written in Java.
From what I've read, for custom scenarios (e.g. Account Linking), we shouldn't use API.AI directly. Instead, the "Callback URL" in Messenger settings (developer.facebook.com) should point to our own hosted app, which in turn calls api.api.ai/v1/query. Is that correct?
Secondly, my Intent in API.AI already has Use webhook ticked. I assume the flow of logic would be as follows:
Messenger → my app (webhook for Messenger) → api.ai → my app (webhook for api.ai)
Apparently it's not the case—API.AI never calls the webhook.
This is the JSON I sent to API.AI:
{"query":"hey","originalRequest":{"source":"facebook","data":{"object":"page","entry":[{"id":"xxx","time":yyy,"messaging":[{"sender":{"id":"zzz"},"recipient":{"id":"xxx"},"timestamp":yyy,"message":{"mid":"aaa","seq":bbb,"text":"hey"}}]}]}},"v":"20170704","sessionId":"1","lang":"en"}
And this is the response from API.AI:
{
"id": "xxx",
"timestamp": "yyy",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "hey",
"speech": "",
"action": "",
"parameters": {
"greeting": "hey"
},
"metadata": {
"inputContexts": [],
"outputContexts": [],
"intentName": "greeting",
"intentId": "zzz",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"contexts": []
},
"score": 1.0
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "1"
}
Does it mean that my app should call the webhook (which is the same app but different endpoint) itself?

Your logic of flow is not correct.
In your case, Facebook will never talk to your app directly. It will always sends the user input to api.ai first. api.ai will then try to find a match from all intents you have created.
This is important, if api.ai manages to find an intent, it will invoke the webhook you have configured. However, if api.ai fail to find a match from any of your intents, it invokes the fallback intents which will post the response back to Facebook. In this case, your app will not be invoked.
My suggestion to you is before start testing on Facebook, use the test tool (located in the top right) in api.ai to make sure your input can be filter by the correct intents and your app is able to recessive your input from api.ai.

You have to give your intent an action! In your response the action field is empty!
If you are using the integrations your flow is like this:
fb -> api.ai -> your service -> api.ai -> fb
Your custom scenario may use it like this (no use of the integrations, just pure text understanding):
fb -> your service -> api.ai -> your service -> fb
EDIT:
Since I've implemented account linking for myself, i wrote following middleware.
https://github.com/hhucn/dbas-fb-hook/blob/master/src/dbas_fb_hook/handler.clj
The flow is now: fb -> service -> api.ai -> fb because I just filter out the auth related stuff and forward the messages directly to api.ai (using the api.ai facebook integration) or my other auth service.
(PS. Microservices are the best)

When API.AI is used as NLU (that is, you call /query), it doesn't call the webhooks. So, it's either:
Messenger → my app (webhook for Messenger) → api.ai
or:
Messenger → api.ai → my app (webhook for api.ai)

It depends if you use api.ai url for code-less agent configuration.
In code-less agent,api.ai will host the facebook interaction end points for you.
[https://bots.api.ai/facebook/*][1].
In code-less agent , typical flow will be
Messenger -> api.ai server->api.ai nlp -> your webhook
(if intent is enabled for webhook fulfillment)
In your scenario
Messenger -> your api server ->api.ai nlp -> your webhook /end point
created for that intent.This is a significant disadvantage as Fulfillment of 1 specific intent might be split across multiple end points, api's.In your case, you might not have enable webhook fulfillment on your intent ,'Hey'

Ideally, FB messenger will not talk to your webhook for messenger service. The workflow should be FB messenger->api.ai->webhook (where your actual logic resides) & even if in case you use, my app (webhook for Messenger) then you shouldn't be needing api.ai in the first place. It is because before taking any action, you need to know what user is saying & that can be done by NLP only! Using my app (webhook for Messenger) will replace NLP directly.
Second thing, We can not see fulfillment in api.ai json response. If at any point in time webhook call fails, your default response from api.ai will be posted as a reply to user's query & fallback will be called when api.ai itself does not understand the context of what user wants to say. Entering default response will help you in debugging as well.

Related

Not able to register Event Grid subscription with webhook delivery properties in Azure

I have a REST service hosted in Azure Web app. I registered a webhook on Azure Event Grid by pointing to REST service endpoint. I have followed below link and added endpoint validation with Event Grid events in REST service. I am able to register webhook successfully.
https://learn.microsoft.com/en-us/azure/event-grid/webhook-event-delivery
But I am facing issue(Not able subscribe webhook) if I configure any delivery properties in Event Grid like Authorization or content-type headers as shown below. Please refer below attachment for error details(Shown right side of pic) as well.
Event Grid subscription with webhook delivery properties failure
Could someone please help me on this.
Thanks in advance,
Ashok
First, we need to check how event delivery is authenticated with event handler.
Also, make sure that validation call is successful with event grid, Event grid supports two ways of validations.
Synchronous Validation
Asynchronous Validation
Subscription validation event example as below:
[
{
"id": "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66",
"topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"subject": "",
"data": {
"validationCode": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6",
"validationUrl": "https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/myeventsub/validate?id=0000000000-0000-0000-0000-00000000000000&t=2021-09-01T20:30:54.4538837Z&apiVersion=2018-05-01-preview&token=1A1A1A1A"
},
"eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
"eventTime": "2021-00-01T22:12:19.4556811Z",
"metadataVersion": "1",
"dataVersion": "1"
}
]
Refer to Webhook event delivery from MS Docs
Also check this for troubleshooting validation issues

No DesignTimeAgent found when testing with detectIntent API using prebuilt agent template and "try this API" button

Always return No DesignTimeAgent found (even using the prebuilt agent template) when testing with detectIntent API in DialogFlow using "Try this API". The API I tried is "projects.agent.sessions.detectIntent".
The session parameter is "projects/dialogflow-293106/agent/sessions/123123123"
and request body is:
{ "queryInput": {
"text": {
"text": "hi",
"languageCode": "en"
} } }
The following error returned:
{ "error": {
"code": 404,
"message": "com.google.apps.framework.request.NotFoundException: No DesignTimeAgent found for project 'dialogflow-293106'.",
"status": "NOT_FOUND" } }
screen cap of "Try this API" 1
screen cap of "Try this API" 2
There are multiple reasons why this error may occur for Dialogflow ES Edition. One is that for agents located in regions which are outside the US. At this point, the API Explorer for projects.agent.sessions.detectIntent doesn’t support other regions outside the US. Since to make an API request for other regions, you must add the location parameters to define the region. You may consider testing the detectIntent API method using other methods as described here.
This error may also occur if the project ID defined in the request is incorrect or doesn’t have an agent linked to it. To verify the project ID of the agent, you may check this information in the agent's general settings.
In addition to that, currently, the API Explorer for Dialogflow CX APIs is not available. Dialogflow ES and Dialogflow CX have different sets of API methods. If you are trying to call a CX agent using the detectIntent method for an ES agent, it will also return an error message. If you want to test your Dialogflow CX agent through REST API, you may check this documentation for an overview of API methods available.
Here’s the detectIntent request for Dialogflow CX agents. You can interact with the APIs as described in the link provided.

Incoming Slack Webhook URL Components

Incoming Slack Webhook URL looks like https://hooks.slack.com/services/aaaaa/bbbbb/ccccc -- What is aaaaa, bbbbb, ccccc.. Can you please let us know is it possible to find what is the Slack Channel name and workspace name based on this webhook
Based on the incoming webhook alone (as a string) it's not possible, apart from the team_id mentioned in the comment above.
From my experience with only incoming-webhooks enabled and publicly distributed apps that information is available only in response after user installs the app with the standard OAuth process. Keep in mind that reponse will change depending of the scope of your application but if you ask for incoming-webhook you will get channel together with url which is incoming-webhook url. You will also get team_name and team_id which is Workspace info. You can find detailed explanation at https://api.slack.com/messaging/webhooks#incoming_webhooks_programmatic and https://api.slack.com/authentication/oauth-v2.
And here is an example of OAuth response json.
{
"ok": true,
"access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
"scope": "identify,bot,commands,incoming-webhook,chat:write:bot",
"user_id": "XXXXXXXX",
"team_name": "Your Workspace Name",
"team_id": "XXXXXXXX",
"incoming_webhook": {
"channel": "#channel-it-will-post-to",
"channel_id": "C05002EAE",
"configuration_url": "https://workspacename.slack.com/services/BXXXXX",
"url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX"
}
So in the nutshell, as far as I know, there is no way to get information from webhook alone, but one other option, which is not directly the answer to the question is to expand your application and include web api permissions and then there is nothing stopping you to request that information independently from incoming-webhook directly from the workspace.

DialogFlow -Web Client - using Sign-in Helper?

I am using the Actions on Google Signin helper to leverage Account Linking for Google Sign-in. The setup is using JSON and invoking it within the Actions on Google simulator or Google Assistant invokes the required helper. Is there a way to use the signin helper for the web client or is there a preferred way to do Account Linking for Google Sign-in for web client?
The JSON for siginin I am using is
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"fulfillmentText": "Hello There!",
"items": [
{
"simpleResponse": {
"textToSpeech": "Please sign in to access!"
}
}
],
"source": "askaibot.com"
},
"systemIntent": {
"data": {
"##type": "type.googleapis.com/google.actions.v2.SignInValueSpec"
},
"intent": "actions.intent.SIGN_IN"
}
}
}
}
I am wondering if there is any means to use Google Signin for the web client when using webhook and JSON setup. Thanks in advance!
UPDATE: Thanks Prisoner, for responding! Yes, I was referring to the webdemo available as a part of integrations or the assistant that runs on the web page noted for e.g. https://bot.dialogflow.com/60710e58-7590-423d-a533-79efcec0f2aa.
Thanks.
The "Web Demo" integration for Dialogflow isn't the Assistant. Although it lets you communicate with an agent built with Dialogflow, it doesn't have all the features that the Assistant does, and does not use the Actions on Google platform and features.
In particular, this means that it does not allow for Google Sign-In.
However...
You can use Google Sign-In for websites to have users log into a web page of yours. You can then use the Dialogflow Detect Intent API to build a chat client on your web page that will send user messages to a server that will send them to Dialogflow and include the user authentication with those messages. Your webhook will need to make sure it distinguishes between a message from the Assistant vs a message from your web page, get the auth info differently, and respond accordingly. All of this, however, is not as simple as what is offered through Actions on Google.

Azure Notification Hub like simple sender

I have some question about Azure notification hub.
It is possible to send push message to gcm or apns without registration devices? I would like only to pass e.g. gcm model like:
{
"to": "registraionId",
"data": {
"title": "Some title",
"message": "Some message"
}
}
I saw that exists defined REST https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx but for me it not working, I suppose that flow should look like [make installation] -> [make registration] -> [send message] is it correct? I also tried to send message by visual studio and azure portal.
Is it possible to send messages without registration etc. ?
I will be very gratefull for any examples :)
I solved my problem, of course exists Rest api https://msdn.microsoft.com/en-us/library/azure/mt608572.aspx which is used to sending direct messages to devices without registrations.

Resources