Commit graph

224 commits

Author SHA1 Message Date
Jacob Bom
247577b2e2
Context based callbacks (#1100)
See https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-11.0 under Context based callbacks and Filters in handlers for a good guide on the changes in this commit.

* Change handlers so context is supported

* Attempt to make parameter "guessing" work on py < 3.5

* Document use_context in all handlers

* Add Context to docs

* Minor fixes to context handling

* Add tests for context stuff

* Allow the signature check to work on py<3.5 with methods

* Fix order of operations

* Address most issues raised in CR

* Make CommandHandler no longer support filter lists

* Fix indent

(pycharm can be an arse sometimes)

* Improve readability in conversationhandler

* Make context have Match instead of groups & groupdict

* Remove filter list support from messagehandler too

* Small fix to StringCommandHandler

* More small fixes to handlers

* Amend CHANGES

* Fix tests and fix bugs raised by tests

* Don't allow users to ignore errors without messing with the warning filters themselves

* Ignore our own deprecation warnings when testing

* Skipping deprecationwarning test on py2

* Forgot some changes

* Handler: Improved documentation and text of deprecation warnings

* HandlerContext: Keep only dispatcher and use properties; improved doc

* Complete fixing the documentation.

 - Fixes per Eldinnie's comments.
 - Fixes per warnings when running sphinx.

* Some small doc fixes (interlinks and optionals)

* Change add_error_handler to use HandlerContext too

* More context based changes

Context Based Handlers -> Context Based Callbacks

No longer use_context args on every single Handler

Instead set dispatcher/updater .use_context=True to use

Works with
- Handler callbacks
- Error handler callbacks
- Job callbacks

Change examples to context based callbacks so new users are not confused

Rename and move the context object from Handlers.HandlerContext to CallbackContext, since it doesn't only apply to handlers anymore.

Fix tests by adding a new fixture `cpd` which is a dispatcher with use_context=True

* Forgot about conversationhandler

* Forgot jobqueue

* Add tests for callbackcontext & for context based callback job

* Fix as per review :)
2018-05-21 15:00:47 +02:00
Dillon Flamand
ef74c525b2 Simplify sentence in examples/README.md (#1061) 2018-04-19 15:20:16 +03:00
Noam Meltzer
baec1bb554 flake8 revamp
- Use pre-commit v1.2.0 flake8
 - Make sure we're running flake8 on examples and tests
 - Fix what had to be fixed
2018-02-19 12:41:38 +02:00
Willem
c19e464324 README.md: Fixed link to paymentbot example (#983)
[ci skip]
2018-02-12 15:32:35 +02:00
Eldinnie
0faa19726a wrong link to paymentbot (#942)
[CI skip]
2017-12-30 15:17:36 +02:00
Jacob Bom
2719c54899 Small changes to the examples readme (#893)
- Add paymentbot.py
- More docs links
2017-12-06 13:26:51 +01:00
Simon Schürrle
38637ecf62 Update examples with consistent string formatting (#870)
* Use the modern string.format().
* Wherever logging is involved, let logging take care of the expansion.
2017-10-20 21:24:00 +03:00
saschalalala
3863b4f371 Rename shortcut functions to snake_case (#661)
* Rename shortcut functions to snake_case

* More function renaming

* Example function rewrite

* Add myself to authors.rst

* More function renaming

* Rename mockbot test functions

* Break comment line for flake max line length
2017-06-14 00:07:03 +02:00
Jeff
c7ed87d475 add telegram doc link comment 2017-06-11 04:30:21 +08:00
Jeff
ad603bd2f9 add new payment example 2017-06-11 03:43:38 +08:00
Noam Meltzer
137ffe2e73 Merge remote-tracking branch 'origin/master' into payment 2017-06-01 22:01:04 +03:00
Jacob Bom
76db279624 We have to send and array... that's new... 2017-05-20 18:46:39 +02:00
Jannes Höke
6479e15578 Bump version to v6.0.0 2017-05-19 21:49:01 +02:00
Rahiel Kasim
0507378509 fix typo's (#523) and comment out failing sticker test 2017-02-18 16:03:50 +01:00
Jannes Höke
a37add39f4 [ci skip] update timerbot.py to use chat_data 2016-12-13 21:57:37 +01:00
Noam Meltzer
acf1541395 Botapi2.3 (#471)
* New fields channel_post and edited_channel_post for Update

refs #468

* setGameScore() changes

 - Changed behaviour: messages with high scores will be update with new
   high scores by default. (documentation fix)
 - Use (new) disable_edit_message in setGameScore to disable the above new
   behaviour.
 - The edit_message parameter from setGameScore is no longer in use. For
   backward compatibility, it will be taken into account for a while,
   unless disable_edit_message is passed explicitly.

refs #468

* New field forward_from_message_id for Message.

refs #468

* New parameter cache_time for answerCallbackQuery

refs #468

* replykeyboardhide renamed to replykeyboardremove

refs #468

* Unitests for updated setGameScore semantics

refs #468

* Backward compatibility for ReplyKeyboardHide

refs #468

* Fix docstrings of wrapper methods in Message

* Unitest new field forward_from_message_id of Message

refs #468

* Fix testMaxCaptionLength

Telegram servers changed their behaviour - now they truncate a long
caption instead of returning an error.

* MessageHandler: Added support for channel posts

* Fix flake8 complaints in a manner which yapf will like it too.

* fix rst markup
2016-12-11 22:44:52 +01:00
Blue
a7bfb0c3a1 hide inline keyboard in conversationbot example (#439) 2016-11-08 22:14:11 +01:00
Jannes Höke
b22c3cc5c0 [ci skip] add state diagrams for conversation handler examples 2016-10-28 08:26:02 +02:00
Jannes Höke
3f30f74024 update examples to use bitwise filters 2016-10-25 19:51:56 +02:00
Jannes Höke
79fc3be9cd Update README.md 2016-10-25 19:37:19 +02:00
Jannes Höke
71c73bdc74 Update README.md 2016-10-25 19:36:57 +02:00
Jannes Höke
10bdf8212c Add pass_user_data and pass_chat_data to Handler (#436)
* initial commit for user_data

* add chat_data and use defaultdict

* fix chat_data copy-paste error

* add test for user_data and chat_data

* fix case where chat is None

* remove braces from import line
2016-10-25 19:28:34 +02:00
Jannes Höke
fae1896232 Switch to readthedocs (#443)
* replace pythonhosted by readthedocs

* fix rtd links in examples/README
2016-10-19 18:00:33 +02:00
Jannes Höke
9d0e0386d9 Link echobot2 example from master 2016-09-24 16:30:39 +02:00
Jannes Höke
be675f0118 update all examples to use instance methods (#421) 2016-09-24 15:32:22 +02:00
Jannes Höke
05fb9d161a Link echobot2 example from tag v5.0 2016-09-23 17:13:06 +02:00
Jannes Höke
5116a77221 Class methods (#362)
* bot.py: add create_references method

* create bot reference in webhook handler, use create_references on new updates

* message.py: implement reply_text

* echobot2.py: use Message.reply_text

* fix create_references in webhook handler

* add some more instance methods

* Chat.kick_member and unban_member

* bot.py: Create bot references in outgoing messages

* add tests for everything testable

* test_updater.py: add create_references method to MockBot

* remove Bot.create_references and refactor TelegramObject.de_json to take the additional parameter bot

* List bot as named kwarg where used

* file.py: Use Bot.request property instead of Bot._request attr
2016-09-20 06:36:55 +02:00
eugenio412
e9c5ee7ad6 unset but (#383)
solved the bug that prevented the unset to work
2016-08-16 21:13:31 +02:00
Ilya Strukov
dd4c0f0f1d Add missing return statement in timerbot example (#368) 2016-08-07 17:59:58 +02:00
Jannes Höke
9d4691e50d Create README.md 2016-07-24 02:35:01 +02:00
Jannes Höke
f5c57cd6c6 new inlinekeyboard example (#355) 2016-07-20 00:15:03 +02:00
Jannes Höke
d5486433e5 use job context for timerbot example 2016-07-15 01:46:27 +02:00
Jannes Höke
c9ec436d68 remove old state machine example 2016-07-15 01:45:43 +02:00
Jannes Höke
ad3eec2af8 ConversationHandler (#331)
* initial commit for conversationhandler and example

* implement simple Promise for run_async/conversationhandler

* refactor Promise._done to done

* add handling for timed out Promises

* correctly handle promises with None results

* fix handling tuple states

* update comments on example

* Added a first test on the ConversationHandler.

* Fixed a small typo.

* Yapf'd.

* add sphinx doc for conversation handler

* fix title for callbackqueryhandler sphinx docs
2016-07-15 01:30:54 +02:00
Jannes Höke
738e3213a7 Merge branch 'master' into jobqueue-rework 2016-06-20 00:49:01 +02:00
Rahiel Kasim
e10fa66286 echobot: simplify handling messageless updates 2016-06-12 17:06:03 +02:00
Rahiel Kasim
deb9de0ba0 README: remove roboed, rename example 2016-06-12 16:58:18 +02:00
Rahiel Kasim
94fd6851ab more robust echobot, let roboed go 2016-06-12 15:30:56 +02:00
Jannes Höke
98be6abc11 Remove clibot.py example 2016-05-31 21:07:47 +02:00
Jannes Höke
de2d732135 Merge branch 'master' into jobqueue-rework
Conflicts:
	README.rst
	telegram/ext/commandhandler.py
	telegram/ext/messagehandler.py
2016-05-31 15:34:36 +02:00
Jannes Höke
e7f4a07b7a update timerbot example with pass_job_queue 2016-05-26 14:48:50 +02:00
Leandro Toledo
86571bc75d addHandler to add_handler 2016-05-26 01:55:51 -03:00
Jannes Höke
b3142d2974 yapf 2016-05-25 23:57:29 +02:00
Jannes Höke
3aedd78e29 make job queue API similar to the dispatcher, add new functionality 2016-05-25 23:36:41 +02:00
leandrotoledo
6bfdff8892 Update examples to column width to 99 [ci skip] 2016-05-23 17:45:01 -03:00
leandrotoledo
c7db9a96cd Set split_before_logical_operator to True 2016-05-23 17:19:35 -03:00
Rahiel Kasim
5971cb35f8 fix merge conflict snakes with master 2016-04-30 14:56:48 +02:00
Jannes Höke
6e5302c089 pass args in timerbot example #270 2016-04-30 10:19:41 +02:00
Rahiel Kasim
73c60ee817 simpler py2/py3 input in clibot example 2016-04-28 17:32:10 +02:00
Rahiel Kasim
474d5f0c9f update README and examples to new snake_case methods 2016-04-28 17:29:34 +02:00
Leandro Toledo
998040da92 Update clibot.py
Changes group=str to int
2016-04-27 22:10:31 -03:00
Noam Meltzer
3f28633e79 MessageHandler / filters: refactor
filters are now functions instead of enum like objects.
their definitions were moved to messagehandler.py
2016-04-26 17:47:37 +03:00
Jannes Höke
d383c10d4e remove check for inline_query 2016-04-22 15:36:46 +02:00
Jannes Höke
4faa4774bd Remove bot token 2016-04-22 09:11:52 +02:00
Jannes Höke
1544f612ae remove cancel command 2016-04-16 21:11:41 +02:00
Jannes Höke
53d1d5f589 fix cancel command 2016-04-16 21:09:24 +02:00
Jannes Höke
6992a7a369 fix key error 2016-04-16 21:03:30 +02:00
Jannes Höke
90576de9e2 inline keyboard example works 2016-04-16 20:55:43 +02:00
Jannes Höke
63c793aad4 initial example for inline keyboard 2016-04-16 20:32:44 +02:00
Jannes Höke
360c3077ea update examples 2016-04-16 19:25:08 +02:00
Avanatiker
0342a5b30b Update timerbot.py
The missing space bothered me.
2016-04-11 13:36:59 +03:00
kiddick@users.noreply.github.com
a264530540 Fix obsolete import for fsm bot. 2016-03-26 19:00:05 +03:00
Jannes Höke
5e7f2688be add encoding to fsm example bot 2016-03-22 02:33:43 +01:00
Jannes Höke
7199d2894f add state machine example 2016-03-21 20:08:32 +01:00
Jannes Höke
af62c5be8e update examples to telegram.ext 2016-03-19 16:39:35 +01:00
Jannes Höke
e2cc8db992 Merge branch 'master' into inlinebots 2016-02-20 11:17:34 +01:00
Rahiel Kasim
3e978277b3 echobot: simplify exception handling 2016-02-09 15:28:54 +01:00
Jannes Höke
c69cdfd184 Initial commit for inline bot support 2016-01-09 15:09:48 +01:00
Karan Sharma
14a9962296 handle case of negative values of seconds 2016-01-05 19:06:28 +05:30
Jannes Höke
4197400853 remove token once again 2016-01-05 14:29:20 +01:00
Jannes Höke
8175fd7b53 update timerbot example 2016-01-05 13:39:51 +01:00
Jannes Höke
81b58c7d00 remove bot token (once again...) 2016-01-04 01:58:50 +01:00
Jannes Höke
dd7d1255d1 fixes, tests and examples for job queue 2016-01-04 01:56:22 +01:00
Rahiel Kasim
90ed128a61 dedicate examples to the public domain (CC0) 2015-12-25 15:19:17 +01:00
Jannes Höke
2a2b679362 improved and renamed examples 2015-12-22 13:23:59 +01:00
Jannes Höke
ea7c54ba07 Release v3.1.1, change author email everywhere 2015-12-21 21:18:53 +01:00
Jannes Höke
c15a1bc151 fix for #123 2015-12-21 19:36:17 +01:00
Jannes Höke
a13245dfbf change 'wb' to 'rb' in certificate open call 2015-12-09 12:59:34 +01:00
Jannes Höke
185bff7117 update example 2015-12-01 18:06:42 +01:00
Jannes Höke
628a4c4eac final renaming of files and flake8 2015-11-24 21:06:55 +01:00
Jannes Höke
1005ad57ce Improve signal handling 2015-11-23 17:40:39 +01:00
Jannes Höke
8d267ed896 use logging 2015-11-22 19:20:16 +01:00
Jannes Höke
593153128c Update examples 2015-11-22 19:15:37 +01:00
Jannes Höke
15501e185b renamed broadcaster.py to dispatcher.py 2015-11-22 14:52:41 +01:00
Jannes Höke
1782d0d19b refactor Broadcaster to Dispatcher 2015-11-22 14:47:38 +01:00
Jannes Höke
628e1b743a add bits of documentation 2015-11-22 13:58:40 +01:00
Jannes Höke
cccd6e5baf Merge branch 'master' of github.com:leandrotoledo/python-telegram-bot into boteventhandler 2015-11-21 03:29:37 +01:00
Rahiel Kasim
62b79df0a4 handle "Unauthorized" exceptions in echobot 2015-11-20 14:41:12 +01:00
Jannes Höke
be368f7d74 add example for webhook 2015-11-17 00:30:21 +01:00
Jannes Höke
0b8fd24771 fixed issues with python2 2015-11-16 20:35:27 +01:00
Jannes Höke
ba3d174fde Change eh.start() to eh.start_polling() 2015-11-16 13:05:17 +01:00
Jannes Höke
ab313488ad Usage instructions for bots 2015-11-15 20:13:03 +01:00
Jannes Höke
d808462fb6 Simple bot 2015-11-15 20:02:09 +01:00
Jannes Höke
71e73c3999 logging 2015-11-15 19:21:35 +01:00
Jannes Höke
a55df8b5e1 update example 2015-11-15 19:14:12 +01:00
Jannes Höke
ae59a18e2d update example 2015-11-15 17:37:01 +01:00
Jannes Höke
04050ca883 Merge branch 'master' of github.com:leandrotoledo/python-telegram-bot into boteventhandler 2015-11-13 11:05:26 +01:00
Rahiel Kasim
ff0d724f32 improve echobot with cleaner code and basic exception handling 2015-11-12 17:26:25 +01:00
Jannes Höke
3162bc60e9 cleaned up code 2015-11-11 13:32:11 +01:00
Jannes Höke
401add78d3 fix big mistake 2015-11-10 23:15:37 +01:00
Jannes Höke
af375eb402 improved code quality 2015-11-10 23:15:37 +01:00
Jannes Höke
d7d4889c50 use run_async decorator in example 2015-11-10 23:15:37 +01:00
Jannes Höke
c1fae0b5ee example bot for BotEventHandler 2015-11-10 23:15:37 +01:00
Jannes Höke
0f8f6584ce Fix for issue #81 2015-11-10 20:36:26 +01:00
Francisco Demartino
bd1f171f51 Remove .encode('utf-8') from echobot
This was making the bot throw TypeError on py3.

Closes #86
2015-10-23 16:48:26 -03:00
Leandro Toledo
a1f35355f6 Keep bleeding edge features on testing branch 2015-09-20 12:43:32 -03:00
Leandro Toledo
f623db06ea Revert "Feature/requests" 2015-09-16 00:21:45 -03:00
leandrotoledo
30749c3b66 Merging testing 2015-09-04 23:21:31 -03:00
leandrotoledo
121e365348 Oops, restoring file on testing 2015-09-04 19:07:20 -03:00
leandrotoledo
d740ce89cf Keep off some features still in progress 2015-09-04 18:11:47 -03:00
njittam
9241534ba6 Create command_handler_example.py
this is an example of how to write a commandHandler
2015-09-02 16:21:11 +02:00
rahiel
41eb45918c use long polling in examples 2015-08-24 11:46:33 +02:00
rahiel
0691b1e971 confirm processed message in examples 2015-08-20 19:58:57 +02:00
Leandro Toledo
163b27b7dd fix license header 2015-08-11 16:58:17 -03:00
Leandro Toledo
59b247af94 Moving from GPLv2 to LGPLv3 2015-08-10 13:57:31 -03:00
Will Thompson
a034317c87 Don't call logging.basicConfig() in library code
Logging should be configured by the application, not by libraries it
uses. Libraries should just get a logger and log to it.

Fixes #21
2015-07-30 07:04:59 +01:00
leandrotoledo
6b7476c18f Updates echobot and getUpdates logging 2015-07-20 08:59:41 -03:00
leandrotoledo
9f27537176 Error handling when no updates available 2015-07-15 07:47:13 -03:00
leandrotoledo
7d8fcc5fb9 update examples 2015-07-14 04:31:20 -03:00
Leandro Toledo
649fbc40c8 Encode to UTF8 text messages 2015-07-12 10:30:35 -03:00
Leandro Toledo
2cee590ca8 fix unicode issue 2015-07-12 10:18:34 -03:00
Leandro Toledo
77930e0d8b Removing token 2015-07-12 09:56:50 -03:00
Leandro Toledo
582bb61e5b Adding echobot example and fix IOError typo 2015-07-12 09:54:03 -03:00
Leandro Toledo
c3ea91e68c Adding RoboEd as example 2015-07-08 00:59:43 -03:00