Prem Uppaluru
Prem Uppaluru

Reputation: 11

Is there a way to directly set fulfillment messages using dialogflow app instance using actions on google client library

We've a dialogflow agent that integrates with Actions on Google as well as Dialogflow Phone Gateway. We use webhook fulfillment for handling many intents and generate responses using SSML. Dialogflow module in AoG client library doesn't currently support the phone gateway integration. Is there a way to access and set the Dialogflow response object's fulfillment messages object with the right information so that the responses work with the phone gateway? The app instance for Dialogflow module (on AoG) only supports conv.ask and conv.close functions which do not permit direct manipulation the underlying JSON object. Phone gateway requires specific values in the fulfillment messages object to activate SSML text to speech.

Any pointers are appreciated.

Upvotes: 1

Views: 184

Answers (1)

Nick Felker
Nick Felker

Reputation: 11978

To manipulate the JSON body of a response, you can use conv.serialize. To replace the response, you can use conv.json with the updated payload as the parameter.

This strategy is employed in the Session Entities plugin to the library:

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)

Upvotes: 0

Related Questions