使用 twilio 拨出电话按顺序拨打多个号码 [英] Call multiple numbers sequentially using twilio outgoing call

查看:35
本文介绍了使用 twilio 拨出电话按顺序拨打多个号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 twilio api 从列表中拨出电话

So I'm using the twilio api to do outgoing calls from a list

NUMS = ['xxx-xxx-xxxx', 'jjj-jjj-jjjj']
for num in NUMS:
    c = make_call(num, "Hi-how-are-you!!!")

并且 make_call 函数包含 twillio 代码

and the make_call function contains the twillio code

def make_call(to_number, mesg):
    global FROM
    call_status = ['COMPLETED', 'FAILED', 'BUSY', 'NO_ANSWER']

    # put your own credentials here 
    ACCOUNT_SID = "--------------------" 
    AUTH_TOKEN = "--------------------" 

    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) 

    call = client.calls.create(
       to=to_number, 
       from_=FROM, 
       url=URL+"/voice/reply/"+mesg,  
       method="POST",  
       status_callback=URL+"/voice/status",
       status_callback_method="POST",
       timeout=10
    ) 
    return call

不知道我做错了什么,但它同时排队,然后同时呼叫他们两个.如果我接听电话,另一个结束.我想按顺序调用,并且放置 time.sleep() 也不起作用.

No idea what i'm doing wrong, but it queues BOTH and then CALLS THEM BOTH AT THE SAME TIME. If I pick up on call, the other one ends. I want to call sequentially, and putting a time.sleep() doesn't work either.

感谢帮助.

推荐答案

Twilio 布道者在这里.

Twilio evangelist here.

对 client.calls.create 的每次调用都是对 Twilios REST API 的简单 HTTP 请求,它告诉它开始一个出站电话呼叫.调用是异步进行的,因此如果您愿意,可以调用该函数 10 次以同时启动 10 个单独的电话呼叫.

Each call to client.calls.create is simple an HTTP request to Twilios REST API that tells it to start an outbound phone call. Calls are made asynchronously, so if you wanted to you could call that function 10 times to simultaneously start ten separate phone calls.

如果您想以串行方式进行调用,而不是使用循环来启动调用,我建议您启动第一个调用,然后使用 StatusCallback 路由处理程序让 Twilio 告诉您第一个调用何时完成(以及为什么),然后在该处理程序中,开始下一个调用.

If you want to make calls in a serial fashion, rather than using a loop to start the calls I would suggest starting the first call and then using the StatusCallback route handler to have Twilio tell you when that first call has completed (and why) and then in that handler, start the next call.

每次活动呼叫完成时,Twilio 都会请求 StatusCallback 路由,允许您开始序列中的下一个呼叫.

Each time the active call completes, Twilio will request that StatusCallback route allowing you to start the next call in your sequence.

希望有所帮助.

这篇关于使用 twilio 拨出电话按顺序拨打多个号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆