4

I'm using the Dialogflow node.js webhook component with express. Here's the boilerplate.

import { dialogflow } from 'actions-on-google';
import express from 'express';
import bodyParser from 'body-parser';

// app init, handle intents
const app = dialogflow()
app.intent('Default Welcome Intent', conv => {
  conv.ask('Welcome to the awesome reminder action!');
});
app.intent('Some Custom Intent', conv => {
  conv.ask('Say something');
});

// bind to express
express().use(bodyParser.json(), app).listen(5000)

Now, I can add a middleware to the dialogflow app (with app.middleware(function)) that runs before intents are handled. Does anyone know how to add a middleware that runs after intents are handled?

Avision
  • 3,613
  • 1
  • 19
  • 24

1 Answers1

2

Maybe these solution1 solution2 solution3 may help you. Otherwise, you may try and call the after function after calling conv.ask or conv.close like

app.intent('Default Welcome Intent', conv => {
  conv.ask('Welcome to the awesome reminder action!');
  // call after function here
});
Abhinav Tyagi
  • 5,158
  • 3
  • 30
  • 60
  • Thanks for the answer. Naturally I can add it at the end of the intent handling but my question is about having more than one intent. I've edited the code in my question to reflect that – Avision Aug 16 '18 at 08:40
  • Did you check the link I have put? Did it help? – Abhinav Tyagi Aug 16 '18 at 08:41
  • I checked it but I don't know how to translate it to my use case. I think the dialogflow object handles the requests. – Avision Aug 16 '18 at 08:47
  • 1
    If you want to add something with Dialogflow after the call, it may not work. But something that you want to do like logging etc may work with express middlewares. – Abhinav Tyagi Aug 16 '18 at 09:13