0

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

1 回答 1

1

这就是我所做的。这包含在一个实际上是“分配回调 URL”的函数中。

脚步:

  1. 使用 'echo' twiml 生成 twiml。修改提供的 URL 以在适当的地方包含“event.RegistrationSid”。
  2. 通过 POST 请求接受注册。
  3. 执行回调,包括“指令:调用”参数。

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
});
};
于 2019-10-17T15:46:33.947 回答