Kristel Serra
Kristel Serra

Reputation: 1

Dialogflow fulfillment to trigger another intent

Hello developers out there. I'm designing an agent in Dialogflow and I want to trigger another intent from a follow-up intent using Events and Fulfillment. I'm not a developer so I've been using the internet to seek help.

I found this video on YouTube which is similar to the use case I'm working on and it was using this code in Mockable.

{
    "followupEventInput": {
    "name": "eventname"
 }
}

I tried to use this in the inline editor for the fulfillment section but I've been getting errors. I could use your expertise to help me. I'm keen to learn a bit of this so I wanted to make it work myself rather than asking someone to code for me. I would appreciate any knowledge that you can extend to me, sensei! :)

Thanks, Kristel

Upvotes: 0

Views: 1615

Answers (1)

Dhruv Rajkotia
Dhruv Rajkotia

Reputation: 380

Let's take an example if you have a 2 intents like intent-1 and intent-2. (NOTE: please "Enabled the Webhook" for those intents in intent fulfillment section)

intent-1 phrases:

  • Hello
  • Hi
  • How are you

intent-1 response:

  • Hey there, Nice to meet you.

intent-1 output context:

  • hello // it's just to see the result

intent-2 event

  • test

intent-2 response

  • This is a test response.

now create an API in Node/Python or any language in which you are comfortable. I have created API in the Node and configured in the webhook.

Here is the sample code:

const express = require('express');
const fetch = require('node-fetch');

const app = express()
const port = process.env.PORT || 3000;
app.listen(port, () => {
   console.log(`Starting server at ${port}`);
});

app.use(express.json())

app.post('/webhook/v2', async (req, res) => {
console.log("Dialogflow: Received a POST request");
if (!req.body) return res.sendStatus(400)
let responseObj = {
   "followupEventInput": {
    "name": "test",
   },
 "source": ""
 }
 return res.json(responseObj)
})

So here I'm returning the {"followupEventInput": {"name": "test",} for all the webhook call(As it's for the test purpose. you can use your own business logic here and based on that you can add followupEventInput in response). So after configuring webhook when I try to enter the Hi/Hello (which is the training phrases of the intent-1) in Dialogflow simulator So Dialogflow will detect the intent-1 and call the webhook. for webhook response we have set the followupEventInput, So internally It'll call the intent-2 and display the intent-2 response.

For testing you can check the output context is set for the intent-1 in the simulator. (hello)

Here I have attached the result image which may help you.

enter image description here

Let me know if you still have any doubts.

Upvotes: 2

Related Questions