Skip to main content

A Python interface for sending bulk messages, dynamic messages, and handling OTP operations via the Bitmoro API.

Project description

Bitmoro Python Library

A Python library for sending messages and handling OTP (One-Time Password) operations using the Bitmoro API.

Table of Contents


Introduction

The Bitmoro Python Library provides a simple interface for:

  1. Sending bulk SMS.
  2. Sending dynamic personalized messages.
  3. Managing OTP operations (generation, sending, and verification).

This library integrates seamlessly with the Bitmoro API, enabling efficient SMS services for your application.

Installation

To install the library, use the following command:

pip install bitmoro

Usage

Initializing the Client

To begin, import the Bitmoro class and initialize it with your API token:

Follow the link to get API key. API Docs

from bitmoro.bitmoro import Bitmoro

token = "<YOUR_API_TOKEN>"
client = Bitmoro(token)

Sending OTPs

You can generate, send, and verify OTPs as shown below:

Generating an OTP

otp_manager = await client.get_otp_manager()
phone_number = "98XXXXXXXX"
otp = otp_manager.generate_otp(phone_number)
print(f"Generated OTP for {phone_number}: {otp}")

Sending an OTP

otp_send_response = await otp_manager.send_otp(
    phone_number=phone_number,
    message_template=f"Your OTP is: {otp}"
)
print("OTP send response:", otp_send_response)

Verifying an OTP

entered_otp = await get_user_input()  # Async function to get user input
otp_verification_response = otp_manager.verify_otp(phone_number, entered_otp)
if otp_verification_response:
    print("OTP verified successfully!")
else:
    print("OTP verification failed.")

Sending Bulk Messages

To send bulk messages:

bulk_response = await client.send_bulk_message(
    message="Hello, this is a test message", #required
    numbers=["98XXXXXXXX"],  #required
    sender_id="BIT_MORE",  #optional
    scheduled_date=int(time.time()) + 60, #optional
    callback_url="https://your-callback-url.com/test" #optional
)
print("Bulk message response:", bulk_response)

Sending Dynamic Messages

For personalized messages, use the send_dynamic_message method:

dynamic_response = await client.send_dynamic_message(
    message="Hello, ${name}!",  #required
    contacts=[
        {"number": "98XXXXXXXX", "name": "John"},
        {"number": "98XXXXXXXX"}
    ],   #required
    sender_id="BIT_MORE", #optional
    scheduled_date=int(time.time()) + 60,  # optional
    default_value={"name": "User"}, #optional
    callback_url= "https://your-callback-url.com/test" #optional
)
print("Dynamic message response:", dynamic_response)

Callback URL Response

When a callback URL is provided, it receives a POST request containing the following information:

{
  "messageId": "unique_message_id",
  "message": "Hello, this is a test message",
  "status": "sent",
  "report": [
    {
      "number": "98XXXXXXXX",
      "status": "success",
      "message": "Sent.",
      "creditCount": 1
    }
  ],
  "senderId": "BIT_MORE",
  "deliveredDate": "2025-01-16T03:53:22.188Z",
  "refunded": 0
}

Dependencies

This library requires Python 3.7+ and the bitmoro package. Install it using:

pip install bitmoro

Example

Here is a complete example of sending an OTP and verifying it:

import asyncio
from bitmoro import Bitmoro

async def main():
    token = "<YOUR_API_TOKEN>"
    client = Bitmoro(token)
    
    otp_manager = await client.get_otp_manager()
    phone_number = "98XXXXXXXX"
    otp = otp_manager.generate_otp(phone_number)
    print(f"Generated OTP for {phone_number}: {otp}")

    otp_send_response = await otp_manager.send_otp(
        phone_number=phone_number,
        message_template=f"Your OTP is: {otp}"
    )
    print("OTP send response:", otp_send_response)

    entered_otp = input("Enter the OTP you received: ")
    otp_verification_response = otp_manager.verify_otp(phone_number, entered_otp)
    if otp_verification_response:
        print("OTP verified successfully!")
    else:
        print("OTP verification failed.")

asyncio.run(main())

License

This project is licensed under the 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

bitmoro-sms-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

bitmoro_sms-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file bitmoro-sms-1.0.0.tar.gz.

File metadata

  • Download URL: bitmoro-sms-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for bitmoro-sms-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c038dd2f8aba3c3e092de87d707e2dab412b619d070ae0cf754e0340a1555b73
MD5 5842fed0891b2aae447c8bcdaae129a9
BLAKE2b-256 d95c411109d486bd3d2511fc5b45d783772e63a617d12334ef17166d3c7194af

See more details on using hashes here.

File details

Details for the file bitmoro_sms-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bitmoro_sms-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for bitmoro_sms-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 372f06727a21b9e8ad060772c2b95cc4bde068826d6d0a22e4c8fc44d0ba993c
MD5 19c8a2e69f50e70052b86fccc5fc3737
BLAKE2b-256 46e5eba5f60ed718beaa31a2606248fdc646a14c82fb7b7b0f22ced8ab633b3f

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