Skip to content

Commit 49a3020

Browse files
committed
auto sms script contribution
1 parent 5267081 commit 49a3020

File tree

2 files changed

+142
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)