-
Notifications
You must be signed in to change notification settings - Fork 3
/
infobip.py
62 lines (53 loc) · 1.8 KB
/
infobip.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
54
55
56
57
58
59
60
61
62
import os
from infobip_api_client.api_client import ApiClient, Configuration
from infobip_api_client.model.sms_advanced_textual_request import SmsAdvancedTextualRequest
from infobip_api_client.model.sms_destination import SmsDestination
from infobip_api_client.model.sms_response import SmsResponse
from infobip_api_client.model.sms_textual_message import SmsTextualMessage
from infobip_api_client.api.send_sms_api import SendSmsApi
from infobip_api_client.exceptions import ApiException
from dotenv import load_dotenv
load_dotenv('.env')
"""
* Send an sms message by using Infobip API.
*
* This example is already pre-populated with your account data:
* 1. Your account Base URL
* 2. Your account API key
* 3. Your recipient phone number
*
* THIS CODE EXAMPLE IS READY BY DEFAULT. HIT RUN TO SEND THE MESSAGE!
*
* Send sms API reference: https://www.infobip.com/docs/api#channels/sms/send-sms-message
* See Readme file for details.
"""
BASE_URL = os.getenv('INFOBIP_BASE_URL')
API_KEY = os.getenv('INFOBIP_API_KEY')
SENDER = "InfoSMS"
RECIPIENT = "998919791999"
MESSAGE_TEXT = "Salom dunyo"
client_config = Configuration(
host=BASE_URL,
api_key={"APIKeyHeader": API_KEY},
api_key_prefix={"APIKeyHeader": "App"},
)
api_client = ApiClient(client_config)
sms_request = SmsAdvancedTextualRequest(
messages=[
SmsTextualMessage(
destinations=[
SmsDestination(
to=RECIPIENT,
),
],
_from=SENDER,
text=MESSAGE_TEXT,
)
])
api_instance = SendSmsApi(api_client)
try:
api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)
print(api_response)
except ApiException as ex:
print("Error occurred while trying to send SMS message.")
print(ex)