Sending SMS with Twilio API
Setup overview
Section titled “Setup overview”- Create a Twilio account
- Get Account SID + Auth Token
- Buy/verify a sender phone number
Store secrets in env vars:
TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKEN
Example
Section titled “Example”import os
# from twilio.rest import Client
def send_sms(to: str, body: str):
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
# client = Client(account_sid, auth_token)
# msg = client.messages.create(
# body=body,
# from_="+15551234567",
# to=to,
# )
# return msg.sid
# send_sms("+15550001111", "hello")- keep rate limits in mind
- never hardcode auth tokens
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading