Skip to main content

Package for GoSMSGE that helps you to send messages to your clients

Project description

GOSMS.GE Python SMS Send

Python client module to send SMS messages using GOSMS.GE SMS Gateway.

To use this library, you must have a valid account on https://gosms.ge.

Please note SMS messages sent with this library will be deducted by your GOSMS.GE account credits.

For any questions, please contact: info@gosms.ge

usage

Send a message with Classic type

from gosms import SMS

sms: SMS = SMS('api_key')

sms.send('995555555555', 'Hello!', 'GOSMS.GE')

Check status of message

from gosms import SMS

sms: SMS = SMS('api_key')

sms.status('message_id')

Check balance

from gosms.settings import GOSMS_SETTINGS
from gosms import sms

GOSMS_SETTINGS['api_key'] = 'your_api_key'

sms.balance()

usage in Django

# django settings file

GOSMS_SETTINGS = {
    # you should have valid API key given by gosms.ge
    'api_key': 'your_api_key',

    # this property will have same value as DEBUG but you can override it here
    'dev_mode': False,
}
# views.py
from gosms import sms


def send_message_view(request):
    """ :returns {"code": string,"message": string,"message_id": number,"balance": number,"user": string} """
    return sms.send('995555555555', 'Hello!', 'GOSMS.GE')


def check_status_view(request):
    """ :returns { id: number,sender: string,receiver: string,message: string',message_id: string,amount: number,status: string } """
    return sms.status('message_id')


def check_balance_view(request):
    """ returns { balance: number, user: string } """
    return sms.balance()

You can use it anywhere

# user.managers
from django.contrib.auth.base_user import BaseUserManager


class UserManager(BaseUserManager):
    use_in_migrations = True

    def _create_user(self, phone_number, password, **extra_fields):
        """
        Creates and saves a User with the given email and password.
        """
        if not phone_number:
            raise ValueError('The given phone_number must be set')
        user = self.model(phone_number=phone_number, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, phone_number, password=None, **extra_fields):
        extra_fields.setdefault('is_superuser', False)
        return self._create_user(phone_number, password, **extra_fields)

    def create_superuser(self, phone_number, password, **extra_fields):
        extra_fields.setdefault('is_superuser', True)

        if extra_fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(phone_number, password, **extra_fields)
# user.models
from django.db import models
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils.translation import ugettext_lazy as _

from user.managers import UserManager

from gosms import sms


class User(AbstractBaseUser, PermissionsMixin):
    phone_number = models.CharField(_('Phone Number'), unique=True)
    is_active = models.BooleanField(_('Is Active'), default=False)
    objects = UserManager()

    USERNAME_FIELD = 'phone_number'
    REQUIRED_FIELDS = []

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        sms.send(self.phone_number, 'user created', 'GOSMS.GE')
# views.py
from django.shortcuts import get_object_or_404, render

from user.models import User
from gosms import sms


def user_register(request):
    user = User(
        phone_number=request.POST.get('phone_number'),
    )
    user.set_password(request.POST.get('password'))
    user.save()
    sms.send_otp(user.phone_number)


def verify_user(request):
    """ verify otp method raises exception if details are incorrect """
    response_data = sms.verify_otp(
        request.POST.get('phone_number'),
        request.POST.get('hash'),
        request.POST.get('code')
    )

    user = get_object_or_404(
        User, phone_number=request.POST.get('phone_number')
    )
    user.is_active = True
    user.save()
    return render(request, 'some_template', context=response_data)

More info

You can check out our website https://www.gosms.ge

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

gosmsge-1.0.5.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

gosmsge-1.0.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file gosmsge-1.0.5.tar.gz.

File metadata

  • Download URL: gosmsge-1.0.5.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for gosmsge-1.0.5.tar.gz
Algorithm Hash digest
SHA256 35ab4713b0f6c68b6a84a0da893ed07955923b95361e97b62c96f5e579e9550f
MD5 c47e38c2c6a247aef530e714da9adb51
BLAKE2b-256 7ec7292e6550bbc4c355dabf778c238763537579e79c3e7c6b8bdba98f3292b4

See more details on using hashes here.

File details

Details for the file gosmsge-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: gosmsge-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for gosmsge-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 66dc2696197baacb60772a7acb124952fedc5639e79ca613e7aa07c018de03c2
MD5 7d799465168dcfaa593deb44a9f641f1
BLAKE2b-256 33befaf08af8088001a5d309c87a51f827f266d8f95a0d034d059fd454dcb7dd

See more details on using hashes here.

Supported by

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