Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markup submodule support #17

Open
SKY-ALIN opened this issue Sep 24, 2022 · 5 comments
Open

Markup submodule support #17

SKY-ALIN opened this issue Sep 24, 2022 · 5 comments
Assignees

Comments

@SKY-ALIN
Copy link

Hello! I want to table a proposal to add a special submodule to generate Telegram-specific markup easily.

Motivation

A common markdown format that every programmer uses is really simple and doesn’t require special utils for that, but MarkdownV2 and HTML which let include spoiler, strikethrough and other telegram innovations are different. For example, MarkdownV2 also requires to escape 18 characters, and if it’s not, reject the request. This may make the task of designing markup generation for bots that include business logic complicated enough and I suppose it’s better to have a ready-made out-of-the-box solution for this.

Implementation suggestion

General explanation

I have recently worked on a related challenge and I’m writing this to propose to re-use my solution. It’s the telegram-text module. The general structure in the context of the pytgbot module I propose to implement is the following:

  • Add telegram-text as a dependency (maybe even optional)
  • Add support for message objects rendering depending on format mode (Markdown / MarkdownV2 / HTML) inside the message sending function
  • Add imports into the pytgbot module core to import styles and other needed classes as from pytgbot import .... Or it’s quite pretty to add a separated file (text.py or markup.py for example) to import as from pytgbot.text import ...

Why telegram-text module?

  • Include all rules for all markup modes
  • Almost entirely covered by tests
  • Fully documented
  • Open to contribute
  • Has a few presets and is easily expandable to add new

Example of the module:

from telegram_text import Bold, Italic, Underline

text = Underline(Bold("Bold") + "and" + Italic("italic") + "with underline.")

Usage example in the pytgbot context

from pytgbot import Bot
from pytgbot.text import Spoiler

API_KEY: str
CHAT: str

bot = Bot(API_KEY)

bot.send_message(CHAT, Spoiler("Example Text!"))
@SKY-ALIN
Copy link
Author

The same proposal for the teleflask framework 👨🏻‍💻

@luckydonald
Copy link
Owner

Interesting proposal.
I'll have a closer look next week.

@luckydonald luckydonald self-assigned this Sep 27, 2022
@SKY-ALIN
Copy link
Author

Ok. Also, I can help with the integration if you agree with the approach

@SKY-ALIN
Copy link
Author

Hi! What have you decided on this issue?

@Andreasannoeuzg
Copy link

from telegram_text import Bold, Italic, Underline

text = Underline(Bold("Bold") + "and" + Italic("italic") + "with underline.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants