首页 > 解决方案 > Twilio Python:如何通过 twilio 调用多个调用

问题描述

我想在 python 上通过 Twilio 呼叫多部电话我刚刚看到 Twilio 博客,但我没有理解这是我的脚本

# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

account_sid = "AC723c6c38e7c58a572ce011a652540a42"
auth_token = "REDACTED"
client = Client(account_sid, auth_token)
# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
call = client.calls.create(

    )

print(call.sid)

那么你能告诉我该怎么做吗

标签: pythontwilio

解决方案


Twilio 开发人员布道者在这里。您应该创建一个要调用的电话号码数组,然后遍历该数组,调用calls.create方法来调用作为参数传入的数组中的每个号码calls.create

# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

account_sid = "AC723c6c38e7c58a572ce011a652540a42"
auth_token = "REDACTED"
client = Client(account_sid, auth_token)
# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
arr = ['INSERT-NUMBER-TO-CALL', 'INSERT-OTHER-NUMBER-TO-CALL'...]
for num in arr:
    call = client.api.account.calls.create(
        to=num,
        from_='YOUR-TWILIO-NUMBER',
        url = 'http://demo.twilio.com/docs/classic.mp3'
        )
    print(call.sid)

或者,url您可以使用它来播放消息,而不是包含指向您要在手机上播放的文件的链接twiml='<Response><Say>INSERT MESSAGE HERE</Say></Response>',。您可以使用不同的 Amazon Polly 语音来自定义说出消息的语音 -更多信息请点击此处


推荐阅读