Skip to content

This package helps to easily and quickly generate beautiful messages for telegram bots using templates described in json.

License

Notifications You must be signed in to change notification settings

obervinov/messages-package

Repository files navigation

Messages Package

Release CodeQL PR

GitHub release (latest SemVer) GitHub last commit GitHub Release Date GitHub issues GitHub repo size

About this project

This package helps to easily and quickly generate beautiful messages for telegram bots using templates described in json.

Supported functions

  • Rendering a line with progress bar
  • Rendering a line with emoji
  • Rendering a simple string

Environment variables

Variable Description Default value
MESSAGES_CONFIG Json file with templates for rendering messages. Example configs/messages.json

Installing with Poetry

tee -a pyproject.toml <<EOF
[tool.poetry]
name = myproject"
version = "1.0.0"

[tool.poetry.dependencies]
python = "^3.12"
messages = { git = "https://github.com/obervinov/messages-package.git", tag = "v2.0.0" }

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
EOF

poetry install

Usage examples

Simple message with emoji

  1. Creating configs/messages.json and adding an example template
    • all emojis should be wrapped in :
    • all variables must be specified in the same form as in your code
{
    "templates": {
        "hello_message": {
            "text": "Hi, <b>{0}</b>! {1}\nAccess for your account - allowed {2}",
            "args": ["username", ":raised_hand:", ":unlocked:"]
        }
    }
}
# Import module
from messages import Messages

# Create instance
messages = Messages()

# Rendering and getting messages
print(
    messages.render_template(
        template_alias='hello_message',
        username="obervinov"
    )
)

output result

Hi, <b>obervinov</b>! ✋
Access for your account - allowed 🔓

Simple message with progress bar

  1. Creating configs/messages.json and adding an example template
    • all emojis should be wrapped in :
    • all variables must be specified in the same form as in your code
{
    "templates": {
        "queue_message": {
            "text": "{0} Messages from the queue have already been processed\n{1}",
            "args": [":framed_picture:", "progressbar"]
        }
    }
}
# Import module
from messages import Messages

# Create instance
messages = Messages()

# Render and get messages with progress bar
print(
    messages.render_template(
        template_alias='queue_message',
        progressbar=messages.render_progressbar(
            total_count=100,
            current_count=19
        )
    )
)

output result

🏞 Messages from the queue have already been processed
[◾◾◾◾◾◾◾◾◾◾◾◾◾◾◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️]19%

GitHub Actions

Name Version
GitHub Actions Templates v2.0.0