我正在尝试实现一个简单的呼叫耳语,让我们的代理知道已拨打了哪个电话号码/产品。当来电时,它会通过一个工作室流程,来电者选择一种语言。然后通过“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);
};