Twilio IBM Watson语音到文本插件回调函数未触发

时间:2018-11-02 11:55:58

标签: node.js twilio ibm-cloud speech-recognition ibm-watson

我的目标是使用Twilio平台上可用的IBM Watson语音转文本插件(Twilio插件功能)进行抄写(呼叫者的输入-IVR对话)。

已安装IBM watson语音转文本插件。

问题:未触发在回调URL上定义的回调函数。

我已遵循此link

中提到的准则

我已将我的可编程语音应用程序配置为Web挂钩功能。 (使用NGROK)和“回调”功能也被配置为Web挂钩。

回调URL配置 enter image description here

我可以看到请求到达/ voice和/ recording,但是请求没有到达/ callback。源代码如下

    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);

我缺少什么配置?

0 个答案:

没有答案