[英]How with twilio to send sms at defined time?
我刚开始使用 twilio 进行启动。 我们需要在预约前 15 分钟向我们的客户发送短信。 约会可以是每天1-5个。 我有约会的时间和日期,以及相应客户的姓名和更多信息,保存在 csv 文件中。
如何让 twilio 在所需时间从 csv 发送短信?
请注意,我只在 python 中编码(我的水平是基本到中等)。 我找到了这个例子:
from twilio.rest import Client
customer_num = '+15558675310'
account_sid = 'AC56382b8b1ac86598d9a775851c9652dc'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body="Join Earth's mightiest heroes. Like Kevin Bacon.",
from_='+15017122661',
to=customer_num)
)
print(message.sid)
如果我可以包含我编写的 function 之类的内容,并且如果有 client.message.create 的参数用于何时发送消息,那就太好了,例如:
def send_time_func(phone_num, other_parameters):
'''Some function I write on my own that goes through the csv
and sends the sms to the customer at the defined time in the csv'''
return(send_time)
message = client.messages.create(
....
send_time=send_time_func(customer_num, other_parameters))
python 是否有一个简单的解决方案? 如果没有,是否有替代 twilio 的替代方案? 你还能给出什么其他建议? 肿瘤坏死因子
Twilio 目前没有作业调度器,因此您需要使用外部调度器来执行其中一些任务,可能以下内容会有所帮助。
另一种简单的方法是创建一个谷歌应用程序脚本。 You can utilize the clock triggers to run a function to fetch a URL to call a Twilio API to send a sms here is a basic function to send a twilio sms in a google apps script.
function sendSms(){
var messagesUrl = "https://api.twilio.com/2010-04-01/Accounts/YOUR_TWILIO_ACCOUNT_SID/Messages.json";
var payload = {
"To": "DESTINATION_NUMBER",
"From" : "YOUR_TWILIO_NUMBER",
"Body" : 'This is a reminder that you have an appointment',
};
var options = {
"method" : "post",
"payload" : payload
};
options.headers = {
"Authorization" : "Basic " + Utilities.base64Encode('YOUR_ACCOUNT_SID:YOUR_AUTH_TOKEN')
};
UrlFetchApp.fetch(messagesUrl, options);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.