Skip to main content

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"]

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

try:
    result = SMSTemplate.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! 📱✉️

Metadata

Release files for traisms 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traisms 0.1.0
File Size Uploaded
traisms-0.1.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for traisms 0.1.0
File Interpreter ABI Platform
traisms-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / traisms-0.1.0.tar.gz

Download URL traisms-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ea3bbaf71dc3a96e5713dd3f7fb9486d5cd425a1757513875f8c608e5f553616
BLAKE2b-256 checksum
How to use checksums
ed4f24ae353c329dd1a3665dedce6a74877db3ed3ac0b16c502b9f662f4b0127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / traisms-0.1.0-py3-none-any.whl

Download URL traisms-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f206657890e45d43665b94b89efdd093f3bdc28949159154b4a33e41f252530
BLAKE2b-256 checksum
How to use checksums
98cb7870f51261e8d0cfcd63ebe0677828d390d73ba1252658c5a226752f7e3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page