【发布时间】:2019-10-10 20:12:56
【问题描述】:
我正在尝试实现一个简单的呼叫耳语,让我们的代理知道已拨打了哪个电话号码/产品。当来电时,它会通过一个工作室流程,来电者选择一种语言。然后通过“Enqueue”小部件将呼叫路由到 taskrouter 队列。根据我在文档中阅读的内容,我需要将回调函数传递给 instruction: 'call' 参数,以便能够指定要“播放”给代理的 URL。
我目前仅限于通过 Studio 和 Functions 在 twilio 内部实现所有内容。
为什么这不起作用,我具体需要做什么?
谢谢!
赋值回调函数
exports.handler = function(context, event, callback) {
const client = context.getTwilioClient();
let eventInfo = JSON.parse(event.TaskAttributes);
// const response = new Twilio.twiml.VoiceResponse();
console.log(Object.keys(event));
console.log(JSON.parse(event.TaskAttributes));
console.log(Object.keys(JSON.parse(event.TaskAttributes)));
// console.log(JSON.parse(event.WorkerAttributes));
const worker = JSON.parse(event.WorkerAttributes);
// console.log("ReservationSid: " + event.ReservationSid);
// console.log(typeof eventInfo);
// // ATTEMPT 1
// // This works to dequeue a call to a worker, but there is no whisper functionality
// callback(null, {
// 'instruction':'dequeue',
// 'post_work_activity_sid' : 'WORKSPACEACTIVITYSID',
// 'from' : eventInfo.from
// });
// // ATTEMPT 2
// // This works to play the whisper to the agent, but the caller is never connected to the agent.
let callbackURL = 'TWILIOFUNCTIONURL';
callback(null, {
'instruction':'call',
'post_work_activity_sid' : 'WORKSPACEACTIVITYSID',
'from' : eventInfo.from,
'url' : callbackURL
});
// // ATTEMPT 3 - Building a twiml version of attempt #2
// // This doesn't work.
//
// let callbackURL = 'TWILIOFUNCTIONURL';
// let twiml = new Twilio.twiml.VoiceResponse();
// const dial = twiml.dial();
// dial.queue({
// 'instruction':'call',
// // 'post_work_activity_sid' : 'WORKSPACEACTIVITYSID',
// 'from' : eventInfo.from,
// 'accept' : true,
// 'url' : callbackURL,
// // 'reservationSid' : event.ReservationSid
// }, event.selected_language);
// console.log(dial.toString());
// console.log(twiml.toString());
// callback(null, twiml);
// // ATTEMPT 4 - Build a twiml version of attempt #1
// // This doesn't work.
//
// let twiml = new Twilio.twiml.VoiceResponse();
// twiml.dial({
// 'instruction':'dequeue',
// 'post_work_activity_sid' : 'WORKSPACEACTIVITYSID',
// 'from' : eventInfo.from
// // 'to' : 'WORKSPACEQUEUESID'
// });
// console.log(twiml.toString());
// callback(null, twiml);
};
包含队列公告内容的回调 URL。
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
// let client = context.getTwilioClient();
// console.log("BEGIN Queue Announcer - context");
// console.log(Object.keys(context));
// console.log(context);
// console.log("BEGIN Queue Announcer - event");
// console.log(Object.keys(event));
// console.log(event);
// console.log("BEGIN Queue Announcer - client");
// console.log(Object.keys(client));
// console.log(client);
// console.log("END Queue Announcer");
// Random attempt to get the call info
// console.log("BEGIN Queue Announcer - CallSid");
// console.log(event.CallSid);
// client.calls(event.CallSid)
// .fetch()
// .then(call => console.log("Call: " + call));
// console.log("END Queue Announcer - CallSid");
let client = context.getTwilioClient();
twiml.say("QUEUE NAME GOES HERE");
twiml.dial()
.queue({
// 'reservationSid' : event.ReservationSid
}, 'english');
callback(null, twiml);
};
【问题讨论】:
-
您的尝试 2 是正确的方法,所以我现在正在查看您的回调中的 TwiML。你说发生了
<Say>的耳语,但它从来没有拨过队列?您在Twilio debugger 中看到任何错误吗?另外,你们在哪里接受预订? -
我只是在“let callbackURL = 'TWILIOFUNCTIONURL';”之前添加了几行上面的行通过对 taskrouter API 的 POST 调用接受预订。好像没有什么效果,但现在我至少接受了预订。我还尝试使用 Echo Twimlet 生成 Twiml,并在队列动词中填充了 ReservationSid。 twilio.com/labs/twimlets/echo
-
你可以试试
.queue({ reservationSid: event.ReservationSid })而不添加队列名称'english',看看是否有帮助? -
做到了!稍后我将发布新代码。
标签: twilio twilio-functions twilio-studio