Skip to main content

A package to send SMS using Onfon Media API

Project description

Onfon-SMS-Sender

A Python package to send SMS using the Onfon Media API.

Introduction

The Onfon-SMS-Sender package allows you to send SMS messages through the Onfon Media API. It supports configuration via environment variables, Django settings, or Flask settings, making it versatile and easy to integrate into various Python environments.

Installation

pip install onfon-sms-sender

Prerequisites

  • Python 3.6 or higher
  • Requests library
  • Optional: Flask or Django for web application integration

Configuration

The package requires the following configuration variables:

  • SMS_API_URL
  • SMS_CLIENT_ID
  • SMS_API_KEY
  • SMS_SENDER_ID

You can set these variables either as environment variables or in your application's settings.

Usage

from onfon_sms_sender import send_sms

recipients = []  # comma separated  List of string recipient phone numbers in format ["254...", "07.."]
message = "Hello, this is a test message from Onfon Media API"
response = send_sms(recipients=recipients, message=message)
print(response)

Usage Example in Flask

You can set up your Flask application to use the send_sms function as shown below:

app.py

from flask import Flask
from onfon_sms_sender import send_sms

app = Flask(__name__)
app.config['SMS_API_URL'] = 'https://api.onfonmedia.co.ke/v1/sms/SendBulkSMS'
app.config['SMS_CLIENT_ID'] = 'your_client_id_here'
app.config['SMS_API_KEY'] = 'your_api_key_here'
app.config['SMS_SENDER_ID'] = 'your_sender_id_here'

@app.route('/send_sms')
def send_sms_route():
    recipients = []# comma separated  List of string recipient phone numbers in format ["254...", "07.."]
    message = "Hello, this is a test message from Onfon Media API"
    response = send_sms(recipients=recipients, message=message)
    return str(response)

if __name__ == '__main__':
    app.run(debug=True)

Usage Example in Django

Ensure your Django project's settings.py includes the necessary configuration:

settings.py

# settings.py
SMS_API_URL = 'https://api.onfonmedia.co.ke/v1/sms/SendBulkSMS'
SMS_CLIENT_ID = 'your_client_id_here'
SMS_API_KEY = 'your_api_key_here'
SMS_SENDER_ID = 'your_sender_id_here'

Use the send_sms function in your Django views:

from django.http import JsonResponse
from onfon_sms_sender import send_sms

def send_sms_view(request):
    recipients = []  # comma separated  List of string recipient phone numbers in format ["254...", "07.."]
    message = "Hello, this is a test message from Onfon Media API"
    response = send_sms(recipients=recipients, message=message)
    return JsonResponse(response, safe=False)

Running Tests

To run tests, ensure you have set the necessary environment variables or updated your settings.py file.

python -m unittest discover

Feedback and Contribution

If you have any feedback or suggestions, please open an issue or submit a pull request on GitHub. Your contributions are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onfon_sms_sender-0.1.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onfon_sms_sender-0.1.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file onfon_sms_sender-0.1.4.tar.gz.

File metadata

  • Download URL: onfon_sms_sender-0.1.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.1

File hashes

Hashes for onfon_sms_sender-0.1.4.tar.gz
Algorithm Hash digest
SHA256 253ef61bd14280223ecef79a878ff9f7177732f2509dee6017b147778cb7bc2e
MD5 22409ac8da0ab4844ab9ebab1167ce7f
BLAKE2b-256 3e07a58715f85f45500a0d154a3c3761ddc09ed93aa224efb28f0aaef0c599b0

See more details on using hashes here.

File details

Details for the file onfon_sms_sender-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for onfon_sms_sender-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b47978c19340061f46dd203805feb1931761756e7008606cb09cc558be4750ec
MD5 a2fd89b7162598ae2910f6975dd7165d
BLAKE2b-256 dc8ca39b1d05310256582fe012cdb735322199ed66152b2e21b3fe8c861c5934

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page