Python module for screenshoting telegram messages.
pip install git+https://github.com/grinrill/tgquote
from tgquote import TelegramImageRenderer
from tgquote.renderers import HtmlCssToImageRenderer
from tgquote.filegetters import DefaultFileGetter
from aiogram import Bot, Dispatcher, executor, types
bot = Bot('your bot token')
dp = Dispatcher(bot)
quoter = TelegramImageRenderer(
HtmlCssToImageRenderer(
api_id = 'your htmlcsstoimage.com api_id',
api_key = 'your htmlcsstoimage.com api_key',
api_url='https://htmlcsstoimage.com/demo_run'
# I use demo apis for tests
# I DO NOT RECOMMEND using the demo api in the prod
# also instead of htmlcsstoimage.com you can use pyppeteer for local rendering
# see below in the readme
),
DefaultFileGetter(bot),
append_css='body {background-color: grey}',
# by default background is transparent
)
@dp.message_handler(
content_types=types.ContentTypes.ANY
)
async def handler(message):
await message.chat.do('upload_photo')
f = await quoter.render(message)
await message.reply_photo(f)
executor.start_polling(dp, skip_updates=True)
Render engine object should be provided as the first argument in TelegramImageRenderer
.
Currently two renderers available: HtmlCssToImageRenderer
using htmlcsstoimage.com api and PyppeteerRenderer
using pyppeteer.
You need api_id and api_key to use this api, you can get it here: https://htmlcsstoimage.com/dashboard/api-keys.
render_engine = HtmlCssToImageRenderer(
api_id = 'your htmlcsstoimage.com api_id',
api_key = 'your htmlcsstoimage.com api_key'
)
You need to install pyppeteer: https://github.com/miyakogi/pyppeteer#installation.
render_engine = PyppeteerRenderer()