gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:06:08 25 4
gpt4 key购买 nike

您好,我有以下工作功能。我在正确使用 或 函数时遇到问题。这是代码的工作移植。我试过:

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

代码:

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

我想记录通话的前 15 秒并将“test”替换为 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”后的语音然后在 Action 中:它将转到/send_slack 路径。这将触发第二个功能:确保第二个函数的路径是/send_slack 或与拳头的 Action 相匹配。

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

关于javascript - 将 twilio 语音结果发送到工作函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46574133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com