发送Twilio语音结果到工作功能 [英] Send twilio speech result to working function

查看:198
本文介绍了发送Twilio语音结果到工作功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有以下的工作功能。我无法正确使用或功能。这是代码的工作移植。
我试过了:

  let twiml = new Twilio.twiml.VoiceResponse(); 
twiml.say({voice:'man',language:'en-gb'},'Hello I.T.');

CODE:

  const got = require('got'); 
exports.handler = function(context,event,callback){

我想记录调用的前15秒,并用event.SpeechResult.toString()替换test。
$ b $ pre $ const requestBody = {
text:test
};
got.post('https://hooks.slack.com/services/T08Q2345/B7D6H7U6A/THAVF2343234oSj5x',{
headers:{
'Content-Type':'application / json '
},
body:JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse ();
callback(null,twiml);
})
.catch(err => {
callback(err);
});
};


解决方案

b
$ b pre $ exports.handler = function(context,event,callback){
const twiml = new Twilio.twiml.VoiceResponse();

twiml.gather({
input:'speech',
timeout:3,
action:'/ send_slack'
})。say 'H-1');
callback(null,twiml);
};

这个函数在说出HI后记录讲话
然后在动作中:转到/ send_slack路径。
这将触发第二个函数:
确保第二个函数的路径是/ send_slack或匹配拳头的动作。

  const got = require('got'); 
exports.handler = function(context,event,callback){
const twiml = new Twilio.twiml.VoiceResponse();
const command = event.SpeechResult.toLowerCase();

const requestBody = {
text:command.toString()
};
got.post('https://hooks.slack.com/services/T095/B7DA/THAgetyourownSj5x',{
headers:{
'Content-Type':'application / json '
},
body:JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse ();
callback(null,twiml);
})
.catch(err => {
callback(err);
});
};


Hello I have the following working function. I am having trouble using the or functions properly. Here is the working porting of the code. I have tried:

  let twiml = new Twilio.twiml.VoiceResponse();
  twiml.say({ voice: 'man', language: 'en-gb' }, 'Hello I.T.');

CODE:

const got = require('got');
exports.handler = function(context, event, callback) {

I want to record the first 15 seconds of the call and replace "test" with event.SpeechResult.toString()

  const requestBody = {
    text: "test"
  };
  got.post('https://hooks.slack.com/services/T08Q2345/B7D6H7U6A/THAVF2343234oSj5x', {
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(requestBody)
  })
  .then(response => {
    let twiml = new Twilio.twiml.MessagingResponse();
    callback(null, twiml);
  })
  .catch(err => {
    callback(err);
  });
};

解决方案

I solved it with 2 functions

exports.handler = function(context, event, callback) {
  const twiml = new Twilio.twiml.VoiceResponse();

  twiml.gather({
    input: 'speech',
    timeout: 3,
    action: '/send_slack'
  }).say('HI');
  callback(null, twiml);
};

This function records the speech after saying "HI" Then in the action: it will go to the /send_slack path. That will trigger the second function : make sure the path on the second function is /send_slack or matches the action of the fist.

const got = require('got');
exports.handler = function(context, event, callback) { 
  const twiml = new Twilio.twiml.VoiceResponse();
  const command = event.SpeechResult.toLowerCase();

  const requestBody = {
    text: command.toString()
  };
  got.post('https://hooks.slack.com/services/T095/B7DA/THAgetyourownSj5x', {
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(requestBody)
  })
  .then(response => {
    let twiml = new Twilio.twiml.MessagingResponse();
    callback(null, twiml);
  })
  .catch(err => {
    callback(err);
  });
};

这篇关于发送Twilio语音结果到工作功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆