问题
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