Bill Software Engineer
Bill Software Engineer

Reputation: 7782

In Google DialogFlow CX, is it possible to call on an external API, then get the callback response after 15min?

I am using an exteranl API that do some work for 15min, when it finish it will call any URL you define in your initial request to send the results to.

Is it possible for dialogFlow to accept this result in 15min? Is there like a built-in async response handler in DialogFlow?

Upvotes: 0

Views: 2312

Answers (2)

Mark Jonathan
Mark Jonathan

Reputation: 224

If you are calling external APIs via webhook, it would be subject to the maximum webhook timeout limit of 30 seconds. After the response timeout is exceeded, Dialogflow invokes a webhook error or timeout built-in event and continues processing as usual. Therefore, Dialogflow would no longer accept webhook responses more than the set timeout limit.

Note that conversational interfaces are meant to be designed as a continuous message exchange between the end user and the app/bot. If your web service requires more time for executing operations in the background and this cannot be optimized, consider redesigning the conversation flow in such a way that end users don't wait for the app/bot to reply for more than the set webhook timeout limit.

If you have your own custom application (integrated using APIs or Client Libraries), you can instead call/invoke the function that needs 15 minutes of work (let’s call this function_1) from your custom application.

Here’s a basic setup:

  1. User enters a query from the interface of your custom application.

  2. Your custom application sends the user query with the Detect Intent request to the Dialogflow agent (using APIs or Client Libraries).

  3. After your custom application receives a Detect Intent response from the agent, you can create code to get the intent name or event name from the detectIntentResponse.queryResult.match.intent.displayName or match.event response json respectively and then call/invoke function_1 based on the intent or event matched.

  4. Once function_1 is finished processing, you can either send a direct response to the user in your custom application’s interface or send a Detect Intent request to your agent so it matches an Intent and sends the intent response back to your custom application.

Upvotes: 1

fcagnola
fcagnola

Reputation: 670

No, it won't be possible as you describe it. The only way to call external services is through webhooks, but these are thought as calls that return a very specific object which Dialogflow then returns as an answer to the user directly, so they are inherently synchronous.

What you could do instead is think of a workaround. I don't know the specific of what service you're calling, but you could set up a small server to handle the webhook response from dialogflow which doesn't do anything except trigger the call to the external api, and when you get the answer you could process it (put the relevant content inside a "fulfilment" object as per Dialogflow specification) and trigger an event in your agent through the dialogflow API.

so the final process could look something like this.

  1. user asks for e.g. "pizza": the right intent is triggered and the route for that intent calls a webhook server
  2. your webhook server receives the call from dialogflow and calls the external api asking for the list of all pizzas ever created. it returns an empty fulfilment to the server
  3. when the webhook server receives the response after 15 mins it triggers an event in the agent (look into the dialogflow api for your programming language of choice: python, node, java) and injects some parameters in the request, which you can then use to form a sentence in the agent

when I was just starting out I found this very useful to get a grasp of what the platform expects you to do in terms of interacting with external services, take a look at the graph especially which I think makes it clearer

Upvotes: 1

Related Questions