Skip to main content

This package to replace content in the TRAI SMS template

Project description

TRAI SMS Template Replacer

Replace content in the TRAI SMS template with ease using this Python package. This library is designed to simplify the process of replacing placeholders in a TRAI SMS template with actual values. It's particularly useful for bulk SMS generation where you need to personalize messages based on dynamic data.

Installation

You can install the traisms library using pip:

pip install traisms

Usage

To get started, import the library and create an instance of the SMSTemplate class:

from traisms import SMSTemplate

template = 'Hi, %%|name^{"inputtype" : "text", "maxlength" : "8"}%% has checked out at %%|time^{"inputtype" : "number", "maxlength" : "6"}%% PM from %%|place^{"inputtype" : "text", "maxlength" : "64"}%%'
values = ["Alice", "2", "Taj Hotel"]

replacer = SMSTemplate()

Then, simply replace the placeholders in the template with the provided values using the replace method:

try:
    result = replacer.replace(template, values)
    print(result)
except Exception as e:
    print(e)

The replace method will return the updated template with the values substituted in place of the placeholders. If there are any validation errors, the library will raise relevant exceptions:

  • Invalid Template Error: This error is raised if a placeholder in the template is not valid.

  • Invalid Number Found: This error is raised if a placeholder expects a numeric value but a non-numeric value is provided.

  • Exceeded Max Length: This error is raised if a placeholder value exceeds its specified maximum length.

Example Error Handling:

# Output:
# Invalid Number Found: Can not replace "1233" expecting numeric value

# or

# Output:
# Exceeded Max Length: Can not replace "Alice" exceeding max length of 8

Template Syntax

The template follows a specific syntax for placeholders, which are enclosed within double percentage signs (e.g., %%). Each placeholder should have the following format:

%%|name^{"inputtype" : "text", "maxlength" : "8"}%%
  • name: Placeholder ID
  • {"inputtype" : "text", "maxlength" : "8"}: Placeholder attributes (optional)

You can customize the placeholder attributes as needed.

Features

  • Easy replacement of placeholders in TRAI SMS templates.
  • Support for dynamic values provided in a list.
  • Customizable placeholder attributes for flexibility.
  • Validation and error handling for template placeholders.
  • Suitable for bulk SMS generation and personalization.

License

This library is provided under the Apache License 2.0.

Contributions

Contributions and feedback are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.


Note: This library is not affiliated with TRAI (Telecom Regulatory Authority of India) but is designed to assist in formatting SMS messages according to TRAI guidelines.

Happy SMS templating! 📱✉️

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

traisms-0.0.4.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

traisms-0.0.4-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file traisms-0.0.4.tar.gz.

File metadata

  • Download URL: traisms-0.0.4.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for traisms-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c3a6a670673db26c1dcc392e0b2b9e5bbd2c4b407fbefbba657e33dbebe1f2b6
MD5 83dec622c801b210cd3610e17c2d411d
BLAKE2b-256 44a24e69fb9ecc3fc86961956995183d9a5a6066b78df37f4daf0695093f5792

See more details on using hashes here.

File details

Details for the file traisms-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: traisms-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for traisms-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1b56fb094d5b681180e6892ec8602e581d67d75872dcf2eaa5ed50a308c9e1e9
MD5 c09dc29efbce0d18e8f50fd581651b60
BLAKE2b-256 115a58eab57a4e095a76a91c1297ec9ff20a7d96f0ae9d18a1d7cee0a9c15e2c

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