Telethon/readthedocs/examples/working-with-messages.rst

46 lines
1.4 KiB
ReStructuredText
Raw Normal View History

=====================
2017-11-19 19:56:05 +03:00
Working with messages
=====================
2017-11-20 07:12:31 +03:00
.. note::
2019-05-09 13:24:37 +03:00
These examples assume you have read :ref:`full-api`.
2018-10-06 21:20:11 +03:00
.. contents::
2017-11-19 19:56:05 +03:00
Sending stickers
2019-05-09 13:24:37 +03:00
================
Stickers are nothing else than ``files``, and when you successfully retrieve
the stickers for a certain sticker set, all you will have are ``handles`` to
these files. Remember, the files Telegram holds on their servers can be
referenced through this pair of ID/hash (unique per user), and you need to
use this handle when sending a "document" message. This working example will
send yourself the very first sticker you have:
2017-11-19 19:56:05 +03:00
.. code-block:: python
2017-11-19 19:56:05 +03:00
2018-06-25 22:14:58 +03:00
# Get all the sticker sets this user has
from telethon.tl.functions.messages import GetAllStickersRequest
sticker_sets = await client(GetAllStickersRequest(0))
2018-06-25 22:14:58 +03:00
# Choose a sticker set
from telethon.tl.functions.messages import GetStickerSetRequest
from telethon.tl.types import InputStickerSetID
sticker_set = sticker_sets.sets[0]
# Get the stickers for this sticker set
stickers = await client(GetStickerSetRequest(
2018-06-25 22:14:58 +03:00
stickerset=InputStickerSetID(
id=sticker_set.id, access_hash=sticker_set.access_hash
)
))
# Stickers are nothing more than files, so send that
await client.send_file('me', stickers.documents[0])
2017-11-19 19:56:05 +03:00
.. _issues: https://github.com/LonamiWebs/Telethon/issues/215