Skip to content

Commit 2f1e73a

Browse files
authored
Merge pull request #585 from advaita-saha/main
auto sms script contribution
2 parents 89ce782 + af12462 commit 2f1e73a

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

auto-sms/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Auto SMS
2+
Easy CLI interface for users looking to test their SMS campaign integration with Kaleyra
3+
4+
The requirements for any user are :-
5+
* A kaleyra account and api key, secret key
6+
* python3 installed
7+
* pip packages required are requests, json
8+
9+
To get the API key from Kaleyra follow these steps:
10+
11+
* Go to the kaleyra.com
12+
* Click on the register button and follow the registration process and complete it.
13+
* The follow the prompt for KYC verification.
14+
* The you will be directed to your dashboard
15+
* On the bottom left corner click the option `developers`
16+
* In the `developers` tab you will get a option for generating `API KEY`
17+
* After API key generation please copy those key to `line no. 10,11,12`
18+
* Click on Billing to make sure your billing details are up-to-date. If they not, follow this link.
19+
For futhers details of the API please refer to the official documentation https://developers.kaleyra.io/docs/getting-started-with-kaleyra-cloud-apis
20+
21+
##### Please replace the comments in main.py with your SID, API Key, SenderID
22+
23+
To run the program, write the following code in the terminal
24+
25+
python main.py
26+
27+
The program is up and running

auto-sms/main.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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

Comments
 (0)