Newer
Older
import nexmo
from django.conf import settings
class Nexmo:
"""
Gateway for sending text messages and making phone calls using Nexmo_.
All you need is your Nexmo Account API and Secret, as shown in your Nexmo
account dashboard.
``NEXMO_API_KEY``
Should be set to your account's API Key.
``NEXMO_API_SECRET``
Should be set to your account's secret.
``NEXMO_DEFAULT_FROM``
Should be set to a phone number or name.
.. _Nexmo: http://www.nexmo.com/
"""
def __init__(self):
self.client = nexmo.Client(key=getattr(settings, 'NEXMO_API_KEY'), secret=getattr(settings, 'NEXMO_API_SECRET'))
self.default_from = getattr(settings, 'NEXMO_DEFAULT_FROM')
def send_sms(self, device, token):
body = 'Your authentication token is %s' % token
phone_number = device.number.as_e164
logger.info("Sending authentication token to %s", phone_number)
self.client.send_message({'to': phone_number, 'from': self.default_from, 'text': body})