smswhatsappservice/send_whatsapp_bulk.py
vickytechkey 590f9c1999
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 37s
Initial commit
2026-09-20 18:57:37 +05:30

59 lines
No EOL
1.7 KiB
Python

import http.client
import os
import json
import sys
# Get mobile number from user input or command line argument
if len(sys.argv) > 1:
mobile_number = sys.argv[1]
else:
mobile_number = input("Enter the mobile number with country code (e.g., 919600494039): ").strip()
if not mobile_number:
print("Error: Mobile number is required!")
sys.exit(1)
# Get OTP code from user input or command line argument
if len(sys.argv) > 2:
otp_code = sys.argv[2]
else:
otp_code = input("Enter the OTP code (e.g., 123456): ").strip()
if not otp_code:
print("Error: OTP code is required!")
sys.exit(1)
conn = http.client.HTTPSConnection("control.msg91.com")
# Read the JSON payload from the template file
template_path = os.path.join(os.path.dirname(__file__), "template jsons", "mobile_number_verification.json")
with open(template_path, "r") as f:
payload_dict = json.load(f)
# Update the target mobile number dynamically
payload_dict["payload"]["template"]["to_and_components"][0]["to"] = [mobile_number]
# Update the OTP values dynamically
components = payload_dict["payload"]["template"]["to_and_components"][0]["components"]
if "body_1" in components:
components["body_1"]["value"] = otp_code
if "button_1" in components:
components["button_1"]["value"] = otp_code
# Convert the dictionary back to a JSON string
payload = json.dumps(payload_dict)
headers = {
'accept': "application/json",
'authkey': "563180AluxJHIeTGn6aaf97aeP1",
'content-type': "application/json"
}
print(f"Sending OTP {otp_code} to {mobile_number}...")
conn.request("POST", "/api/v5/whatsapp/whatsapp-outbound-message/bulk/", payload, headers)
res = conn.getresponse()
data = res.read()
print("Response:", data.decode("utf-8"))