Skip to main content

A Django package for seamless integration with Iranian SMS services like ParsianWebCo , Kavenegar and Melipayamak.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Django Iran SMS

Overview

A Django-based SMS integration system for simplifying in-country SMS usage in Iran, leveraging the parsianwebco.ir , melipayamak.com , kavenegar.com service with JWT authentication. Developed by the Chelseru team, drfiransms is designed to support additional services in future releases.

Features

  • Integration with parsianwebco.ir , melipayamak.com , kavenegar.com
  • JWT-based authentication using rest_framework_simplejwt
  • Scalable and extensible for other SMS providers
  • Easy installation and configuration

Installation

Prerequisites

  • Python 3.11
  • Django 5.1 or higher

Installation via pip

pip install django-iran-sms

Configuration

In your Django project's settings.py, add the following parameters:

settings.py

INSTALLED_APPS = [
...
'drfiransms', # When used in DRF.

]
DJANGO_IRAN_SMS = {
    'AUTHENTICATION': 'rest_framework_simplejwt',  # Specify the authentication method
    'SMS_BACKEND': 'PARSIAN_WEBCO_IR',  # Set the SMS provider backend
    'OTP_CODE': {
        'LENGTH': 6,  # Default length of OTP code
        'EXPIRE_PER_MINUTES': 2,  # Default expiration time in minutes
    },
    'PARSIAN_WEBCO_IR': {
        'API_KEY': 'API_KEY obtained from sms.parsianwebco.ir',  # API key from the SMS provider
        'TEMPLATES': {
            'OTP_CODE': 1,  # Template ID for OTP code
        }
    },
    'MELI_PAYAMAK_COM': {
        'USERNAME': 'Username used to log in to the melipayamak.com website.',
        'PASSWORD': 'API_KEY obtained from melipayamak.com',
        'FROM': '50004001001516',  # The sender number that should be received from the web service.
    },
    'KAVENEGAR_COM': {
        'API_KEY': 'API_KEY obtained from kavenegar.com',
        'FROM': '2000660110'
    }

}

Django Iran SMS Configuration

The configuration parameters for DJANGO_IRAN_SMS can be set as follows:

Authentication

Currently, only rest_framework_simplejwt is supported for authentication.

SMS Backend

You can choose one of the following SMS providers:

  • PARSIAN_WEBCO_IR
  • MELI_PAYAMAK_COM
  • KAVENEGAR_COM

OTP Code

The OTP_CODE parameter is a dictionary containing the following keys:

  • LENGTH: Specifies the length of the OTP code. It must be between 3 and 10 digits. If not provided, the default value is 6.
  • EXPIRE_PER_MINUTES: Defines the expiration time of the OTP code in minutes. It must be greater than 0. If not provided, the default value is 2 minutes.

Usage

URL Configuration

In your urls.py, include the following views:

  • OTPCodeSend: For sending OTP codes.
  • Authentication: For handling authentication and optional registration.

urls.py

from drfiransms.views import OTPCodeSend, Authentication, MessageSend

urlpatterns += [
    path('lur/send-code/', OTPCodeSend.as_view(), name='send_code'),  # Endpoint to send OTP code
    path('lur/authentication/', Authentication.as_view(), name='authentication'),  # Endpoint for authentication
    path('lur/send-message/', MessageSend.as_view(), name='send_message'), # Endpoint to send Message
]

Sending Verification Code via API

To send a POST request for receiving a verification code for a mobile number, use the following structure:

curl -X POST https://djangoiransms.chelseru.com/lur/send-code/ \
     -H "Content-Type: application/json" \
     -d '{
           "mobile": "09123456789"
         }'
curl -X POST https://djangoiransms.chelseru.com/lur/authentication/ \
     -H "Content-Type: application/json" \
     -d '{
           "mobile": "09123456789",
           "code": "108117114",
           "group": "1"
         }'
  • group: An attribute for times when there is a need to segment users, for example a user with a phone number can register as both a driver and a passenger. This attribute is not required and if not entered, the default value will be 0.
curl -X POST https://djangoiransms.chelseru.com/lur/send-message/ \
     -H "Content-Type: application/json" \
     -d '{
           "mobile_number": "09123456789",
           "message_text": "hello luristan."
         }'

User Table

Djangosms automatically creates a User table in the Django admin with two fields:

  • mobile: Stores the user's mobile number.
  • user: A one-to-one relationship with Django's default User model.
  • group: An attribute for times when there is a need to segment users, for example a user with a phone number can register as both a driver and a passenger. This attribute is not required and if not entered, the default value will be 0.

OTP Code Table

drfsms automatically creates an OTP Code table in the Django admin with two fields:

  • mobile: Stores the user's mobile number.
  • code: Stores the OTP Code.

JWT Authentication

Djangoiransms supports JWT authentication using the rest_framework_simplejwt package. The system is compatible with this authentication method for secure communication with the SMS gateway. Other authentication and login methods are currently under development.

Future Plans

  • Support for additional SMS providers.
  • Enhanced error handling.
  • Rate limiting and monitoring.
  • Contribution

A Django package for seamless integration with Iranian SMS services like ParsianWebCo , Kavenegar and Melipayamak. Contributions are welcome! Please submit pull requests or report issues on the GitHub repository.

License

MIT License

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

django_iran_sms-1.3.2.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

django_iran_sms-1.3.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file django_iran_sms-1.3.2.tar.gz.

File metadata

  • Download URL: django_iran_sms-1.3.2.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for django_iran_sms-1.3.2.tar.gz
Algorithm Hash digest
SHA256 0cc8fd9531b82ce069a0d5f5d51d8870ae7f5060f7c0f8b1b335169c40c9f7d9
MD5 24af6b11ec42d67bcb0238b2de875513
BLAKE2b-256 69dfbf50ede67444e2cc5a0c65f15215f7583b35ecb7acb8c1a91b1c46e77901

See more details on using hashes here.

File details

Details for the file django_iran_sms-1.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_iran_sms-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6840dd22cdd444041d17439ed1976ed16c456f5b11711b2e3081cf4945523bb
MD5 e9eb22adaa07b12b4673f0f5bbf6be91
BLAKE2b-256 259b06438b52a55bb317f6c4d1b273a7f56424e590a5e549390d6ed179eabb81

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