API.AI logic flow

This discussion applies to any integration, but I'll use Messenger as an example. Also, to provide context, my backend is written in Java.

From what I've read, for custom scripting (like Link Linking) we shouldn't use API.AI directly. Instead, the "callback url" in Messenger settings ( developer.facebook.com

) should point to our own hosted application, which in turn calls api.api.ai/v1/query

. It is right?

Second, my intent in API.AI already has Use webhook

. I assume the flow of logic will be as follows:

Messenger → my app (webhook for Messenger) → api.ai → my app (webhook for api.ai)

      

Apparently this is not the case - API.AI never invokes web hockey.

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 this mean my application should call a webhook (which is the same application but a different endpoint)?

+3


source to share


5 answers


When API.AI is used as NLU (i.e. you are calling /query

) it does not call webcams. So this is either:

Messenger → my app (webhook for Messenger) → api.ai

      



or

Messengerapi.aimy app (webhook for api.ai)

      

0


source


You must give your intention to act! In your response, the action field is empty!

If you are using the integration, your flow looks like this:

fb -> api.ai -> your service -> api.ai -> fb

      

Your custom script can use it like this (no integration needed, pure text comprehension only):

fb -> your service -> api.ai -> your service -> fb

      




EDIT: Since I implemented the account binding for myself, I wrote the following middleware. https://github.com/hhucn/dbas-fb-hook/blob/master/src/dbas_fb_hook/handler.clj

Now thread: fb -> service -> api.ai -> fb

because I'm just filtering out auth related stuff and redirecting messages directly to api.ai (using facebook api.ai integration) or my other auth service.

(PS. Microservices are the best)

+1


source


Your flow logic is wrong.

In your case, Facebook will never communicate directly with your application. It will always send user input to api.ai first. api.ai will try to match all your intentions.

This is important, if api.ai manages to find the intent, it will refer to the webhook you configured. However, if api.ai cannot match any of your intents, it will trigger fallback intents that will send the response back to Facebook. In this case, your application will not be called.

My suggestion for you is, before starting testing on Facebook, use the test tool (located in the upper right corner) in api.ai to make sure your login can be filtered by the correct intent and your application can recess your login from api.ai ...

+1


source


It depends if you are using api.ai url for no code configuration.

In an agent without code, api.ai will host facebook interaction endpoints for you. [ https://bots.api.ai/facebook/ *] [1]. In an agent without code, a typical flow would be

Messenger -> api.ai server->api.ai nlp -> your webhook

      

(if intent is enabled for webhook execution) In your scenario

Messenger -> your api server ->api.ai nlp -> your webhook /end point

      

created for this intention. This is a significant drawback, as the execution of one particular intent can be split across multiple endpoints, api. In your case, you can not allow web check execution for your intent, "hey"

0


source


Ideally, FB messenger won't talk to yours webhook for messenger service

. The workflow should be FB messenger->api.ai->webhook (where your actual logic resides)

, and even if you are using my app (webhook for Messenger)

, then you don't necessarily need api.ai. This is because before taking any action you need to know what the user is saying and this can only be done with NLP! Usage my app (webhook for Messenger)

will directly replace NLP.

Secondly, we cannot see the execution in the api.ai json response. If at any given time the call to the web host fails, your default response from api.ai will be posted as a response to the user's request, and the response will be triggered when api.ai itself doesn't understand the context of what the user wants to say. Entering the default answer will also help you debug.

enter image description here

0


source







All Articles