Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I route SMSes using Twilio, based on a schedule?

Tags:

sms

twilio

I send SMS alerts to my mobile phone using Twilio; I would like to route this to a different number based on a schedule / rota? ie I am in the US, so during my day I would like to get alerts, and then during the UK's day I would like someone else?

Any ideas?

Thanks

like image 903
tom.wilkie Avatar asked Jan 23 '26 10:01

tom.wilkie


1 Answers

You can just configure the sending address based on the current date and time. In Python this would look something like this:

from datetime import datetime

curr_time = datetime.utcnow()

# roughly, London working hours
if 8 < curr_time.hour <= 17:
     recipient = "+44XXXXXXXXXXX"
else:
     recipient = "+1XXXXXXXXXXXX"

send_sms_message(from=twilio_number, to=recipient, body=body)

Without knowing more about how you are sending the messages, or how you are generating alerts, it's difficult to provide a more nuanced answer.

like image 93
Kevin Burke Avatar answered Jan 25 '26 07:01

Kevin Burke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!