feat: automatic sms sending script

This commit is contained in:
Advaita Saha 2022-09-25 12:02:53 +05:30
parent 3789b6aa08
commit eccd20a234
3 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# Auto SMS
Easy CLI interface for users looking to test their SMS campaign integration with Kaleyra
![Software Sample](demo.gif)
## Install the Dependencies :-
* A kaleyra account and api key, secret key
* python3 installed
* ```pip install requests```
* ```pip install json```
To get the API key from Kaleyra follow these steps:
* Go to the kaleyra.com
* Click on the register button and follow the registration process and complete it.
* The follow the prompt for KYC verification.
* The you will be directed to your dashboard
* On the bottom left corner click the option `developers`
* In the `developers` tab you will get a option for generating `API KEY`
* After API key generation please copy those key to `line no. 9,10,11`
* Click on Billing to make sure your billing details are up-to-date. If they not, follow this link.
For futhers details of the API please refer to the official documentation https://developers.kaleyra.io/docs/getting-started-with-kaleyra-cloud-apis
## Quick Start :-
```
git clone https://github.com/abhijeet007rocks8/Dev-Scripts
cd Dev-Scripts/Python/Automations/Auto SMS/
```
##### Please replace the comments in main.py with your SID, API Key, SenderID
To run the program, write the following code in the terminal
python main.py
The program is up and running

BIN
scripts/SMS Sender/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 KiB

118
scripts/SMS Sender/main.py Normal file
View File

@ -0,0 +1,118 @@
# Created by @advaitasaha
# Imports
import requests
# Variables
global apiKey
global SID
global senderID
apiKey = "" # enter your api key
SID = "" # enter your SID number
senderID = "" # enter the senderID registered
# Functions for semding SMS
def send_sms(number):
headers_sms = {
"api-key": apiKey,
}
data_sms = {
"type": "TXN",
"to": "+91{}".format(str(number)),
"sender": senderID,
"source": "API",
"body": "Thank you {} for using this software.".format(
"name"
), # change the body of the messages
"template_id": "1207161891861378858", # enter registered template id
}
response = requests.post(
"https://api.kaleyra.io/v1/{}/messages".format(SID),
headers=headers_sms,
data=data_sms,
)
return response.json()
def number_val(number):
headers = {
"Content-Type": "json",
"api-key": apiKey,
}
response = requests.get(
"https://api.kaleyra.io/v1/{}/lookup/+91{}".format(SID, str(number)),
headers=headers,
)
if response.json()["invalid_count"]:
return False, response.json()
else:
return True, response.json()
def send_flash_sms(number):
headers = {
"api-key": apiKey,
}
data = {
"to": "+91{}".format(str(number)),
"type": "TXN",
"sender": senderID,
"body": "Thank you {} for using this software.".format(
"name"
), # change the body of the messages
"flash": "1",
}
response = requests.post(
"https://api.kaleyra.io/v1/{}/messages".format(SID), headers=headers, data=data
)
return response.json()
while True:
print("------------------------------------------------------------------")
print("Welcome to Kaleyra SMS sending software, created by @Advaita Saha")
print("------------------------------------------------------------------")
print("1: Send SMS")
print("2: Send flash SMS")
print("3: Check Number Validity")
print("0: Exit Program")
print("------------------------------------------------------------------")
userInput = int(input("Enter the option number you want to perform: "))
if userInput == 1:
number = int(input("Enter the phone number to which you want to send: "))
out = send_sms(number)
print("------------------------------------------------------------------")
print("SMS sent, below is the JSON output")
print(out)
elif userInput == 2:
number = int(input("Enter the phone number to which you want to send: "))
out = send_flash_sms(number)
print("------------------------------------------------------------------")
print("Flash SMS sent, below is the JSON output")
print(out)
elif userInput == 3:
number = int(input("Enter the phone number to which you want to send: "))
out = number_val(number)
if out[0]:
print("------------------------------------------------------------------")
print("Valid Number, details below")
print(out[1])
else:
print("------------------------------------------------------------------")
print("Invalid Number")
print(out[1])
elif userInput == 0:
break