简体   繁体   English

Twilio 语音回拨

[英]Twilio voice callback

I'm having a tough time getting the Twilio Voice callback function to work properly, and would greatly appreciate any assistance in resolving this.我很难让 Twilio 语音回调 function 正常工作,非常感谢任何帮助解决这个问题。

I have a working VOIP webapp using Python, twilio package and twilio voice SDK. I have a working VOIP webapp using Python, twilio package and twilio voice SDK.

I need to get call status when a call is being made: answered, completed, ringing, in-progress and the likes.我需要在通话时获取通话状态:已answered, completed, ringing, in-progress中等。

is_record = fetch_recording_data_from_DB
handle_url = '/handle'
callback_url = '/events'
events = 'answered ringing initiated completed'

#incoming call 
dial = Dial(timeout=15, record='record-from-ringing' if is_record else 'false', action=handle_url)
        dial.client(
                identity=contact_data['company_id'] or company_id,
                status_callback_event = events,
                status_callback = callback_url,
                status_callback_method = 'POST'
            )

        return response.append(dial)

The handle_url is triggered after call ends or the 20s is exhausted with no answer to determine whether to make a call forwarding or play VM, this works fine.通话结束或20s用尽无应答后触发handle_url来判断是进行呼叫转移还是播放VM,这很好用。 No error whatsoever, calls come in - I answer and talk for a while, if I don't, it goes to voicemail, records and hangs up.没有任何错误,电话打进来 - 我接听并谈了一会儿,如果我不接听,它会转到语音信箱,录音并挂断。 I see my recording, cost, duration and other data on the calls tab on Twilio console, under Monitor.我在 Twilio 控制台的 Monitor 下的呼叫选项卡上看到了我的录音、成本、持续时间和其他数据。 All fine.一切都好。 I just can't get the status callback bit.我只是无法获得状态回调位。

#status callback function
def stat_events():
    return request.values, {'Content-Type': 'text/xml'}

..... ......

class StatEvents(Resource):
    def post(self):
        return stat_events()

Now, on the Twilio console, I can see the response and the other information (fromstate, sequencenumber,...) under Request Inspector (multiple times, as it should be) xdxxdxd.ngrok.io/events (POST, 200) regarding the call, but on my network tab (chrome) (when I make a call on the frontend) I check under the events network and see {} - empty现在,在 Twilio 控制台上,我可以在 Request Inspector 下看到响应和其他信息(fromstate、sequencenumber、...)(应该是多次) xdxxdxd.ngrok.io/events (POST, 200)关于通话,但在我的网络选项卡(chrome)上(当我在前端拨打电话时)我在事件网络下检查并看到{} - 空

I tried console.log() on the events, nothing.我在事件上尝试了 console.log(),没有。 so either I am not using this option well or there's something magical at play.所以要么我没有很好地使用这个选项,要么有一些神奇的东西在起作用。

I need the status so I can save the call log to my DB (background task) when it's completed or no-answer .我需要状态,以便在completedno-answer时将通话记录保存到我的数据库(后台任务)。

data I want but it's only showing up on Twilio console and empty on network tab (apart from saving call log, I need this data to show the status on the front-end):我想要的数据,但它只显示在 Twilio 控制台上并在网络选项卡上为空(除了保存通话记录,我需要这些数据来显示前端的状态):

    "Called": "+653xxxxxx",
    "ParentCallSid": "CAd1ed07xxxxxxxxxxxxxxx",
    "ToState": "",
    "CallerCountry": "US",
    "Direction": "outbound-dial",
    "Timestamp": "Fri, 22 Jul 2022 08:58:56 +0000",
    "CallbackSource": "call-progress-events",
    "CallerState": "MI",
    "ToZip": "",
    "SequenceNumber": "0",
    "CallSid": "CA3a39c6b1xxxxxxxxxxxxxx",
    "To": "+653xxxxxxxx",
    "CallerZip": "",
    "ToCountry": "SG",
    "CalledZip": "",
    "ApiVersion": "2010-04-01",
    "CalledCity": "",
    "CallStatus": "initiated",
    "From": "+194xxxxxxx",
    "AccountSid": "ACb9f4fe8f52xxxxxxxxxxxxx",
    "CalledCountry": "SG",
    "CallerCity": "",
    "ToCity": "",
    "FromCountry": "US",
    "Caller": "+1947xxxxxx",
    "FromCity": "",
    "CalledState": "",
    "FromZip": "",
    "FromState": "MI"
}```

```handle_url```'s function uses ```DialCallStatus``` in place of ```CallStatus```, as I read that this would be sent by Twilio request to the endpoint.

Events looks to be a list:事件看起来是一个列表:

status_callback_event=['initiated', 'answered'] status_callback_event=['已启动', '已回答']

You describe that you are receiving requests to your /events webhook, but that you're not getting events in the browser.您描述您正在接收对/events webhook 的请求,但您没有在浏览器中获取事件。

When you register to receive events via a status_callback_url then those events are only sent as webhooks to your server.当您注册通过status_callback_url接收事件时,这些事件仅作为 webhook 发送到您的服务器。

However, if you have implemented the Twilio Voice SDK in JavaScript, then you can get call events by listening to events on the Twilio.Device object and on Twilio.Call objects . However, if you have implemented the Twilio Voice SDK in JavaScript, then you can get call events by listening to events on the Twilio.Device object and on Twilio.Call objects . For example, the Twilio.Device will emit the incoming event when there is a new incoming call.例如, Twilio.Device将在有新来电时发出incoming事件。 And the Twilio.Call will emit accept events when an incoming call is accepted, and disconnect for when a call is over. Twilio.Call将在接听来电时发出accept事件,并在通话结束时disconnect

You can use these events to show call progress in your UI.您可以使用这些事件在 UI 中显示呼叫进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM