pythondjangosms-gateway

What are the settings.py credentials for SMS in DJANGO of integrating the third party API like SMSBOX, other than TIWILIO


What will be the credentials in settings.py, to send this sms via third party api. Like where to give HOST_NAME, PASSWORD, API_KEY?

message = SmsMessage(body='Project Created', from_phone='+923117593775', to=['+923411727228'])
message.send()

Solution

  • You can use python's request library for making requests to APIs. SMSBox has different APIs for accessing the services. This one is for sending a SMS.

    import requests
    from django.conf import settings
    
    def sendSMS(message, from ,to):
        url = 'https://www.smsbox.com/SMSGateway/Services/Messaging.asmx/Http_SendSMS'
        payload = {
            "username": settings.SMSUsername,
            "password": settings.SMSPassword,
            "customerId": settings.SMSCutomerID,
            "senderText": settings.SMSSenderName,
            "messageBody": str(message),
            "recipientNumbers": ','.join(to),
            "isBlink": False,
            "isFlash": False
        }
        response = request.post(url, payload)
        
    

    Now in your settings.py, you can have the required setting variables

    SMSUsername = 'your_username'
    SMSPassword = 'your_password'
    SMSCutomerID = 'your_customer_id'
    SMSSenderName  'sms_sender_name'
    

    Twilio has a supported python SDK package for integration of its services, so you can directly implement it, but for platforms who don't have SDK support for python/django, you can use requests library to call APIs as per their documentation. This function was made according to the documentation provided by SMSBox, you can create your own functions as per your requirement and the API documentation.