我正在尝试编写一个程序,需要使用Twilio在Whatsapp上发送链式消息。 这是我一直在使用的代码:
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = '############'
auth_token = '##########'
client = Client(account_sid, auth_token)
phonelist = []
phonelist.append('######')
phonelist.append('######')
for i in range(0,len(phonelist)):
receiver = 'whatsapp:+34' + phonelist[i]
message = client.messages.create(
from_='whatsapp:+14155238886',
body='Hey there!',
to=receiver
)
#I have hidden the real phone numbers and account data with #
无论何时执行此操作,两个电话号码都会收到消息嘿!。
但是,我也试图在如下所示的函数下定义代码:
from twilio.rest import Client
phonelist= []
phonelist.append('#######')
phonelist.append('#######')
#Send a chain message to phones in phonelist
def chain_alert(phonelist, message):
account_sid = '#######'
auth_token = '#######'
client = Client(account_sid, auth_token)
for i in range(0,len(phonelist)):
destinatario = 'whatsapp:+34' + phonelist[i]
message = client.messages.create(
from_='whatsapp:+14155238886',
body=message,
to=destinatario
)
chain_alert(phonelist, "Hola")
只要运行此命令,列表中的第一个电话号码就会收到 Hola ,但是第二个电话号码会收到
两个代码似乎对我来说都应该一样工作。我在这里做错了吗,或者这可能是API的错误?