-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms_api_voyage.py
29 lines (23 loc) · 928 Bytes
/
sms_api_voyage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from dotenv import load_dotenv
import vonage
class API:
def __init__(self):
load_dotenv('.env')
self.VONAGE_API_KEY = os.getenv("VONAGE_API_KEY")
self.VONAGE_API_SECRET = os.getenv("VONAGE_API_SECRET")
self.VONAGE_BRAND_NAME = os.getenv("VONAGE_BRAND_NAME")
self.TO_NUMBER = int(os.getenv("TO_NUMBER"))
def send_sms(self, name, mail, data):
client = vonage.Client(key=self.VONAGE_API_KEY, secret=self.VONAGE_API_SECRET)
responsedata = client.sms.send_message(
{
"from": self.VONAGE_BRAND_NAME,
"to": self.TO_NUMBER,
"text": f"{name} <{mail}>\n{data}",
}
)
if responsedata["messages"][0]["status"] == "0":
print("Message sent successfully.")
else:
print(f"Message failed with error: {responsedata['messages'][0]['error-text']}")