-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
53 lines (44 loc) · 1.43 KB
/
test.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from dotenv import load_dotenv
import os
load_dotenv(".env")
import sendlk
SENDLK_TOKEN = os.environ.get("SENDLK_TOKEN")
SECRET = os.environ.get("SECRET")
SENDER_ID = os.environ.get("SENDER_ID")
PHONE_NUMBER = os.environ.get("PHONE_NUMBER")
sendlk.initialize(SENDLK_TOKEN, SECRET)
from sendlk.responses import SmsResponse, ProfileResponse
from sendlk.exceptions import SendLKException
from sendlk.engine import SMS, Profile
from sendlk.options import SendLKVerifyOption, SendLKCodeTemplate
try:
response: SmsResponse = SMS.send(PHONE_NUMBER, "Hello World!", SENDER_ID)
print(response)
except SendLKException as e:
print(e)
try:
response: ProfileResponse = Profile.balance()
print(response.remaining)
except SendLKException as e:
print(e)
class CustomCodeTemplate(SendLKCodeTemplate):
def __init__(self):
super().__init__()
def text(self, code: str) -> str:
return f"{code} is the verification code for foo service."
options: SendLKVerifyOption = SendLKVerifyOption(
code_length=6,
expires_in=5,
sender_id=SENDER_ID,
subject="foo",
code_template=CustomCodeTemplate()
)
try:
response: SmsResponse = SMS.send_verify_code(PHONE_NUMBER, options)
token = response.data.get("token", None)
code = input("Enter the code: ")
response: SmsResponse = SMS.validate_verify_code(code, token)
print(response)
print(response.data)
except SendLKException as e:
print(e)