简体   繁体   English

将 twilio 语音结果发送到工作函数

[英]Send twilio speech result to working function

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()我想记录通话的前 15 秒并用 event.SpeechResult.toString() 替换“test”

  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我用 2 个函数解决了它

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.该函数记录说“HI”后的语音,然后在动作中:会转到/send_slack路径。 That will trigger the second function : make sure the path on the second function is /send_slack or matches the action of the fist.这将触发第二个函数:确保第二个函数的路径是 /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);
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM