nimbleape/asterisk-dialogflow-rtp-audioserver

Passing back Dialogflow text data (slots) to Asterisk - is this the correct way?

Opened this issue · 1 comments

I don't actually need the voice back from Asterisk, I need the intent body it returns. In my case, I need a series of questions handled exclusively by Dialogflow to resolve to a townName variable when all required slots are filled, and then drop out of stasis and let pure dialplan take over.

In case anyone else is looking to do this, this is what I have a managed to get working:

In asterisk-dialogflow-rtp-audioserver/index.js at around line 40, just after:
dialogflowConnector.on('message', async (data) => {
add
data.channelId = payload.channelId

Then over in asterisk-dialogflow-ari-bridge/index.js, just after log.info('connected to ari websocket'), I added the following - note that fields.town and the returned variable is obviously uniquely specific for my own project - modify as needed!

  const mqttTopicPrefix = 'dialogflow-asterisk'
  await mqttClient.subscribe(`${mqttTopicPrefix}/events`) 

  mqttClient.on('message', async (topic, message) => { // note change to async
    const payload = JSON.parse(message.toString())
    if (topic == `${mqttTopicPrefix}/events` && payload.intent && payload.intent.parameters.fields.town && payload.intent.parameters.fields.town.stringValue) {
      await client.channels.setChannelVar({ channelId: payload.channelId, variable: 'townName', value: payload.intent.parameters.fields.town.stringValue })
      await client.channels.continueInDialplan({ channelId: payload.channelId })
    }
  })

I've had a bit of a fight with this over the weekend, as I have never used MQTT, events or ARI before, and with my node as rusty as it is I'd be ashamed to submit it as a pull request. And perhaps my requirement for data rather than voice is unique, but if not, it would be great to have something similar as a standard part of a future version.

If I am taking completely the wrong approach with this, let me know, but it seems to work for me!

Sounds like a good addition, not sure how to make it genericly useful etc...

On a side note you can set a custom response in Dialogflow and then based on that we could then send a particular mqtt message so that you're having the ARI process look at every single message.... only look at the message when we've got a custom payload response based on Dialogflow intents

Screen Shot 2020-03-15 at 20 50 57

Closing as not really an issue - I'll make an issue for handling custom json responses