【问题标题】:Answer a phone call on the browser with Twilio使用 Twilio 在浏览器上接听电话
【发布时间】:2020-11-27 17:25:58
【问题描述】:

我希望通过浏览器上的工作人员接听电话。 在我的工人身上,我有以下内容

{"contact_uri":"client:Peter"}

在我的来电方法上,一个任务成功创建并进入队列

twiml = Twilio::TwiML::VoiceResponse.new do |response|
  response.say(message: message)
  response.enqueue workflowSid: 'sid'
end
render xml: twiml.to_xml

然后在我的前端代码中,触发了一个 reservation.created 事件。

worker = new Twilio.TaskRouter.Worker(data.token)
worker.on 'reservation.created', (reservation) ->
  reservation.dequeue()

但是 reservation.dequeue() 没有初始化对我的浏览器的调用,我仍然收到 Twilio 默认等待声音并且没有其他响应。

【问题讨论】:

  • worker 是 WebWorker,对吗?您可以尝试使用postMessagereservation.dequeue() 的结果发送回主线程。

标签: javascript twilio


【解决方案1】:

据我所知,您的代码很好,但这里的主要问题是您没有定义 Twilio 客户端。如果您要将这些调用发送到浏览器而不是设置 Twilio 客户端,则还必须设置设备。你可以在Twilio Client documentation找到更多信息。

生成 Twilio 客户端令牌后,您可以连接到 Twilio,即

device = new Twilio.Device(data.token, {
                closeProtection: true,
               debug: true,
                // Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
                // providing better audio quality in restrained network conditions. Opus will be default in 2.0.
                codecPreferences: ["opus", "pcmu"],
                // Use fake DTMF tones client-side. Real tones are still sent to the other end of the call,
                // but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone
                // a second time and sending the tone twice. This will be default in 2.0.
                fakeLocalDTMF: true,
                // Use `enableRingingState` to enable the device to emit the `ringing`
                // state. The TwiML backend also needs to have the attribute
                // `answerOnBridge` also set to true in the `Dial` verb. This option
                // changes the behavior of the SDK to consider a call `ringing` starting
                // from the connection to the TwiML backend to when the recipient of
                // the `Dial` verb answers.
                enableRingingState: true
            });
            // Incoming call to.
             device.on('incoming', function (conn) {
             //This will automatically accept the call, bind it with a button to enhance it
                        conn.accept();         
                });

如需了解更多信息,请转至Twilio Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多