Skip to content

Commit b517949

Browse files
committed
Send stickers by ID or URL
1 parent b7513aa commit b517949

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

botogram/objects/mixins.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,34 @@ def send_venue(self, latitude, longitude, title, address, foursquare=None,
273273
self._api.call("sendVenue", args, expect=_objects().Message)
274274

275275
@_require_api
276-
def send_sticker(self, sticker, reply_to=None, extra=None, attach=None,
277-
notify=True):
276+
def send_sticker(self, sticker=None, reply_to=None, extra=None,
277+
attach=None, notify=True, *,
278+
path=None, file_id=None, url=None):
278279
"""Send a sticker"""
280+
if sticker is not None:
281+
if path is not None:
282+
raise TypeError("The sticker argument is overridden by " +
283+
"the path one")
284+
path = sticker
285+
_deprecated_message(
286+
"The sticker parameter", "1.0", "use the path parameter", -3
287+
)
288+
279289
args = self._get_call_args(reply_to, extra, attach, notify)
290+
if path is not None and file_id is None and url is None:
291+
files = {"sticker": open(path, "rb")}
292+
elif file_id is not None and path is None and url is None:
293+
files = None
294+
args["sticker"] = file_id
295+
elif url is not None and file_id is None and path is None:
296+
args["sticker"] = url
297+
files = None
298+
elif path is None and file_id is None and url is None:
299+
raise TypeError("path or file_id or URL is missing")
300+
else:
301+
raise TypeError("Only one among path, file_id and URL must be " +
302+
"passed")
280303

281-
files = {"sticker": open(sticker, "rb")}
282304
return self._api.call("sendSticker", args, files,
283305
expect=_objects().Message)
284306

docs/api/telegram.rst

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,12 @@ about its business.
412412

413413
.. versionadded:: 0.3
414414

415-
.. py:method:: send_sticker(sticker, [reply_to=None, attach=None, extra=None, notify=True])
415+
.. py:method:: send_sticker([sticker=None, reply_to=None, attach=None, extra=None, notify=True, path=None, file_id=None, url=None])
416416
417-
Send the sticker to the user (in webp format). If the sticker you're
418-
sending is in reply to another message, set *reply_to* to the ID of the
419-
other :py:class:`~botogram.Message`.
417+
Send the sticker to the user (in webp format). You can specify the sticker by
418+
passing its *path*, its *url*, or its Telegram *file_id*. Only one of these
419+
arguments must be passed. If the sticker you're sending is in reply to another message,
420+
set *reply_to* to the ID of the other :py:class:`~botogram.Message`.
420421

421422
The *attach* parameter allows you to attach extra things like
422423
:ref:`buttons <buttons>` to the message.
@@ -429,12 +430,19 @@ about its business.
429430
:param object attach: An extra thing to attach to the message.
430431
:param object extra: An extra reply interface object to attach
431432
:param bool notify: If you want to trigger the client notification.
433+
:param str path: The path to the webp-formatted sticker
434+
:param str file_id: The Telegram *file_id* of the sticker
435+
:param str url: The URL to the webp-formatted sticker
432436
:returns: The message you sent
433437
:rtype: ~botogram.Message
434438

435439
.. deprecated:: 0.4
436440

437441
The *extra* parameter is now deprecated
442+
443+
.. deprecated:: 0.6
444+
445+
The *sticker* parameter is now deprecated
438446

439447
.. versionchanged:: 0.3
440448

@@ -1053,11 +1061,12 @@ about its business.
10531061

10541062
.. versionadded:: 0.3
10551063

1056-
.. py:method:: send_sticker(sticker, [reply_to=None, attach=None, extra=None, notify=True])
1064+
.. py:method:: send_sticker([sticker=None, reply_to=None, attach=None, extra=None, notify=True, file_id=None, url=None])
10571065
1058-
Send the sticker to the chat (in webp format). If the sticker you're
1059-
sending is in reply to another message, set *reply_to* to the ID of the
1060-
other :py:class:`~botogram.Message`.
1066+
Send the sticker to the chat (in webp format). You can specify the sticker by
1067+
passing its *path*, its *url*, or its Telegram *file_id*. Only one of these
1068+
arguments must be passed. If the sticker you're sending is in reply to another message,
1069+
set *reply_to* to the ID of the other :py:class:`~botogram.Message`.
10611070

10621071
The *attach* parameter allows you to attach extra things like
10631072
:ref:`buttons <buttons>` to the message.
@@ -1070,12 +1079,19 @@ about its business.
10701079
:param object attach: An extra thing to attach to the message.
10711080
:param object extra: An extra reply interface object to attach
10721081
:param bool notify: If you want to trigger the client notification.
1082+
:param str path: The path to the webp-formatted sticker
1083+
:param str file_id: The Telegram *file_id* of the sticker
1084+
:param str url: The URL to the webp-formatted sticker
10731085
:returns: The message you sent
10741086
:rtype: ~botogram.Message
10751087

10761088
.. deprecated:: 0.4
10771089

10781090
The *extra* parameter is now deprecated
1091+
1092+
.. deprecated:: 0.6
1093+
1094+
The *sticker* parameter is now deprecated
10791095

10801096
.. versionchanged:: 0.3
10811097

docs/changelog/0.6.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,15 @@ New features
3232
* New argument ``syntax`` in :py:meth:`botogram.User.send_video`
3333
* New argument ``syntax`` in :py:meth:`botogram.User.send_voice`
3434
* New argument ``syntax`` in :py:meth:`botogram.Message.edit_caption`
35+
36+
* Added support for sending stickers by ID or URL
37+
38+
* New arguments ``path``, ``file_id`` and ``url`` in :py:meth:`botogram.Chat.send_sticker`
39+
* New arguments ``path``, ``file_id`` and ``url`` in :py:meth:`botogram.User.send_sticker`
40+
41+
Deprecated features
42+
-------------------
43+
44+
Deprecated features will be removed in botogram 1.0!
45+
46+
* The ``sticker`` parameter in :py:meth:`botogram.Chat.send_sticker` and :py:meth:`botogram.User.send_sticker` is now deprecated

0 commit comments

Comments
 (0)