-->

Twilio IBM Watson Speech To Text Addon Callback fu

2019-07-24 02:27发布

问题:

My objective is to get transcribe (Caller's input - IVR Conversation) using IBM Watson Speech to Text Addon which is available on Twilio platform (Twilio Add-ons feature).

IBM watson speech to text add-on is installed.

Problem: Callback function which defined on Callback URL is not getting triggered.

I have followed the guidelines mentioned on this link

I have configured my Programmable voice application as web hook function. (Using NGROK) and Callback function is also configured as a web hook.

Callback URL Configuration

I can see request landing to /voice and /recording, but the requesting is not landing to /callback. Source code is below

    const express = require('express');
const bodyParser = require('body-parser')
const axios = require('axios')
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const app = express();
app.use(bodyParser.urlencoded({extended: false}))

app.post('/voice', (req, res) => {
  const twiml = new VoiceResponse()

  twiml.say('Hi! I want to know what do you think about coding. One')
  //twiml.record({maxLength: '10', action: '/callback'})
  twiml.record({maxLength: '10', action: '/recording',playBeep:false})
  twiml.hangup()

  res.send(twiml.toString())
});

app.post('/recording', (req, res) => {
  const twiml = new VoiceResponse()
  const recordingUrl = req.body.RecordingUrl

  twiml.say('Thanks for howling... take a listen to what you howled.')
  twiml.play(recordingUrl)
  twiml.say('Goodbye.')

  res.send(twiml.toString())
})

app.post('/callback', (req, res) => {
  const addOns = JSON.parse(req.body.AddOns)

  if (!('ibm_watson_speechtotext' in addOns.results)) {
    return 'Add Watson Speech to Text add-on in your Twilio console'
  }

  const payloadUrl = addOns.results.ibm_watson_speechtotext.payload[0].url
  const accountSID = process.env.TWILIO_ACCOUNT_SID
  const authToken = process.env.TWILIO_AUTH_TOKEN

  axios.get(payloadUrl, {auth: {username: accountSID, password: authToken}})
    .then(response => {
      const results = response.data.results[0].results
      const transcripts = results.map(item => item.alternatives[0].transcript)
      return transcripts
    })
     .then(transcripts => res.send(transcripts.join(' ')))
})

app.listen(1553);

What configuration am i missing ?