我正在尝试实现一个简单的电话窃窃私语,以使我们的代理知道拨打了哪个电话号码/产品。来电时,会经过录音室流程,在此流程中,呼叫者选择一种语言。然后,通过“入队”小部件将呼叫路由到任务路由器队列。根据我在文档中阅读的内容,我需要向回调函数传递一个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);
};
答案 0 :(得分:0)
这就是我所做的工作。它包含在一个功能中,该功能实际上是“分配回调URL”。
步骤:
exports.handler = function(context, event, callback) {
const client = context.getTwilioClient();
let eventInfo = JSON.parse(event.TaskAttributes);
// Generate the callback url
let callbackURL = `http://twimlets.com/echo?Twiml=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3CResponse%3E%0A%3CSay%3ECALLWHISPERGOESHERE%3C%2FSay%3E%0A%3CDial%3E%0A%3CQueue%20reservationSid%3D%22${event.ReservationSid}%22%3E%3C%2FQueue%3E%0A%3C%2FDial%3E%0A%3C%2FResponse%3E&`;
// Generate POST request to accept the reservation
const rp = require("request-promise");
const postURI = `https://taskrouter.twilio.com/v1/Workspaces/${event.WorkspaceSid}/Tasks/${event.TaskSid}/Reservations/${event.ReservationSid}`;
const postForm = {
ReservationStatus: "accepted"
};
const postAuth = {
user: context.ACCOUNT_SID,
pass: context.AUTH_TOKEN
};
const options = {
method: "POST",
uri: postURI,
auth: postAuth,
form: postForm
};
rp(options)
.then(body => {
console.log(body);
callback(null, null);
})
.catch(err => {
console.log(err);
callback(null, err);
});
// Call the agent
callback(null, {
instruction: "call",
post_work_activity_sid: "POSTWORKACTIVITYSID",
from: eventInfo.from,
url: callbackURL
});
};