We are sending a HTTP Header with a JWT Token, we have configured this header in dialogflow console.
We want to verify this token in a previous step to send the request to a specific intent, for example welcome_intent.
We are using "middleware" as this previous step, and the verification is correct and it's applied to every communication. And we want to know, how
In case the JWT is wrong, we want to return an error and not continue with the associated intent, for example: welcome_intent.
We have tried to end the flow with "conv.close" in "middleware", but we have seen that the flow continues and it goes to the intent associated with the query.
How can we get out of the flow and return an error in the middleware function?
const {
dialogflow
} = require('actions-on-google');
const fulfillment = dialogflow({
clientId: "clientIdDialogflow",
debug: true
});
const jwt = require('jsonwebtoken');
fulfillment.middleware(async (conv) => {
let tokenIncorrect = await utils.verifyJWT(conv);
if (tokenIncorrect) {
conv.close("Lo siento pero no puedes continuar con la conversación.");
}
});
// Intents functions
fulfillment.intent("welcome_intent", .....);