簡體   English   中英

如何使用 twilio 在定義的時間發送短信?

[英]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 目前沒有作業調度器,因此您需要使用外部調度器來執行其中一些任務,可能以下內容會有所幫助。

4種方式調度Node.js代碼

  • 是節點,但我想你可以推導出 Python 的步驟

如何同時使用 email 和短信通知

另一種簡單的方法是創建一個谷歌應用程序腳本。 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