我正在使用 Twilio 函数、Studio 和 TaskRouter。
场景:caller_1
来电。在任务队列中排队 > 分配回调运行并发出一个instruction: "call"
> 设置的电话号码to
被拨打。当一个新的呼叫进来时,它被排入队列。
分配回调.js:
exports.handler = async function (context, event, callback) {
const axios = require("axios");
const { Called, ReservationSid, TaskSid } = event;
try {
const { workerPhone } = await axios.get(....);
callback(null, {
instruction: "call",
to: workerPhone,
from: Called,
url: `https://example.com/agentAnswer?reservationSid=${ReservationSid}`,
status_callback_url: `https://example.com/callStatusCallback?TaskSid=${TaskSid}`,
});
} catch (error) {
callback(error);
}
};
我正在手动设置工作人员的可用性,url
并status_callback_url
防止在通话时接听新电话。
网址:agentAnswer.js
exports.handler = function (context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
const { reservationSid } = event;
const dial = twiml.dial();
dial.queue({
url: "connectingToAgent", // this is where I set the worker activity to `false` and say a message before connecting to worker
reservationSid,
postWorkActivitySid: context.AVAILABLE,
});
callback(null, twiml);
};
连接代理.js
exports.handler = async function (context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
try {
const twilioClient = context.getTwilioClient();
// set operator activity to "in call" -- this will prevent
// the worker from accepting incoming calls
const { activityName } = await twilioClient.taskrouter
.workspaces(context.WORKSPACE_SID)
.workers(context.WORKER_SID)
.update({ activitySid: context.IN_CALL_ACTIVITY });
console.log("worker activity: ", activityName);
} catch (error) {
callback(error);
}
twiml.say("Please hold, while we connect you to the next available operator.")
callback(null, twiml);
status_callback_url: callStatusCallback.js
exports.handler = async function (context, event, callback) {
const twilioClient = context.getTwilioClient();
const { TaskSid } = event;
try {
await twilioClient.taskrouter
.workspaces(context.WORKSPACE_SID)
.tasks(TaskSid)
.update({ assignmentStatus: "completed", reason: "call completed" });
// set worker to available
await twilioClient.taskrouter
.workspaces(context.WORKSPACE_SID)
.workers(context.WORKER_SID)
.update({ activitySid: context.AVAILABLE });
callback(null, "");
} catch (error) {
callback(error);
}
};
这是我收到错误的地方:队列中有四个呼叫者。每当已连接到工作人员的第一个呼叫者挂断时,队列中的所有呼叫者都会断开连接(直接转到语音信箱),最后一个呼叫者除外。最后一个呼叫者成功地拨打了出站电话,而不是排队的第二个呼叫者。
我已经尝试instruction: "redirect"
并使用<Dial>
inurl
连接到代理。并监听statusCallbackEvent: "initiated completed"
将工作人员活动分别设置为“通话中”和“可用”。使用这种方法,我也得到了相同的结果。
我会在这几个星期。谁能指出我在这里做错了什么?提前致谢!