简体   繁体   English

如何使用 twilio 在定义的时间发送短信?

[英]How with twilio to send sms at defined time?

I just started using twilio for a start-up.我刚开始使用 twilio 进行启动。 We need to send to our customers sms 15 min before appointments.我们需要在预约前 15 分钟向我们的客户发送短信。 The appointments can be 1-5 per day.约会可以是每天1-5个。 I have the times and dates of the appointments, with the name of the corresponding customer and more info, saved in a csv-file.我有约会的时间和日期,以及相应客户的姓名和更多信息,保存在 csv 文件中。

How can I make twilio send the sms at the desired time from the csv?如何让 twilio 在所需时间从 csv 发送短信?

Note that I am coding exclusively in python (my level is basic to mid).请注意,我只在 python 中编码(我的水平是基本到中等)。 I have found this example:我找到了这个例子:

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)

It would be great if I could include something like a function written by me and if there would be a parameter of client.message.create for when to send the message, something like:如果我可以包含我编写的 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))

Is there a simple solution for that with python? python 是否有一个简单的解决方案? If not, is there an alternative to twilio that does this?如果没有,是否有替代 twilio 的替代方案? What other suggestions can you give?你还能给出什么其他建议? Tnx肿瘤坏死因子

Twilio currently doesn't have a job scheduler, so you need to use an external scheduler to perform some of these tasks, possibly the below will be helpful. Twilio 目前没有作业调度器,因此您需要使用外部调度器来执行其中一些任务,可能以下内容会有所帮助。

4 ways to schedule Node.js code 4种方式调度Node.js代码

  • Yes Node but I imagine you can derive the steps for Python是节点,但我想你可以推导出 Python 的步骤

How to use email and SMS notifications together如何同时使用 email 和短信通知

Another simple way would be to create a google apps script.另一种简单的方法是创建一个谷歌应用程序脚本。 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. 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.

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