GithubHelp home page GithubHelp logo

keralabots / tgrambot Goto Github PK

View Code? Open in Web Editor NEW
21.0 1.0 2.0 421 KB

TGramBot is a partially auto-generated and asynchronous Minimal Telegram Bot API framework in Python for bots

License: GNU General Public License v3.0

Python 100.00%
httpx telegram telegram-bot autogeneration hacktoberfest

tgrambot's People

Contributors

anandpskerala avatar sky-alin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tgrambot's Issues

Markup submodule support

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 tgrambot 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 tgrambot module core to import styles and other needed classes as from tgrambot import .... Or it’s quite pretty to add a separated file (text.py or markup.py for example) to import as from tgrambot.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 tgrambot context

from tgrambot import Bot
from tgrambot.text import Spoiler

bot = Bot("token", workers=50, parse_mode='MarkdownV2')

@bot.on_message(Filters.command('start'))
async def start_bot(c: Bot, m: Message):
    await c.send_message(m.chat.id, Spoiler("Hola Amigo!"))

tgrambot pip3 installation failed

I tried to install tgrambot, but it keeps raising an error.

/storage/emulated/0 $ pip3 install tgrambot
Collecting tgrambot
  Downloading TGramBot-0.0.1b1.tar.gz (36 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>        File "/data/data/ru.iiec.pydroid3/cache/pip-install-alvimup5/tgrambot_50d7f24ab9b644ba8ae2cbf4df223581/setup.py", line 6, in <module>
          from compiler import build_types, build_methods
        File "/data/data/ru.iiec.pydroid3/cache/pip-install-alvimup5/tgrambot_50d7f24ab9b644ba8ae2cbf4df223581/compiler/__init__.py", line 3, in <module>
          from .build_api import build_api
        File "/data/data/ru.iiec.pydroid3/cache/pip-install-alvimup5/tgrambot_50d7f24ab9b644ba8ae2cbf4df223581/compiler/build_api.py", line 10, in <module>
          from bs4 import BeautifulSoup
      ModuleNotFoundError: No module named 'bs4'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
/storage/emulated/0 $

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.