发送twilio语音结果到工作函数
问题描述:
您好我有以下工作功能。我无法正确使用或功能。这是代码的工作移植。 我曾尝试:发送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()代替 “测试”
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);
});
};
答
我解决了它的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);
};
此函数在说出“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);
});
};