Coverage for jutil/sms.py : 0%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import requests
2from django.conf import settings
3from jutil.validators import phone_filter
6def send_sms(phone: str, message: str, sender: str = '', **kw):
7 """
8 Sends SMS via Kajala Group SMS API. Contact info@kajala.com for access.
9 :param phone: Phone number
10 :param message: Message to be esnd
11 :param sender: Sender (max 11 characters)
12 :param kw: Variable key-value pairs to be sent to SMS API
13 :return: Response from requests.post
14 """
15 if not hasattr(settings, 'SMS_TOKEN'):
16 raise Exception('Invalid configuration: settings.SMS_TOKEN missing')
17 if not sender:
18 sender = settings.SMS_SENDER_NAME
19 if not sender:
20 raise Exception('Invalid configuration: settings.SMS_SENDER_NAME missing')
21 headers = {
22 'Content-Type': 'application/json',
23 'Authorization': 'Token ' + settings.SMS_TOKEN,
24 }
25 data = {
26 'dst': phone_filter(phone),
27 'msg': message,
28 'src': sender,
29 }
30 for k, v in kw.items():
31 data[k] = v
32 return requests.post("https://sms.kajala.com/api/sms/", json=data, headers=headers)