-
Notifications
You must be signed in to change notification settings - Fork 27
Callback query and inline keyboards support #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """ | ||
| botogram.messages | ||
| Logic for callbacks sent to your bot | ||
|
|
||
| Copyright (c) 2016 Pietro Albini <pietro@pietroalbini.io> | ||
| Released under the MIT license | ||
| """ | ||
|
|
||
|
|
||
| def process_callback(bot, chains, update): | ||
| for hook in chains["callback_query"]: | ||
| bot.logger.debug("Processing callback query in update #%s with the " | ||
| "hook %s..." % (update.update_id, hook.name)) | ||
|
|
||
| result = hook.call(bot, update) | ||
| if result is True: | ||
| bot.logger.debug("Update %s was just processed by the %s hook." % | ||
| (update.update_id, hook.name)) | ||
| return | ||
|
|
||
| bot.logger.debug("No hook actually processed the #%s update." % | ||
| update.update_id) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """ | ||
| botogram.objects.callback_query | ||
| Representation of the callback query-related upstream API objects | ||
|
|
||
| Copyright (c) 2015 Pietro Albini <pietro@pietroalbini.io> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be you, not me, and we're not in 2015.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it's your work 🥇
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did nothing on that file: the copyright notice should be of the single file, not of the whole project, and you're the author of that file :) |
||
| Released under the MIT license | ||
| """ | ||
|
|
||
| from .base import BaseObject | ||
|
|
||
| from .messages import User, Message | ||
| from . import mixins | ||
|
|
||
|
|
||
| class CallbackQuery(BaseObject, mixins.CallbackMixin): | ||
| """Telegram API representation of a callback query | ||
|
|
||
| https://core.telegram.org/bots/api#callbackquery | ||
| """ | ||
|
|
||
| required = { | ||
| "id": str, | ||
| "from": User, | ||
| "message": Message, | ||
| "chat_instance": str, | ||
| } | ||
| optional = { | ||
| "inline_message_id": str, | ||
| "data": str, | ||
| "game_short_name": str, | ||
| } | ||
| replace_keys = { | ||
| "from": "sender", | ||
| } | ||
|
|
||
| def __init__(self, data, api=None): | ||
| super().__init__(data, api) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ about its business. | |
| * :py:class:`~botogram.ReplyKeyboardMarkup` | ||
| * :py:class:`~botogram.ReplyKeyboardHide` | ||
| * :py:class:`~botogram.ForceReply` | ||
| * :py:class:`~botogram.CallbackQuery` | ||
|
|
||
|
|
||
| .. py:class:: botogram.User | ||
|
|
@@ -2077,6 +2078,47 @@ about its business. | |
| *This attribute can be None if it's not provided by Telegram.* | ||
|
|
||
|
|
||
| .. py:class:: botogram.CallbackQuery | ||
|
|
||
| This class represents a callback query received by the bot. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot the version this is added to. |
||
| .. py:attribute:: id | ||
|
|
||
| The id of the callback. | ||
|
|
||
| .. py:attribute:: sender | ||
|
|
||
| The :py:class:`~botogram.User` that sent the callback query. | ||
|
|
||
| .. py:attribute:: message | ||
|
|
||
| The :py:class:`~botogram.Message` that was attached to the button that originated the query. | ||
|
|
||
| *This attribute can be None if it's not provided by Telegram.* | ||
|
|
||
| .. py:attribute:: inline_message_id | ||
|
|
||
| The id of the message sent via the bot in inline mode that was attached to the button that originated the query. | ||
|
|
||
| *This attribute can be None if it's not provided by Telegram.* | ||
|
|
||
| .. py:attribute:: chat_instance | ||
|
|
||
| The chat to which the message with the callback button was sent. | ||
|
|
||
| .. py:attribute:: data | ||
|
|
||
| Data associated with the callback button. | ||
|
|
||
| *This attribute can be None if it's not provided by Telegram.* | ||
|
|
||
| .. py:attribute:: game_short_name | ||
|
|
||
| Short name of a Game to be returned, serves as the unique identifier for the game. | ||
|
|
||
| *This attribute can be None if it's not provided by Telegram.* | ||
|
|
||
|
|
||
| .. _Telegram's Bot API: https://core.telegram.org/bots/api | ||
| .. _API methods: https://core.telegram.org/bots/api#available-methods | ||
| .. _API types: https://core.telegram.org/bots/api#available-types | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename this to
add_callback_hookto be consistent with@bot.callback?