Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

How to bypass middleware and only get JSON response #418

Open
JpEncausse opened this issue Mar 3, 2021 · 1 comment
Open

How to bypass middleware and only get JSON response #418

JpEncausse opened this issue Mar 3, 2021 · 1 comment

Comments

@JpEncausse
Copy link

JpEncausse commented Mar 3, 2021

The documentation describe a middleware that will register functions on a given intent.

I'm using Node-RED with a fullfilment end-point. I can't and don't want to build a middleware because I want to manage the response flow. I only need a wrapper on the API to retrieve a valid JSON.

Is there a way to use the conv object in order to retrieve a valid JSON response ?
Something like in the playground

@Fleker
Copy link
Member

Fleker commented Mar 9, 2021

Do you want to use the library then, or would you just prefer sending JSON back directly?

If you want the library, you can use something similar to the session-entities-plugin and use the serialize method:

const responseBody = this.conv.serialize() as ResponseBody
const convBody = this.conv.body as GoogleCloudDialogflowV2WebhookRequest
responseBody.sessionEntityTypes = this.entities.map(entity => {
    entity.name = `${convBody.session}/entityTypes/${entity.name}`
    return entity
})
this.conv.json(responseBody)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants