Files

38 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import json
import urllib.request
import base64
PROJECT_ID = "16fbbcfd-1c94-4827-869c-0364f5f67488"
API_TOKEN = "PTfb129c5160af67841e2da19d5e9d94bcf6312a81fa43f248"
SPACE = "orbis-hosting.signalwire.com"
FROM_NUMBER = "+18177645007"
def send(to_number, body):
url = f"https://{SPACE}/api/messaging/messages"
payload = json.dumps({"to": to_number, "from": FROM_NUMBER, "body": body}).encode()
auth = base64.b64encode(f"{PROJECT_ID}:{API_TOKEN}".encode()).decode()
req = urllib.request.Request(url, data=payload, method="POST", headers={
"Content-Type": "application/json",
"Authorization": f"Basic {auth}",
})
try:
with urllib.request.urlopen(req) as resp:
print(resp.read().decode())
except urllib.error.HTTPError as e:
print(f"HTTP {e.code}: {e.read().decode()}")
sys.exit(1)
def main():
if len(sys.argv) < 3:
print("usage: sms-outbound-send.py <to_number> <body>")
sys.exit(1)
send(sys.argv[1], sys.argv[2])
if __name__ == "__main__":
main()