Skip to content

Commit 311210e

Browse files
author
Pietro Albini
committed
Add ability to send sticker
Added and documented the following methods: * botogram.Bot.send_sticker * botogram.User.send_sticker * botogram.Chat.send_sticker * botogram.Message.reply_with_sticker
1 parent 6bc88c3 commit 311210e

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

botogram/frozenbot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def _call(self, func, component=None, **available):
215215
objects.Chat.send_video,
216216
objects.Chat.send_file,
217217
objects.Chat.send_location,
218+
objects.Chat.send_sticker,
218219
]
219220

220221
for _proxy in _proxied_sends:

botogram/objects/mixins.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ def send_location(self, latitude, longitude, reply_to=None, extra=None):
124124

125125
self._api.call("sendLocation", args)
126126

127+
@_require_api
128+
def send_sticker(self, sticker, reply_to=None, extra=None):
129+
"""Send a sticker"""
130+
args = self._get_call_args(reply_to, extra)
131+
132+
files = {"sticker": open(sticker, "rb")}
133+
self._api.call("sendSticker", args, files)
134+
127135

128136
class MessageMixin:
129137
"""Add some methods for messages"""
@@ -177,6 +185,11 @@ def reply_with_location(self, latitude, longitude, extra=None):
177185
"""Reply with a geographic location to the current chat"""
178186
self.chat.send_location(latitude, longitude, self.message_id, extra)
179187

188+
@_require_api
189+
def reply_with_sticker(self, sticker, extra=None):
190+
"""Reply with a sticker to the current message"""
191+
self.chat.send_sticker(sticker, self.message_id, extra)
192+
180193

181194
class FileMixin:
182195
"""Add some methods for files"""

docs/api/bot.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,25 @@ components.
453453
:param float longitude: The longitude of the location
454454
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
455455
:param object extra: An extra reply interface object to attach
456+
457+
.. py:method:: send_sticker(sticker, [reply_to=None, extra=None])
458+
459+
This method sends a sticker to a specific chat chat (in webp format). The
460+
chat must be identified by its ID, and Telegram applies some restrictions
461+
on the chats allowed to receive your locations: only users who sent you a
462+
message in the past are allowed, and also the group chats your bot is
463+
currently in.
464+
465+
If the sticker you're sending is in reply to another message, set
466+
*reply_to* to the ID of the other :py:class:`~botogram.Message`. *extra*
467+
is an optional object which specifies additional reply interface options
468+
on the recipient's end, and can be one of the following types:
469+
470+
* :py:class:`botogram.ReplyKeyboardMarkup`
471+
* :py:class:`botogram.ReplyKeyboardHide`
472+
* :py:class:`botogram.ForceReply`
473+
474+
:param int chat: The ID of the chat which should receive the location
475+
:param str sticker: The path to the webp-formatted sticker
476+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
477+
:param object extra: An extra reply interface object to attach

docs/api/telegram.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ about its business.
220220
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
221221
:param object extra: An extra reply interface object to attach
222222

223+
.. py:method:: send_sticker(sticker, [reply_to=None, extra=None])
224+
225+
Send the sticker to the user (in webp format). If the sticker you're
226+
sending is in reply to another message, set *reply_to* to the ID of the
227+
other :py:class:`~botogram.Message`. *extra* is an optional object which
228+
specifies additional reply interface options on the recipient's end, and
229+
can be one of the following types:
230+
231+
* :py:class:`botogram.ReplyKeyboardMarkup`
232+
* :py:class:`botogram.ReplyKeyboardHide`
233+
* :py:class:`botogram.ForceReply`
234+
235+
:param str sticker: The path to the webp-formatted sticker
236+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
237+
:param object extra: An extra reply interface object to attach
238+
223239

224240
.. py:class:: botogram.Chat
225241
@@ -403,6 +419,22 @@ about its business.
403419
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
404420
:param object extra: An extra reply interface object to attach
405421

422+
.. py:method:: send_sticker(sticker, [reply_to=None, extra=None])
423+
424+
Send the sticker to the chat (in webp format). If the sticker you're
425+
sending is in reply to another message, set *reply_to* to the ID of the
426+
other :py:class:`~botogram.Message`. *extra* is an optional object which
427+
specifies additional reply interface options on the recipient's end, and
428+
can be one of the following types:
429+
430+
* :py:class:`botogram.ReplyKeyboardMarkup`
431+
* :py:class:`botogram.ReplyKeyboardHide`
432+
* :py:class:`botogram.ForceReply`
433+
434+
:param str sticker: The path to the webp-formatted sticker
435+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
436+
:param object extra: An extra reply interface object to attach
437+
406438

407439
.. py:class:: botogram.Message
408440
@@ -708,6 +740,19 @@ about its business.
708740
:param float longitude: The longitude of the location
709741
:param object extra: An extra reply interface object to attach
710742

743+
.. py:method:: reply_with_sticker(sticker, [reply_to=None, extra=None])
744+
745+
Reply with the sticker (in webp format) to the chat. *extra* is an
746+
optional object which specifies additional reply interface options on the
747+
recipient's end, and can be one of the following types:
748+
749+
* :py:class:`botogram.ReplyKeyboardMarkup`
750+
* :py:class:`botogram.ReplyKeyboardHide`
751+
* :py:class:`botogram.ForceReply`
752+
753+
:param str sticker: The path to the webp-formatted sticker
754+
:param object extra: An extra reply interface object to attach
755+
711756

712757
.. py:class:: botogram.Photo
713758

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ botogram 1.0, and warnings are in place to notify you where to change what.
2626
New features
2727
------------
2828

29+
* Added the ability to send stickers
30+
31+
* New method :py:meth:`botogram.User.send_sticker`
32+
* New method :py:meth:`botogram.Chat.send_sticker`
33+
* New method :py:meth:`botogram.Bot.send_sticker`
34+
* New method :py:meth:`botogram.Message.reply_with_sticker`
35+
2936
* Added the :py:attr:`botogram.User.name` computed attribute
3037
* Added the :py:attr:`botogram.Chat.name` computed attribute
3138
* Added the :py:attr:`botogram.User.avatar` attribute

0 commit comments

Comments
 (0)