|
| 1 | +# Created by @advaitasaha |
| 2 | +# Imports |
| 3 | +import requests |
| 4 | + |
| 5 | +# Variables |
| 6 | +global apiKey |
| 7 | +global SID |
| 8 | +global senderID |
| 9 | +apiKey = "" # enter your api key |
| 10 | +SID = "" # enter your SID number |
| 11 | +senderID = "" # enter the senderID registered |
| 12 | + |
| 13 | +# Functions for semding SMS |
| 14 | + |
| 15 | + |
| 16 | +def send_sms(number): |
| 17 | + |
| 18 | + headers_sms = { |
| 19 | + "api-key": apiKey, |
| 20 | + } |
| 21 | + |
| 22 | + data_sms = { |
| 23 | + "type": "TXN", |
| 24 | + "to": "+91{}".format(str(number)), |
| 25 | + "sender": senderID, |
| 26 | + "source": "API", |
| 27 | + "body": "Thank you {} for using this software.".format( |
| 28 | + "name" |
| 29 | + ), # change the body of the messages |
| 30 | + "template_id": "1207161891861378858", # enter registered template id |
| 31 | + } |
| 32 | + |
| 33 | + response = requests.post( |
| 34 | + "https://api.kaleyra.io/v1/{}/messages".format(SID), |
| 35 | + headers=headers_sms, |
| 36 | + data=data_sms, |
| 37 | + ) |
| 38 | + return response.json() |
| 39 | + |
| 40 | + |
| 41 | +def number_val(number): |
| 42 | + |
| 43 | + headers = { |
| 44 | + "Content-Type": "json", |
| 45 | + "api-key": apiKey, |
| 46 | + } |
| 47 | + |
| 48 | + response = requests.get( |
| 49 | + "https://api.kaleyra.io/v1/{}/lookup/+91{}".format(SID, str(number)), |
| 50 | + headers=headers, |
| 51 | + ) |
| 52 | + if response.json()["invalid_count"]: |
| 53 | + return False, response.json() |
| 54 | + else: |
| 55 | + return True, response.json() |
| 56 | + |
| 57 | + |
| 58 | +def send_flash_sms(number): |
| 59 | + |
| 60 | + headers = { |
| 61 | + "api-key": apiKey, |
| 62 | + } |
| 63 | + |
| 64 | + data = { |
| 65 | + "to": "+91{}".format(str(number)), |
| 66 | + "type": "TXN", |
| 67 | + "sender": senderID, |
| 68 | + "body": "Thank you {} for using this software.".format( |
| 69 | + "name" |
| 70 | + ), # change the body of the messages |
| 71 | + "flash": "1", |
| 72 | + } |
| 73 | + |
| 74 | + response = requests.post( |
| 75 | + "https://api.kaleyra.io/v1/{}/messages".format(SID), headers=headers, data=data |
| 76 | + ) |
| 77 | + return response.json() |
| 78 | + |
| 79 | + |
| 80 | +while True: |
| 81 | + print("------------------------------------------------------------------") |
| 82 | + print("Welcome to Kaleyra SMS sending software, created by @Advaita Saha") |
| 83 | + print("------------------------------------------------------------------") |
| 84 | + print("1: Send SMS") |
| 85 | + print("2: Send flash SMS") |
| 86 | + print("3: Check Number Validity") |
| 87 | + print("0: Exit Program") |
| 88 | + print("------------------------------------------------------------------") |
| 89 | + userInput = int(input("Enter the option number you want to perform: ")) |
| 90 | + |
| 91 | + if userInput == 1: |
| 92 | + number = int(input("Enter the phone number to which you want to send: ")) |
| 93 | + out = send_sms(number) |
| 94 | + print("------------------------------------------------------------------") |
| 95 | + print("SMS sent, below is the JSON output") |
| 96 | + print(out) |
| 97 | + |
| 98 | + elif userInput == 2: |
| 99 | + number = int(input("Enter the phone number to which you want to send: ")) |
| 100 | + out = send_flash_sms(number) |
| 101 | + print("------------------------------------------------------------------") |
| 102 | + print("Flash SMS sent, below is the JSON output") |
| 103 | + print(out) |
| 104 | + |
| 105 | + elif userInput == 3: |
| 106 | + number = int(input("Enter the phone number to which you want to send: ")) |
| 107 | + out = number_val(number) |
| 108 | + if out[0]: |
| 109 | + print("------------------------------------------------------------------") |
| 110 | + print("Valid Number, details below") |
| 111 | + print(out[1]) |
| 112 | + else: |
| 113 | + print("------------------------------------------------------------------") |
| 114 | + print("Invalid Number") |
| 115 | + print(out[1]) |
| 116 | + |
| 117 | + elif userInput == 0: |
| 118 | + break |
0 commit comments