【问题标题】:How with twilio to send sms at defined time?twilio 如何在定义的时间发送短信?
【发布时间】:2020-08-12 11:43:28
【问题描述】:

我刚开始使用 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)

如果我可以包含类似我编写的函数之类的东西,并且如果有一个 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 的替代品可以做到这一点?你还能给出什么其他建议?天呐

【问题讨论】:

    标签: python twilio sms sms-gateway


    【解决方案1】:

    Twilio 目前没有作业调度程序,因此您需要使用外部调度程序来执行其中一些任务,可能以下内容会有所帮助。

    4 ways to schedule Node.js code

    • 是节点,但我想您可以推导出 Python 的步骤

    How to use email and SMS notifications together

    【讨论】:

    • 谢谢,可惜 Twilio 没有更简单的方法来使用 python 安排 SMS。除此之外,您能否向我推荐一个发送预定 SMS 的 Twilio 替代服务?
    • Twilio 是一个构建器平台,所以一切皆有可能,但它通常需要一定程度的构建/编码才能完成。
    【解决方案2】:

    另一种简单的方法是创建一个谷歌应用程序脚本。您可以利用时钟触发器运行函数来获取 URL 以调用 Twilio API 以发送短信这里是在谷歌应用脚​​本中发送 twilio 短信的基本函数。

    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);
    }
    

    【讨论】:

    • 谢谢!另一个人建议,应该有一个用于 Twilio 的 GUI,其中包括安排 SMS 发送时间的选项,但没有提供详细信息。你能告诉我 twilio GUI 吗?
    • 我不熟悉,但对于您的情况,我认为 Google 电子表格会很好用。您可以将 csv 文件中的信息复制到 Google 电子表格中。然后编写一个脚本,每天循环浏览您的工作表,如果当天有约会,则发送短信
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    相关资源
    最近更新 更多