Send twilio speech result to working function

旧巷老猫 提交于 2020-01-24 21:06:10

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/46574133/send-twilio-speech-result-to-working-function

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