Twilio IBM Watson Speech To Text Addon Callback function not getting triggered

99封情书 提交于 2019-12-24 08:26:38

问题


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 ?

来源:https://stackoverflow.com/questions/53118160/twilio-ibm-watson-speech-to-text-addon-callback-function-not-getting-triggered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!