1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Compare commits

...

601 Commits
3.6.6 ... 3.8.3

Author SHA1 Message Date
6e871b8eb1 Merge pull request #1270 from Badiboy/master
Check and update for full compatibility to Bot API up to 5.3
2021-08-18 23:31:15 +03:00
f6359bc32c Readme fix 2021-08-18 23:29:40 +03:00
2bc052ad5a Check and update for full compatibility to Bot API up to 5.3
Pre-release of 4.0.0
2021-08-18 23:27:28 +03:00
022ef6a64c Dependecies clearing 2021-08-18 22:16:30 +03:00
3232811543 Merge pull request #1269 from Badiboy/master
Check and update for full compatibility to Bot API up to 5.0
2021-08-18 22:01:12 +03:00
fabcd93dd7 API update fix 03 2021-08-18 21:57:56 +03:00
8053183cb5 API update fix 02 2021-08-18 19:36:48 +03:00
b2b7d90888 API update fix 01 2021-08-18 19:32:43 +03:00
3e9d73c25d Merge remote-tracking branch 'upstream/master' 2021-08-18 18:52:09 +03:00
d6501ddc0e Check and update for full compatibility to Bot API up to 5.0 2021-08-18 18:47:38 +03:00
e818e3875d Merge pull request #1266 from coder2020official/master
New set of register_xxx_handler functions for dynamic handlers registering.
2021-08-17 16:50:00 +03:00
56cd3971dc Update __init__.py 2021-08-16 22:41:27 +04:00
958ca34e9c Merge pull request #1264 from coder2020official/master
Added skip_pending parameter to polling and infinity_polling in addition to skip_pending in Telebot.Init. Allows skip pending updates for already created Bot instances.
2021-08-16 21:07:41 +03:00
f4ef2366b6 Update skip_updates_example.py 2021-08-16 22:03:17 +04:00
f553960096 Update __init__.py 2021-08-16 22:00:08 +04:00
24ef64456b Update __init__.py 2021-08-16 14:53:00 +04:00
3e7da0fd18 Update skip_updates_example.py 2021-08-16 14:49:45 +04:00
2c0f42b363 Update __init__.py 2021-08-16 14:48:21 +04:00
1e4a6e2125 Update __init__.py 2021-08-15 13:32:11 +04:00
beeb60aab8 skip_updates 2021-08-15 11:40:13 +04:00
5b942a5b31 Merge pull request #1263 from coder2020official/master
Create chat_member_example.py
2021-08-14 17:55:15 +03:00
3e4a6cd702 Create chat_member_example.py 2021-08-14 18:46:45 +04:00
0e369953cb Merge pull request #1261 from Badiboy/master
BotCommandScopeChatMember fix
2021-08-12 15:17:11 +03:00
911e356930 BotCommandScopeChatMember fix 2021-08-12 15:16:04 +03:00
554b39a49a Merge pull request #1257 from AmolDerickSoans/master
Add IPO bot
2021-08-06 14:48:51 +03:00
ea16f35432 Add IPO bot
Listed oneIPO bot created using pyTelegramBotAPI in  section : Bpts using this API
2021-08-06 12:29:00 +05:30
81d94687be Merge pull request #1254 from snikidev/bug/InputInvoiceMessageContent-return-statement
🐛 Bugfix: Add return statement to to_dict() method inside InputInvoiceMessageContent type
2021-08-03 21:03:38 +03:00
4ba4bc18cf add extra space 2021-08-03 17:35:59 +01:00
c117ff2d50 Add return statement to to_dict() method inside InputInvoiceMessageContent 2021-08-03 17:34:29 +01:00
735c224444 Merge pull request #1248 from coder2020official/master
caption_entities in edit_message_caption
2021-07-30 19:11:05 +03:00
81adfd335e UPD 2021-07-30 19:15:37 +05:00
7ebe589b46 Update __init__.py 2021-07-28 23:10:15 +05:00
9c1b19a9e4 upd 2021-07-28 23:06:31 +05:00
02b886465e new filters 2021-07-25 15:46:53 +05:00
2d89ceb745 Merge pull request #1241 from Badiboy/master
Release version 3.8.2
2021-07-21 21:54:29 +03:00
ae8c3252df Release version 3.8.2 2021-07-21 21:53:56 +03:00
7914f71938 Merge pull request #1237 from monosans/comprehension
Replace for loops with comprehensions
2021-07-19 23:40:55 +03:00
097ba9fec2 Replace for loops with comprehensions 2021-07-19 20:03:03 +03:00
d09d9f0c09 Merge pull request #1232 from Badiboy/master
Invoice tips typo fix
2021-07-15 09:27:49 +03:00
29c98b0230 Invoice tips typo fix 2021-07-15 09:27:07 +03:00
2b1db1f1b3 Merge pull request #1231 from vnagornyy/master
Added tip for invoice
2021-07-15 09:23:10 +03:00
fa80b1dba0 Added tip for invoice 2021-07-15 08:56:04 +03:00
b45db584df Merge pull request #1230 from Badiboy/master
Fix worker_pool issue
2021-07-13 22:16:48 +03:00
f52ea635e5 Fix worker_pool issue 2021-07-13 22:09:56 +03:00
9b56afd569 Merge pull request #1229 from Badiboy/master
Fix CallbackQuery issue for games
2021-07-13 20:13:36 +03:00
6fb10e92e4 Fix CallbackQuery issue for games 2021-07-13 20:11:47 +03:00
fcf4d91564 Merge remote-tracking branch 'upstream/master' 2021-07-13 20:00:17 +03:00
38319871e6 Merge pull request #1225 from dannkunt/patch-1
Fix wrong type hint
2021-07-13 11:32:06 +03:00
2d0b092ea4 Fix wrong type hint
call.id gives int
2021-07-10 22:03:31 +03:00
060b8c61bb Merge remote-tracking branch 'upstream/master' 2021-07-09 10:50:53 +03:00
db2accc2f8 Merge pull request #1223 from Badiboy/master
Timeouts in making requests are rethought
2021-07-09 10:50:46 +03:00
798fda4c8a Merge remote-tracking branch 'upstream/master' 2021-07-09 10:50:03 +03:00
2578e48134 Timeouts in making requests are rethought 2021-07-09 10:42:56 +03:00
ac20216a7a Merge pull request #1222 from Badiboy/master
Preserve dict change in de_json routines
2021-07-08 13:43:09 +03:00
beb5a456eb Preserve dict change in Update 2021-07-08 09:35:48 +03:00
41faadd572 Merge pull request #1221 from AndydeCleyre/feature/mentioncolorcodebot
mention colorcodebot as a project using this library
2021-07-08 08:36:22 +03:00
a15016d7d9 mention colorcodebot as a project using this library 2021-07-07 13:00:32 -04:00
47dd84c441 Merge pull request #1216 from SwissCorePy/master
fixed bug
2021-07-01 20:04:37 +03:00
c7b360e982 fixed bug 2021-07-01 18:54:39 +02:00
09041b018f Merge pull request #1215 from SwissCorePy/master
Added the property `difference` to the class ChatMemberUpdated
2021-06-30 17:33:13 +03:00
3a4cf47def Merge branch 'master' of https://github.com/SwissCorePy/pyTelegramBotAPI 2021-06-30 14:16:54 +02:00
56e4f68a83 added the property difference to ChatMemberUpdated 2021-06-30 14:16:38 +02:00
484e7fccbd Merge pull request #1214 from SwissCorePy/master
new deprecated decorator
2021-06-30 15:01:46 +03:00
791d65e95a replaced old deprecated decorator 2021-06-30 13:47:39 +02:00
073d7fb6a7 Update util.py
whoops warn is not optional
2021-06-30 13:11:48 +02:00
a6668397e1 new deprecated decorator
added a new deprecated decorator to util
2021-06-30 13:08:05 +02:00
983d626d87 Merge pull request #1212 from Badiboy/master
Update file_name to visible_file_name in send_document
2021-06-29 13:31:25 +03:00
a4e73a05c6 Update file_name to visible_file_name in send_document 2021-06-29 13:30:01 +03:00
30e304ffb5 Merge pull request #1204 from floydya/file-name-patch
Allows to set visible document file_name on send.
2021-06-29 13:27:44 +03:00
430b34c7a2 Merge pull request #1210 from SwissCorePy/master
README update
2021-06-28 17:15:45 +03:00
b222416fd8 Update README.md 2021-06-28 15:44:49 +02:00
f8110cd046 Update README.md
* Added the new message_handlers
* Added some information about local Bot API Server
* Replaced the split_string with the smart_split function
2021-06-28 15:17:53 +02:00
6bc60f4aa9 Merge pull request #1208 from SwissCorePy/master
get_chat_member_count and ban_chat_member added.
get_chat_members_count and kick_chat_member are marked as deprecated.
2021-06-28 13:09:19 +03:00
b48a445e9f Update __init__.py
updated docstrings
2021-06-28 12:02:40 +02:00
0b383498eb addded logger info for deprecated funcs 2021-06-28 11:59:21 +02:00
2e3b4223a5 Merge pull request #1209 from Badiboy/master
Release 3.8.1 - bugfix
2021-06-28 12:41:38 +03:00
60bb63ab2b Release 3.8.1 - bugfix 2021-06-28 12:41:15 +03:00
0aa7a8a8f6 new 5.3 function names
added the new function names (the previous names are still working) from 5.3 and some other small changes
2021-06-28 09:31:06 +02:00
72ed7c1dde Merge pull request #1207 from Badiboy/master
Post-release fix for infinity_polling
2021-06-27 20:43:34 +03:00
a29c4af2ee Post-release fix for infinity_polling 2021-06-27 20:40:16 +03:00
8d8f234138 Merge pull request #1206 from MAIKS1900/master
2 of 3 Bot API 5.3 changes
2021-06-27 17:33:04 +03:00
491cc05a95 - Set BotCommandScope as abstract class.
- Docstrings from telegram API Scope types
2021-06-27 17:28:11 +03:00
b2c6077f4d Merge branch 'master' of https://github.com/MAIKS1900/pyTelegramBotAPI into master 2021-06-27 15:08:37 +03:00
fb290dc12d Merge pull request #1205 from Badiboy/master
Release version 3.8.0
2021-06-27 13:24:55 +03:00
c088fabe6c Release version 3.8.0 2021-06-27 13:09:08 +03:00
a791ff4e46 Add tests for file sending with name 2021-06-27 11:58:33 +03:00
e56f134a7c Add file_name support to send_document method 2021-06-27 11:38:45 +03:00
38c4c21030 Add file_name argument to send_data method 2021-06-27 11:37:27 +03:00
3e33b7f1cb Bot API 5.3 changes
- Personalized Commands for different chats
- Custom Placeholders of input field for ReplyKeyboardMarkup and ForceReply.
2021-06-26 14:36:14 +03:00
e381671645 Merge pull request #1201 from SwissCorePy/master
Added handlers for `my_chat_member` and `chat_member`.
Added aalowed_updates to polling functions.
2021-06-24 09:06:33 +03:00
ce991e9ac3 Update types.py
added the missing attributes `can_manage_chat` and `can_manage_voice_chats` to ChatMember class
2021-06-23 22:52:24 +02:00
3d5415433e Update __init__.py
Updated TeleBot doc string and added the missing functions to AsyncTeleBot
2021-06-23 22:51:17 +02:00
0bfefdf15d changed allowed_updates in util to update_types
i think its more clear name
2021-06-23 19:57:44 +02:00
506464e637 Update __init__.py
Added the parameter `allowed_updates` to polling and infinity_polling functions
2021-06-23 19:29:36 +02:00
4554cb969f Update __init__.py
added handlers for `my_chat_member` and `chat_member`
2021-06-23 16:10:48 +02:00
65cf841015 Update util.py
added `allowed_updates` list (used by `_init_._retrieve_all_updates` because `chat_member` is not requested by default)
2021-06-23 16:09:40 +02:00
0f0ce934dc Merge pull request #1199 from SwissCorePy/master
added InputInvoiceMessageContent and tgs_sticker support
2021-06-22 17:34:05 +03:00
bffbe764e5 Update tgs_sticker support
* Updated `create_new_sticker_set` and `add_sticker_to_set` functions
* Removed `create_new_animated_sticker_set` and `add_sticker_to_animated_sticker_set` functions
2021-06-22 15:57:34 +02:00
c00595e212 Update types.py
* Added Parameter `caption_entities` to `InputMedia` class
* Added Parameter `disable_content_type_detection` to `InputMediaDocument` class
2021-06-22 15:55:14 +02:00
b20f5b359b Merge pull request #1200 from pablodz/patch-1
Fix long string blocking version of python on github actions setup
2021-06-22 08:29:50 +03:00
558eef78b4 Fix long string blocking version of python on github actions setup 2021-06-21 17:27:35 -05:00
3f46ce3b7b added InputInvoiceMessageContent and tgs_sticker support
and some small changes
2021-06-21 19:59:39 +02:00
69e8edef19 Merge pull request #1198 from SwissCorePy/master
Added some missing features
2021-06-21 20:48:04 +03:00
d3369245c4 fixed wrong type hint 2021-06-21 17:49:03 +02:00
55e9f2095e Merge branch 'master' of https://github.com/eternnoir/pyTelegramBotAPI 2021-06-21 17:39:57 +02:00
7118613ef7 Added missing features
* added some missing features of TelegramBotAPI 4.6-5.2 to pyTelegramBotAPI
* added type hints to (almost) all public TeleBot functions
2021-06-21 17:39:13 +02:00
105d65d5ce Merge pull request #1197 from vishal2376/master
Add developer bot
2021-06-21 14:16:37 +03:00
f11bf08ba1 Update README.md 2021-06-21 16:30:17 +05:30
66598e39fe Change description of developer bot 2021-06-21 16:27:32 +05:30
4146b50384 Add developer bot 2021-06-21 13:16:22 +05:30
f62d642572 Merge pull request #1196 from leonheess/patch-1
Add Anti-Tracking Bot
2021-06-20 19:33:50 +03:00
18f1fd42b0 Add Anti-Tracking Bot 2021-06-20 13:14:55 +02:00
07d198aebe Merge pull request #1195 from SwissCorePy/master
Added class ChatMemberUpdated
2021-06-19 22:18:50 +03:00
0370a9f277 Added class ChatMemberUpdated
* Added class `ChatMemberUpdated` to types
* Simplified `de_json` functions in `WebhookInfo` and `Update` classes (for overall more consistent code)
* changed `options_ids` to ´option_id` in class `PollAnswer`
* Added test for `ChatMemberUpdated` class in `test_types.py` and added the fields `my_chat_member` and `chat_member` to the `Update` class and its tests
2021-06-19 20:13:53 +02:00
22d3ac027a Merge pull request #1194 from SwissCorePy/master
Minor updates to the https://github.com/eternnoir/pyTelegramBotAPI/pull/1191
2021-06-19 19:25:04 +03:00
795f7fff7f Some small changes
* Fixed type warnings in some editors by changing `var: Type = None` to `var: Union[Type, None] = None`
* changed some args from `obj['arg']` to `obj.get('arg')` if arg is optional
* better PEP-8 compliance for less weak warnings
* added tests for the new type `ChatInviteLink`
2021-06-19 17:59:55 +02:00
ab6d40a072 Merge pull request #1193 from Badiboy/master
Raise exception if no token passed
2021-06-19 15:10:32 +03:00
d26923e167 Raise exception if no token passed 2021-06-19 15:09:52 +03:00
05aff236c1 Merge pull request #1191 from SwissCorePy/master
Huge update with type checking and some new properties.

Note: should be presisely tested before publishing.
2021-06-19 15:00:12 +03:00
a9ae070256 Update types.py 2021-06-18 22:37:31 +02:00
63fe6e01d1 Fixed the errors from my last PRs
I testet all using pytest and python versions 3.6-3.9 on macOS
2021-06-18 22:35:49 +02:00
bbafdd1c1d Some Updates
> Added lot of type hints to types.py
> Added some new fields from TelegramBotAPI to pyTelegramBotAPI
> fixed `circular import error in util.py
> Added functions `log_out` and `close` to __init__.py and apihelper.py
> And some more small changes
2021-06-17 20:28:53 +02:00
fe9df2df8c Merge pull request #1186 from AREEG94FAHAD/master
Add to translator bot
2021-06-12 21:13:41 +03:00
b0b8623dce Merge pull request #1 from AREEG94FAHAD/Cryptocurrency
Update README.md
2021-06-12 19:02:06 +03:00
a01e59951a Update README.md 2021-06-12 19:01:42 +03:00
d5c202abbd Update README.md 2021-06-12 18:19:18 +03:00
81299ff613 Update README.md 2021-06-12 18:18:51 +03:00
25bac68309 Update README.md 2021-06-12 18:18:16 +03:00
a05324bdad Merge pull request #1181 from pablodz/master
Github Actions: setup for 3.6+ pypy3.6+
2021-06-09 17:29:57 +03:00
74c4ab2f04 Merge pull request #1183 from SwissCorePy/master
Fixed a bug in `user_link`
2021-06-09 17:28:13 +03:00
ab05cb0045 Fixed a bug in user_link
`user_link` returned an empty string if `include_id` was set to False
2021-06-09 16:20:42 +02:00
709eb8cf45 Github Actions: setup for 3.6+ pypy3.6+ 2021-06-06 14:30:55 -05:00
643cdeceee Merge pull request #1179 from Badiboy/master
Fix special case when content_type is None
2021-06-04 12:29:05 +03:00
2add34c702 Fix special case when content_type is None 2021-06-04 12:28:33 +03:00
877397a46b Merge pull request #1178 from Badiboy/master
Partial rollback for previous update
2021-06-04 12:12:26 +03:00
afbc67795a Partial rollback for previous update 2021-06-04 12:11:37 +03:00
da5dc20b3a Merge pull request #1176 from SwissCorePy/master
Added some functions and type hints
2021-06-03 23:45:21 +03:00
ed5e5e5077 Update util.py
- Removed function `unix_time`
- Added function `escape`
- Added function `user_link`
- Added function `quick_markup`
- Added some type hints
2021-06-03 19:51:33 +02:00
9a6ddce8df Added the function unix_time 2021-06-03 19:06:53 +02:00
db8478d0a4 Merge pull request #1174 from SwissCorePy/master
Add `smart_split` function to utils.py
2021-06-03 19:55:44 +03:00
20030f47af Update util.py
Added the function `smart_split` to split text into meaningful parts.
2021-06-03 18:51:32 +02:00
f7cf1965cb Merge pull request #1168 from anvarjamgirov/patch-1
Bug fixed on set_game_score
2021-06-01 08:30:42 +03:00
aea067f789 Bug fixed on set_game_score
fixed wrong ordered argument error on calling apihelper.set_game_score method in set_game_score
2021-06-01 08:39:09 +05:00
e2c20c1e55 Merge pull request #1167 from zora89/master
typo corrected.
2021-05-25 23:56:01 +03:00
1209281787 type corrected. 2021-05-26 02:17:49 +05:30
742f67c85b Merge pull request #1163 from yehwankim23/patch-1
Fix typo
2021-05-20 12:07:34 +03:00
e22fcbe3c0 Fix typo 2021-05-20 18:01:10 +09:00
d3998dfadb Merge pull request #1161 from yarreg/feature/invite-link-api
Create_chat_invite_link, edit_chat_invite_link, revoke_chat_invite_link methods
2021-05-19 11:30:06 +03:00
ff54f194ad Added: create_chat_invite_link, edit_chat_invite_link, revoke_chat_invite_link methods 2021-05-19 11:22:40 +03:00
f6b967421e Merge pull request #1160 from Badiboy/master
Update version.py
2021-05-15 20:30:27 +03:00
59559199d5 Update version.py 2021-05-15 20:29:58 +03:00
98784c811e Merge pull request #1159 from Badiboy/master
Fix release 3.7.8u1 (update was inconsistent, sorry)
2021-05-15 20:28:51 +03:00
26e5f3d3a8 Fix release 3.7.8u1 2021-05-15 20:27:52 +03:00
fe1f99abdf Merge pull request #1158 from Badiboy/master
send_poll fix of fix
2021-05-15 20:09:49 +03:00
7540a26fb9 send_poll fix of fix
Previous update was inconsistent, sorry.
2021-05-15 20:08:51 +03:00
10d0ff2c06 Merge pull request #1157 from Badiboy/master
Release 3.7.8
2021-05-15 11:36:00 +03:00
90de2e4ad9 Release 3.7.8
Regular release with minor updates
2021-05-15 11:35:13 +03:00
d3c2ffd422 Merge pull request #1155 from Badiboy/master
send_poll fix with PollOptions
2021-05-15 11:31:02 +03:00
53c98328c1 send_poll fix with PollOptions
Now send_poll correctly operates with PollOptions passed as array of PollOption.
2021-05-12 00:26:33 +03:00
3d26a0ce0d Merge pull request #1154 from Badiboy/master
Change message handler filtering order
2021-05-11 23:27:54 +03:00
73fb18c193 Change message handler filtering order
Now content_type is checked first.
2021-05-11 23:26:22 +03:00
1ba595daa0 Merge pull request #1153 from hemantapkh/patch-1
Add Torrent Hunt bot in README
2021-05-11 09:23:59 +03:00
47cab4d63e Fix typo 2021-05-11 07:58:19 +05:45
4a25675007 Add Torrent Hunt bot in README 2021-05-11 07:51:13 +05:45
c437b40d58 Merge pull request #1140 from eternnoir/dependabot/pip/py-1.10.0
Bump py from 1.4.29 to 1.10.0
2021-04-20 22:00:39 +03:00
b7a18bf0d9 Bump py from 1.4.29 to 1.10.0
Bumps [py](https://github.com/pytest-dev/py) from 1.4.29 to 1.10.0.
- [Release notes](https://github.com/pytest-dev/py/releases)
- [Changelog](https://github.com/pytest-dev/py/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/py/compare/1.4.29...1.10.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-20 17:03:50 +00:00
bc3d5a46b7 Merge pull request #1138 from Badiboy/master
Python 3.5 end-of-life
2021-04-19 18:46:53 +03:00
990bb827be Python 3.5 end-of-life 2021-04-19 18:45:49 +03:00
3ecb84bd94 Merge pull request #1137 from FosterToster/master
middleware handlers exception handling
2021-04-19 18:42:24 +03:00
2565094897 fixed overwriting exception args 2021-04-19 22:20:42 +07:00
855b838e91 more explict process_middleware exceptions suppressing 2021-04-18 22:41:28 +07:00
042d8c17da suppress_middleware_excepions configuration. False by default. 2021-04-18 22:31:24 +07:00
a39fb14726 middleware handlers exception handling 2021-04-18 19:56:52 +07:00
888c7a6b0d Merge pull request #1126 from David256/feature-new-property-fullname
Change fstrings to string formatting
2021-04-02 01:41:48 +03:00
2f69917a82 Change fstrings to string formatting 2021-04-01 16:52:12 -05:00
efa35ba71c Merge pull request #1125 from David256/feature-new-property-fullname
New property full_name
2021-04-02 00:05:29 +03:00
6c90da793e New property full_name 2021-04-01 14:56:08 -05:00
4024490249 Merge pull request #1121 from Badiboy/master
Minor release
Heroku example update
2021-03-28 11:57:49 +03:00
209d9b27b4 Minor release 2021-03-28 11:57:05 +03:00
96e0be8942 Heroku example update 2021-03-28 11:54:46 +03:00
87bce0bce1 Merge pull request #1113 from barbax7/master
Added Price Tracker bot
2021-03-18 17:43:43 +03:00
f23059d7ec Added Price Tracker bot 2021-03-18 08:38:47 +01:00
cc08fe32c6 Merge pull request #1107 from MasterGroosha/patch-1
Removed my bot from README
2021-03-09 10:35:06 +03:00
07e93f95a1 Removed my bot from list
The link is now dead, and so is that bot
2021-03-09 02:05:44 +03:00
a10e8afa5c Merge pull request #1096 from anvaari/master
Add my bot to Readme.md
2021-02-16 13:25:07 +03:00
b39244f827 Add my bot to Readme.md 2021-02-16 13:41:56 +03:30
af4d986a13 Merge pull request #1090 from Badiboy/master
Custom logging level for infinity_polling
2021-02-05 00:43:22 +03:00
8790f26e68 Custom logging level for infinity_polling 2021-01-30 14:41:19 +03:00
f01412a996 Merge pull request #1086 from dexpiper/patch-1
README list of bots update
2021-01-22 16:56:02 +03:00
20d0ab229f README list of bots update
Add another bot to the list below
2021-01-21 17:19:54 +03:00
2dec4f1ffc Merge pull request #1083 from ModischFabrications/patch-1
Add MineGramBot to readme
2021-01-20 13:31:05 +03:00
a7d1dbf0e9 add MineGramBot 2021-01-20 11:04:55 +01:00
eace25d9d2 Merge pull request #1082 from Badiboy/master
Minor update to copyMessage
2021-01-19 01:28:16 +03:00
fdf2838669 Minor update to copyMessage 2021-01-19 01:27:39 +03:00
74fb8258b6 Merge pull request #1067 from Aazerra/copyMessage_method
Added copyMessage method
2021-01-19 01:16:09 +03:00
cc299fe4da Merge pull request #1081 from ModischFabrications/patch-1
Extend readme with more usage hints
2021-01-18 02:26:02 +03:00
cd31c8db5c fix example 2021-01-17 23:47:03 +01:00
6d7116d521 document SESSION_TIME_TO_LIVE 2021-01-17 23:45:23 +01:00
f93916372e document edit_message_text in readme 2021-01-17 23:34:54 +01:00
80c9e17fd4 add apihelper.ENABLE_MIDDLEWARE = True to readme 2021-01-17 23:22:45 +01:00
003a92f466 Merge pull request #1080 from Badiboy/master
Release v.3.7.6
2021-01-18 01:02:45 +03:00
d57aa04bfb Release v.3.7.6 2021-01-18 01:02:19 +03:00
9c2d279806 Merge pull request #1078 from ModischFabrications/patch-1
Hide token from debug logs
2021-01-17 12:21:42 +03:00
3109e35bb4 show bot id 2021-01-17 01:26:38 +01:00
ea51b1e95e hide token from debug logs
prevent leaks of the bot token by hiding it from the log
2021-01-17 01:06:47 +01:00
3799a1e99a Merge pull request #1077 from Badiboy/master
Added short live sessions
2021-01-17 00:46:01 +03:00
ec8714ad3a Short live sessions u1 2021-01-17 00:43:52 +03:00
bc54a5379c Added short live sessions 2021-01-16 23:50:25 +03:00
a7587057bf Merge pull request #1076 from Badiboy/master
Polling timeout fix
2021-01-16 02:15:26 +03:00
e9ba2fd8bb Polling timeout fix 2021-01-16 02:14:29 +03:00
8203fa588f Merge pull request #1074 from Badiboy/master
Version update to previous commit
2021-01-14 15:49:01 +03:00
2e5250ec98 Version update to previous commit 2021-01-14 15:48:30 +03:00
1f910745f1 Merge pull request #1073 from Badiboy/master
Fix restrict_chat_member until_date bug
2021-01-14 15:47:21 +03:00
f56da17741 Fix restrict_chat_member until_date bug 2021-01-14 15:45:47 +03:00
a0d86977b0 Merge pull request #1072 from Badiboy/master
Infinity polling fall down fixed
2021-01-14 03:57:00 +03:00
82838e1d26 Infinity polling fall down fixed 2021-01-14 03:44:37 +03:00
bb8bc7672a Merge pull request #1070 from dgarcoe/patch-1
Update README.md
2021-01-13 20:03:10 +03:00
6e3e159109 Update README.md
I included my bot in the README. Thanks for the library!
2021-01-13 17:55:08 +01:00
b561e35330 Update __init__.py 2021-01-12 11:19:57 +03:30
b684c4f60d Fix Things on copyMessage 2021-01-12 11:17:53 +03:30
58281f0a10 Added copyMessage method 2021-01-11 02:50:17 +03:30
87574a7613 Merge pull request #1066 from Badiboy/master
drop_pending_updates in set_webhook
2021-01-09 21:23:55 +03:00
52ebb5a1a7 drop_pending_updates in set_webhook 2021-01-09 21:22:49 +03:00
da9ee5ffba Merge pull request #1065 from Badiboy/master
Release version  3.7.5
2021-01-07 20:47:12 +03:00
0900acfae9 Release version 3.7.5 2021-01-07 20:46:50 +03:00
c6cf615722 Merge pull request #1062 from Badiboy/master
Added timeout to xxx_webhook
2021-01-07 02:38:26 +03:00
5dc008a762 Added timeout to xxx_webhook 2021-01-07 00:13:44 +03:00
bbcd7aa9db Merge pull request #1060 from TarasKindrat/master
Modify RedisHandlerBackend, add argument "password=None" to __init__()
2021-01-06 15:06:24 +03:00
51effdd9a1 Merge pull request #1061 from barbax7/patch-2
Added bot @donamazonbot to the list
2021-01-06 15:05:37 +03:00
0126ba82a5 Added bot @donamazonbot to the list 2021-01-05 17:31:18 +01:00
6b0484b9db Modify RedisHandlerBackend, add argument "password=None" to __init__()
With argument "password=None" in method __init__(), and argument "password" in "self.redis = Redis(host, port, db, password)", will be able to use Redis with password protection, if password is set .
2021-01-05 13:06:14 +02:00
eab36a99e9 Update README.md 2021-01-01 23:14:00 +08:00
28357c8c33 Merge pull request #1056 from Badiboy/master
Bot API update
2020-12-29 19:27:06 +03:00
6559f431b7 Bot API update
Bot API conformance up to 4.4

Added webhook parameters from 5.0
2020-12-29 19:24:41 +03:00
b5d054cf5f Merge pull request #1054 from timgates42/bugfix_typo_performance
docs: fix simple typo, perfomance -> performance
2020-12-25 01:52:17 +03:00
93b86307d9 docs: fix simple typo, perfomance -> performance
There is a small typo in examples/webhook_examples/README.md.

Should read `performance` rather than `perfomance`.
2020-12-25 09:47:40 +11:00
f62d72e2a1 Merge pull request #1053 from Badiboy/master
Avoid dead threads in treaded polling
2020-12-25 00:03:24 +03:00
c4e624d999 Avoid dead threads in treaded polling 2020-12-24 23:55:12 +03:00
fcb3d9b1b3 Merge pull request #1052 from Badiboy/master
Exception if middleware is used but not enabled
2020-12-24 19:57:25 +03:00
2534dc5925 Exception if middleware is used but not enabled. 2020-12-24 19:55:24 +03:00
ded0d257fc Merge pull request #1050 from twistfire92/master
fix restrict_chat_member method
2020-12-22 23:05:43 +03:00
96686e5221 fix restrict_chat_member method 2020-12-22 21:38:38 +03:00
b522053e27 Merge pull request #1043 from vixfwis/master
Add webhook example for Twisted
2020-12-17 16:49:26 +03:00
4e61bc3a8b add short description to example and readme files 2020-12-17 15:34:36 +03:00
487ede7c88 Merge pull request #1046 from Badiboy/master
Fix unban_chat_member in async
2020-12-16 01:58:31 +03:00
4658d2b8da Fix unban_chat_member in async 2020-12-16 01:57:30 +03:00
75a18e5869 add webhook example for Twisted framework 2020-12-15 15:02:41 +03:00
fab2b2d223 Merge pull request #1035 from Badiboy/master
parse_mode = ""
2020-12-09 11:23:09 +03:00
65c3ca58da Update __init__.py
Allow parse_mode = "" to disable default parse mode.
2020-12-09 01:41:07 +03:00
a4d0b685b5 Merge pull request #1026 from Badiboy/master
Bot API 5.0 pinning-unpinning logic post-fix.
2020-11-29 16:11:46 +03:00
6cc80f25d7 Bot API 5.0 pinning-unpinning logic post-fix. 2020-11-29 15:33:39 +03:00
0418818629 Merge pull request #1025 from alexmechanic/master
Bot API 5.0 pinning-unpinning logic update
2020-11-29 15:28:43 +03:00
b9898bbdda Fix 0a2216a22b #2
+ message_id arg of unpin_chat_message() passing to the helper
- removed passing arg to unpin_all_chat_messages()
2020-11-29 15:21:59 +03:00
00c9351f83 Hotfix 0a2216a22b
* message_id made optional as API declares
2020-11-29 15:12:14 +03:00
0a2216a22b Bot API 5.0 pinning-unpinning logic update
+ add unpin_all_chat_messages() (former unpin_chat_message())
* update unpin_chat_message() (add message_id arg)
2020-11-29 14:47:53 +03:00
438cfe4dbd Merge pull request #1022 from Badiboy/master
Version 3.7.4 release
2020-11-20 23:50:39 +03:00
640f398262 Version 3.7.4 release 2020-11-20 23:49:55 +03:00
a9db217c64 Merge pull request #1020 from Badiboy/master
added only_if_banned to unban_chat_member
2020-11-20 15:05:41 +03:00
5824d47590 added only_if_banned to unban_chat_member 2020-11-18 02:22:52 +03:00
0da192aec7 Merge pull request #1014 from Badiboy/master
set_webhook bugfinx
2020-11-11 01:02:21 +03:00
bd27645965 set_webhook bugfinx
set_webhook does not reset allowed_updates for empty list (to default)
2020-11-11 00:32:34 +03:00
2c15cd0996 Merge pull request #1012 from Badiboy/master
Long polling timeouts update
2020-11-07 16:51:10 +03:00
00d125a298 long_polling_timeout update 3 2020-11-07 14:59:45 +03:00
a548374a4d long_polling_timeout update 2 2020-11-07 14:43:17 +03:00
03e1aef70e long_polling_timeout update 1 2020-11-07 14:02:11 +03:00
ece7ca97e0 Merge pull request #1011 from Badiboy/master
Long polling updates and combo content types
2020-11-07 13:02:22 +03:00
7a3fd30f6a Long polling updates and combo content types 2020-11-07 12:52:51 +03:00
1d99cc224f Merge pull request #1005 from Badiboy/master
Animation content_type
2020-11-03 23:26:53 +03:00
fa3ca84d24 Animation content_type
"When you send gif telegram gives you animation and document at same time in update and when you parse that first if is animation and second is document because of this the content_type set document not animation"
2020-11-03 17:46:19 +03:00
42e6d84f13 Merge pull request #1004 from diegop384/patch-1
Update README.md
2020-11-03 17:36:04 +03:00
27461c03af Update README.md
I added my bot
2020-11-03 09:28:31 -05:00
3be51390b1 Merge pull request #997 from Mrsqd/patch-1
Added Frcstbot description
2020-10-30 00:42:04 +03:00
afa88304d7 Added Frcstbot
I've made a weather forecast bot using your API. Can you approve my request to add it, please?
2020-10-29 02:09:47 +03:00
82e79b6ac6 Merge pull request #995 from pinguluk/patch-1
Update README.md
2020-10-28 14:16:03 +03:00
746c71665e Update README.md
linked example/webhook_examples to the directory
2020-10-28 12:31:57 +02:00
37c09406d0 Merge pull request #989 from andvch/patch-1
Fix broken text_mention html formatting
2020-10-15 11:57:38 +03:00
36a3ce62c4 Fix broken text_mention html formatting 2020-10-14 12:06:49 +03:00
6dc8173176 Merge pull request #977 from Badiboy/master
Previous commit bugfix
2020-09-22 01:46:51 +03:00
00c2e9b51c Piece death fix 2020-09-22 01:41:51 +03:00
29711e2425 Merge remote-tracking branch 'upstream/master' 2020-09-22 01:34:55 +03:00
75a5dd1492 Minor bugfix 2020-09-22 01:34:49 +03:00
3ae145f206 Update README.md 2020-09-10 16:22:50 +08:00
5fda52cf5d Merge pull request #970 from meoww-bot/master
UPG: Added the field reply_markup to the Message object
2020-09-07 13:09:46 +03:00
9ab906e60c fix: simplify code
json.loads(button.to_json()) equals to button.to_dict()
2020-09-02 18:09:14 +08:00
698b4371e6 test: Add tests for InlineKeyboardMarkup and ...
Add tests for InlineKeyboardMarkup and InlineKeyboardButton
2020-09-02 10:33:32 +08:00
a803edd09b fix: button in markup should be obj, not json text 2020-09-02 09:25:23 +08:00
32a9e65ecc fix: reply_markup does not change content_type 2020-09-02 09:12:49 +08:00
decad450d0 feat: make InlineKeyboardMarkup JsonDeserializable
feat: make InlineKeyboardMarkup JsonDeserializable, add de_json func to InlineKeyboardMarkup object
2020-09-01 18:13:22 +08:00
630a9a5b2c feat: make InlineKeyboardButton JsonDeserializable
feat: make InlineKeyboardButton JsonDeserializable, add de_json func to InlineKeyboardButton Object
2020-09-01 18:07:45 +08:00
cdae65116b feat: make LoginUrl JsonDeserializable
feat: make LoginUrl JsonDeserializable, add de_json func
2020-09-01 18:03:21 +08:00
6832c33733 feat: Added the field reply_markup to the Message
Added the field `reply_markup` to the Message object
2020-08-31 12:00:56 +00:00
d15cb16bef Merge pull request #969 from ArtemFrantsiian/patch-1
Fix an error with the is_pil_image function
2020-08-29 22:04:36 +03:00
81100f249c Fix an error with the is_pil_image function
When I've tried to send_photo as shown in detailed_example, I got an error: "AttributeError: module 'PIL' has no attribute 'Image'". 
This error was described well here: https://stackoverflow.com/a/11911536/9092263. So in accordance to prescriptions, I've made changes and It works fine for me.

Steps to reproduce:
1. initiate bot via TeleBot constructor
2. call function bot.send_photo(call.message.chat.id, open("some_image.jpg", "rb"))

P.S.
Error Environment: 
- python==3.8.5
- pyTelegramBotAPI==3.7.3
- PIL==7.2.0
2020-08-29 21:57:41 +03:00
79ff9191f3 Merge pull request #967 from meoww-bot/patch-1
Added the field `file_unique_id` (Bot API 4.5)
2020-08-29 11:18:00 +03:00
bdfb793e34 test: Added file_unique_id from Bot API 4.5 2020-08-29 12:07:38 +08:00
e811163b5f UPG: Added the field file_unique_id
Added the field file_unique_id to the objects Animation, Audio, Document, PassportFile, PhotoSize, Sticker, Video, VideoNote, Voice, File and the fields small_file_unique_id and big_file_unique_id to the object ChatPhoto. (Bot API 4.5)
2020-08-29 04:29:02 +08:00
1eb9651894 Merge pull request #963 from Badiboy/master
Minor readme update
2020-08-26 00:53:12 +03:00
309e55845c Minor readme update 2020-08-26 00:51:55 +03:00
2bc5c1a500 Merge pull request #960 from CrafterKolyan/patch-1
Add last_update_id parameter for constructor
2020-08-25 21:58:33 +03:00
7acad2d825 Merge pull request #958 from Badiboy/master
Bot API support checked/updated up to 4.2
2020-08-25 21:49:40 +03:00
5120650774 Move parameter to the end of list 2020-08-25 21:45:30 +03:00
c13f9a7f98 Add last_update_id parameter for constructor 2020-08-25 21:26:28 +03:00
bab9b4077d Bot API support checked/updated up to 4.2 2020-08-25 18:18:51 +03:00
47b9c1d3fb Merge pull request #957 from Badiboy/master
Empty list optimization, Py2 arteacts removed
2020-08-25 16:46:28 +03:00
06ed637f2f Merge remote-tracking branch 'upstream/master' 2020-08-25 16:24:07 +03:00
7bf432170e Merge pull request #956 from Pablo-Davila/master
Append bots to list
2020-08-25 16:23:52 +03:00
8cd18945c5 Append bots to list
TasksListsBot
MyElizaPsychologistBot
2020-08-25 15:45:08 +02:00
48b53f6a8e Update version.X 2020-08-24 21:36:27 +08:00
cdd48c7aed Empty list optimization, Py2 arteacts removed,
Empty list optimization: None instead of [].

Py2 arteacts removed: no more six moudle used.
2020-08-24 16:02:35 +03:00
513a85cad9 Merge remote-tracking branch 'upstream/master' 2020-08-24 13:00:30 +03:00
c1c84a588d Merge pull request #955 from fgallaire/master
Fix 'NoneType' object assignment error from #892 and #954
2020-08-22 18:32:25 +03:00
5e19965b0c Fix 'NoneType' object assignment error from #892 and #954 2020-08-22 16:11:52 +02:00
17f48916ad Merge remote-tracking branch 'upstream/master' 2020-08-21 17:40:56 +03:00
5b70980bda Resolve conflicts 2020-08-21 17:38:54 +03:00
73487f96c4 Custom exception handler for poll mode
Initial beta of custom exception handler for poll mode.

Use ExceptionHandler class and bot.exception_handler to proceed unhandled exceptions in poll mode.
2020-08-21 17:36:08 +03:00
818905de32 Merge pull request #954 from rfoxxxy/master
Added missing thumb parameters to send_document, send_animation and send_video_note
Implemented getting the runtime version of pyTelegramBotAPI
Fixed docstring for send_video_note function
2020-08-21 17:33:22 +03:00
cab33ad0d9 fixed thumb processing 2020-08-21 14:09:38 +03:00
9ca3c78c84 back version to 3.7.2 2020-08-21 11:22:24 +03:00
0ab4046a4f Create version.py 2020-08-21 11:09:53 +03:00
8b50dc488b added missing thumb params and more 2020-08-21 11:09:43 +03:00
83df269730 Merge pull request #953 from Badiboy/master
Two None checks
2020-08-20 00:00:57 +03:00
18eb8eb605 Two None checks 2020-08-19 23:57:48 +03:00
19aaf83d88 Merge pull request #950 from BLUE-DEVIL1134/master
Update README.md
2020-08-17 11:48:59 +03:00
3b57c288b4 Update README.md 2020-08-17 14:08:20 +05:30
8f1c34db76 Merge pull request #947 from BLUE-DEVIL1134/master
Update README.md
2020-08-14 22:07:47 +08:00
2aaff09c39 Update README.md 2020-08-14 11:38:57 +05:30
1cd36253f0 Update README.md 2020-08-14 11:36:04 +05:30
484c3a4c48 Update README.md 2020-08-14 10:50:56 +05:30
5347a068e0 Merge pull request #944 from barbax7/patch-1
Update README.md
2020-08-13 18:25:23 +03:00
52511fce48 Update README.md
Added my bot to the list.
2020-08-13 12:14:57 +02:00
507d524215 Merge pull request #939 from mrpes/patch-6
Keyboard bugfix
2020-08-04 22:03:00 +03:00
ec79d1dc1e Keyboard bugfix 2020-08-04 23:45:33 +05:00
31e40d155b Merge pull request #938 from Badiboy/master
CopyPaste bugfix
2020-08-04 18:29:31 +03:00
c6f51f6c55 CopyPaste bugfix 2020-08-04 18:28:35 +03:00
dc07cacc7f Merge pull request #935 from mrpes/patch-4
Exceptions classes redesign followup
2020-08-04 18:25:31 +03:00
ce6a21cd09 Merge branch 'master' into patch-4 2020-08-04 19:49:55 +05:00
58c4010155 Merge pull request #937 from Badiboy/master
Bugfix and DISABLE_KEYLEN_ERROR
2020-08-04 12:40:32 +03:00
a5fd407eb6 Bugfix and DISABLE_KEYLEN_ERROR
Bugfix and DISABLE_KEYLEN_ERROR to supress keyboard length errors.
2020-08-04 12:29:56 +03:00
1bb98483c2 Update apihelper.py 2020-08-04 05:34:13 +05:00
67fdb2f52e Merge pull request #934 from Badiboy/master
Minor keyboard update followup
2020-08-03 11:37:09 +03:00
c17a2379ba Exceptions classes redesign followup 2020-08-03 06:39:12 +05:00
cc36207992 Minor keyboard update followup 2020-08-02 18:58:22 +03:00
e987e40ee7 Merge pull request #930 from mrpes/patch-5
Minor keyboard code redisign
2020-08-02 18:49:32 +03:00
1ba093cb02 Change logger level to warning 2020-08-02 20:30:58 +05:00
4e5fb59fc0 Replace exceptions with warnings
Also further PIL support added
2020-08-02 20:20:33 +05:00
317a490cf0 Type checking moved to utils 2020-08-01 01:30:38 +05:00
5823ca5613 Minor keyboard code redesign 2020-08-01 01:28:56 +05:00
9a3f370dce Merge pull request #929 from mrpes/patch-3
Support for sending PIL images in sendPhoto / sendChatPhoto as photo argument.
2020-07-31 11:06:31 +03:00
97aa9637cb Update apihelper.py 2020-07-31 10:45:58 +05:00
0ab908705b Support for PIL images as photo argument
Added autoconversion of PIL image to file-like object. PIL module is optional
2020-07-31 10:39:04 +05:00
88e0f1337b Merge pull request #928 from mrpes/patch-2
Exception classes redesign: additional Exception subclasses added
2020-07-31 01:37:32 +03:00
67536d4eec Fixing backward compatibility issue
Just realized that renaming ApiException to BaseApiException will cause backward compatibility issue
2020-07-31 03:30:03 +05:00
a14424704e Exception classes redesign
Replacing 1 exception class with 3 more specific classes: 
HTTP Exception (server returned http code != 200), 
Invalid JSON Exception (server returned invalid json),
Telegram Expection (telegram returned ok != true)

All 3 classes extend BaseApiException so we can handle all API exceptions at the same time
2020-07-31 03:10:34 +05:00
b790e4e6ba Merge pull request #927 from mrpes/patch-1
Optional retry on requests error
2020-07-30 11:14:51 +03:00
0ac64469b0 Retry on requests error
Added RETRY_ON_ERROR var. If its value is true, we'll try to get proper result MAX_RETRIES times, with RETRY_TIMEOUT delay between requests. Last request will be called outside of the try block, so it will throw an exception on failure

P.S.
I'm actually not sure if there are better ways to solve this problem, but this was my way of solving it
2020-07-30 09:34:51 +05:00
ce3c91b619 Merge pull request #919 from Badiboy/master
Minor updates in code
2020-07-21 01:27:32 +03:00
dbe9ce49df Minor updates in code 2020-07-21 01:20:01 +03:00
48e48610f3 Merge pull request #918 from daveusa31/master
Documented the default parse_mode installation
2020-07-18 23:01:25 +03:00
d7aaccef63 Merge pull request #917 from EskiSlav/master
Added strike and underline entities to parse to html
2020-07-18 21:19:47 +03:00
a02f499a20 Documented the default parse_mode installation 2020-07-18 19:02:07 +03:00
c533a52e39 Restored necessary comment 2020-07-18 00:25:00 +03:00
b50eb1bafb Added nested entities from Bot API 4.5 2020-07-17 13:43:45 +03:00
40e19e5af1 Merge pull request #915 from zeph1997/editreadme
Added JoinGroup Silencer Bot into the "Bots using this API" in README
2020-07-16 14:22:45 +03:00
bc5d9c8d69 Update README.md 2020-07-16 19:09:37 +08:00
6049de4356 Update README.md 2020-07-16 19:07:39 +08:00
b38ceaaec8 Merge pull request #913 from Aragroth/master
Added ability to specify params of width and height for video
2020-07-11 22:30:53 +03:00
7c94eee3a2 Update apihelper.py 2020-07-11 20:09:48 +03:00
00798df0c0 Merge pull request #909 from iPurya/patch-1
Fix Sticker tests
2020-07-07 09:17:01 +03:00
d2d7cc39be Update test_types.py 2020-07-07 03:39:00 +04:30
d74f47e16c Merge pull request #908 from iPurya/patch-2
Added field file_unique_id to Sticker.
2020-07-07 01:31:08 +03:00
d5e9f73821 Update test_types.py
tests updated for pull request #908.
2020-07-07 02:38:06 +04:30
49398f5c61 Update types.py
Sending stickers everytime have different file_id, so for detecting special stickers we need a unique parameter.
2020-07-07 01:31:33 +04:30
f42ec4fe0d Bump version. 2020-07-06 00:37:17 +08:00
e9f925e14c Merge pull request #906 from daveusa31/master
Added ability to set default parse_mode in main TeleBot class.
2020-07-04 22:29:32 +03:00
0304e6507f Append default parse_mode 2020-07-04 21:07:42 +03:00
0f387db8d2 Fix tabs 2020-07-04 20:45:48 +03:00
30664f396a Merge pull request #904 from timbyxty/master
Added NST bot to the bot list
2020-07-04 00:17:43 +03:00
cdffeba829 added NST 2020-07-03 22:05:47 +05:00
f4d978cd98 Update apihelper.py 2020-07-02 17:51:34 +03:00
f83f69ed50 Update apihelper.py 2020-07-02 17:50:14 +03:00
a69a358ebd Update __init__.py 2020-07-02 17:47:38 +03:00
4afde9f557 Update apihelper.py 2020-07-02 17:46:41 +03:00
8e82d1c462 Merge pull request #902 from 0xnu/patch-1
Update README.md
2020-07-02 16:08:22 +03:00
b5a4276282 Update README.md
Link to Sports bot added.
2020-07-02 13:27:51 +01:00
d43292e42b Merge pull request #892 from Otxoto/Otxoto-patch-2
Added thumbnail support for send_audio and send_video
2020-06-24 19:10:15 +03:00
99de5490a0 Added thumb parameter to send_video 2020-06-23 20:17:21 +02:00
53ccef5e5e added thumb parameter to send_video 2020-06-23 20:14:52 +02:00
29b432e65a Added thumb to send_audio 2020-06-23 20:12:46 +02:00
4f4c0891d9 Added thumb support to send_audio 2020-06-23 20:10:12 +02:00
03b1531bd7 Merge pull request #890 from Otxoto/master
Update User type
Added:
can_join_groups
can_read_all_group_messages
supports_inline_queries
2020-06-22 23:14:45 +03:00
ab496f995e Merge pull request #1 from Otxoto/Otxoto-patch-1
Complete User Class
2020-06-22 13:18:42 +02:00
44872ce87d Complete User Class
Added following fields:
can_join_groups
can_read_all_group_messages
supports_inline_queries
2020-06-22 13:18:13 +02:00
c24d1e2d0b Update README.md 2020-06-07 02:50:30 +08:00
38694a9173 Merge pull request #865 from Badiboy/master
Update test_telebot.py
2020-05-29 12:43:24 +03:00
1494946d02 Update test_telebot.py
Build fix.
2020-05-29 12:37:23 +03:00
5facf7de92 Merge pull request #808 from pikss86/master
Add possibility to create and use custom session, for examle - torpy
2020-05-29 12:17:58 +03:00
f7008d4d99 Merge pull request #856 from Badiboy/master
send_chat_permissions fix
2020-05-20 12:03:05 +03:00
32dc03ec44 send_chat_permissions fix 2020-05-20 11:57:41 +03:00
dbff7cbb3e Merge pull request #852 from olegshek/keyboard_button_poll_type
Keyboard button poll type
2020-05-18 11:23:02 +03:00
27e2cbc7ea Remove unnecessary test 2020-05-18 12:22:26 +05:00
592dcbfedf Add PollAnswer type;
Add poll_answer_handler
2020-05-18 12:05:30 +05:00
03b02561a5 Add request_poll attribute to KeyboardButton;
Add KeyboardButtonPollType object
2020-05-18 11:48:54 +05:00
783fe56566 Merge pull request #848 from Badiboy/master
Correct processing of bool parameters. Some timeouts added.
2020-05-16 17:45:30 +03:00
2368421332 Correct processing of bool parameters. Some timeouts added. 2020-05-16 17:34:56 +03:00
046276b491 Merge pull request #841 from drforse/master
fix test 1
2020-05-12 21:02:01 +03:00
3de8140c0b fix test 1 2020-05-12 18:29:36 +01:00
e5ad9ab383 Merge pull request #840 from drforse/master
fix test
2020-05-12 20:21:40 +03:00
d04e708438 fix test 2020-05-12 18:09:04 +01:00
200c6ccd07 Merge pull request #839 from drforse/master
add PollAnswer, poll_answer_handler
2020-05-12 19:56:22 +03:00
75a018e18b add PollAnswer, poll_answer_handler; make User Serializable and Dictionaryble; some pep fixes 2020-05-12 01:09:34 +01:00
aacc494a55 Merge pull request #834 from tohabyuraev/master
Bot API 4.5 partial support (in regards to chat).
2020-05-11 23:11:11 +03:00
ee00d0458d Fix some bugs 2020-05-11 22:26:03 +03:00
a60253bf60 UPG: Add ChatPermissions, set_chat_permissions 2020-05-11 16:38:09 +03:00
a80927baf9 UPG: add setChatAdministratorCustomTitle 2020-05-09 23:23:08 +03:00
8be9bcc8ed UPG: Add custom_title, slow_mode_delay 2020-05-09 20:28:29 +03:00
1824637617 UPG: Refactoring InlineKeyboardMarkup 2020-05-09 20:06:33 +03:00
df640966c2 Merge pull request #831 from Badiboy/master
Fix to_dic->to_dict refactoring
2020-05-09 00:54:22 +03:00
2849e67029 Fix to_dic->to_dict refactoring 2020-05-09 00:51:18 +03:00
d02de07142 Merge pull request #830 from tohabyuraev/newcon
Add BotCommand, setMyCommands
2020-05-08 22:06:24 +03:00
a56fb8cc54 UPG: Add BotCommand, setMyCommands 2020-05-08 21:06:39 +03:00
c5e5af96d1 Merge pull request #827 from CSRedRat/patch-1
Add handler decorator example
2020-05-07 18:01:39 +03:00
5d388f7ec4 Add handler decorator example 2020-05-07 19:56:17 +05:00
6c45511605 Update version 3.7.1 2020-05-02 19:41:46 +08:00
d8a08638a7 Merge pull request #821 from Badiboy/master
send_poll revised to standart signature
2020-05-02 13:35:34 +03:00
e2d70da694 Fix poll options serialization 2020-05-02 13:27:39 +03:00
6e1cf24946 send_poll revised to standart signature 2020-05-02 13:09:52 +03:00
be0fe94ee8 Merge pull request #819 from Badiboy/master
Fix Deprecation warning due to invalid escape sequences
2020-05-01 11:51:45 +03:00
ef81868ebc Fix Deprecation warning due to invalid escape sequences 2020-05-01 11:25:51 +03:00
57fb8d2fad Bump version. 3.7.0 2020-04-28 19:18:44 +08:00
c2590ab5ed Merge pull request #815 from bedilbek/remove-type-hinting
Remove type hinting for python 3.5 compatibility
2020-04-27 22:48:04 +03:00
24deb8a51d Change class from new-style class to object class 2020-04-28 00:34:52 +05:00
d7ebaa5bb3 Fix importing dependencies 2020-04-28 00:24:47 +05:00
601b570b85 Fix python2.7 compatibility for class inheritance 2020-04-28 00:22:05 +05:00
bdaabc4752 Merge pull request #814 from Badiboy/master
Travis update: remove Python 2
2020-04-27 22:01:37 +03:00
72d088940c Readme content fix 2020-04-27 22:00:20 +03:00
f1a960c56b Travis update: remove Python 2 2020-04-27 21:56:37 +03:00
bcc3a1afb4 Remove Type Hinting 2020-04-27 23:43:39 +05:00
d0edf44774 Merge pull request #813 from drforse/patch-1
Fix Dice test
2020-04-27 18:36:17 +03:00
9c87ed3679 fix test 2020-04-27 16:20:30 +01:00
67cfa04737 Merge pull request #812 from Badiboy/master
Disable REDIS tests to save Travis
2020-04-27 17:47:30 +03:00
be5d7bb73d Disable REDIS tests to save Travis
To enable REDIS set
test_handler_backeds.REDIS_TEST = True
before running tests.
2020-04-27 17:46:19 +03:00
f3a65ef9b3 Merge pull request #811 from drforse/master
update dice as the api has updated
2020-04-27 17:14:39 +03:00
99c63e9eba add emoji field for dice 2020-04-27 06:30:05 +01:00
e89a552e06 Merge pull request #810 from Badiboy/master
Polls are updated to the latest API state
2020-04-26 23:23:15 +03:00
bb4f6a7190 Polls are updated to the latest API state.
Polls are updated to the latest API state.

Minor code refactoring.
2020-04-25 22:22:08 +03:00
197dd2a582 add requests session for use torpy 2020-04-24 23:30:10 +05:00
dc3df70f9f Merge pull request #807 from Badiboy/master
Minor code refactoring (naming)
2020-04-24 18:21:54 +03:00
aac9ce45a3 Merge remote-tracking branch 'upstream/master' 2020-04-24 18:19:55 +03:00
24e984adf8 Minor code refactoring (naming) 2020-04-24 18:19:30 +03:00
1ed3bc2a53 Merge pull request #803 from noideaw/patch-2
added can_invite_users parameter to restrict_chat_member function param description
2020-04-24 18:16:25 +03:00
ce11b6f523 Merge pull request #806 from noideaw/patch-1
added can_invite_users parameter to restrict_chat_member function
2020-04-24 18:15:05 +03:00
8c7c7b31b2 Update __init__.py
added can_invite_users parameter to restrict_chat_member function
2020-04-24 19:38:23 +04:30
39e3be6673 Merge pull request #804 from noideaw/patch-3
Add can_invite_users to restrict_chat_member #1
2020-04-24 01:34:58 +03:00
b1b2726ef6 Update apihelper.py
added can_invite_users parameter to restrict_chat_member function
2020-04-24 00:21:05 +04:30
da924dbaeb Update __init__.py
added can_invite_users parameter to restrict_chat_member function
2020-04-23 23:59:04 +04:30
7966def331 Merge pull request #801 from bedilbek/fix-middleware-invocations
Fix not needed invocations on typed middleware handlers
2020-04-20 11:10:04 +03:00
aab560b4ee Fix all the time invocations on typed_middleware handlers even if update did not have that update_type message 2020-04-20 11:30:03 +05:00
646bbb8330 Merge pull request #794 from drforse/master
Add Dice and send_dice
2020-04-16 15:56:46 +03:00
339a5c01c1 Merge pull request #789 from bedilbek/step-handler-backend
HandlerBackend Mechanism Implementation
Codebase Refactoring
2020-04-16 15:53:11 +03:00
615402e4f8 return a line as it was 2020-04-15 06:16:07 +01:00
51b1fb7695 added Dice and send_dice 2020-04-15 06:10:05 +01:00
0881e34381 Refactor tests 2020-04-15 01:11:43 +05:00
3aec66bc0d Remove class static variable 2020-04-15 01:11:43 +05:00
e7e7c58133 Add Memory, File, Redis Backend tests 2020-04-15 01:11:43 +05:00
003c5db37f Add filename checking 2020-04-15 01:11:43 +05:00
286188f380 Add Step/Reply Handler Backend Mechanism
Implement Memory, File, Redis Backends
2020-04-15 01:11:43 +05:00
dd726b0759 Merge pull request #792 from Badiboy/master
Refactoring and API conformance
2020-04-14 22:22:48 +03:00
1bd9f5187c Merge pull request #787 from bedilbek/middleware-handler-readme
Middleware Handler README Update
2020-04-12 02:20:05 +03:00
68330c9a07 Update contents with middleware handler 2020-04-12 01:44:15 +05:00
b912e4dbaf Update with middleware handler 2020-04-12 01:41:34 +05:00
dab80d421b Refactoring update 2 2020-04-11 17:38:47 +03:00
247fe6e947 Refactoring bugfix 2020-04-11 17:06:14 +03:00
995814d846 Refactoring and API conformance
Refactoring.

new_chat_member is out of support.

Bugfix in html_text.

Started Bot API conformance checking.
2020-04-11 16:54:25 +03:00
36a228da92 Merge pull request #786 from Badiboy/master
Possibility to use alternative serializer
2020-04-11 16:52:53 +03:00
ec86182f62 Possibility to use alternative serializer
With apihelper.CUSTOM_SERIALIZER you can replace pickle with other "dumper" like dill.
2020-04-11 13:42:34 +03:00
2c385bf077 Merge pull request #785 from bedilbek/middleware-support
Add Middleware Handler
2020-04-11 11:20:58 +03:00
56cbc2ff93 Add examples to better understand middleware handler 2020-04-11 13:03:52 +05:00
932ac9477b Add ENABLE_MIDDLEWARE=False in apihelpers to keep backward compatibility 2020-04-11 13:02:50 +05:00
1e242f2263 Add Middleware support 2020-04-08 23:13:19 +05:00
862f17c716 Merge pull request #776 from irevenko/master
Add new bot in README
2020-03-28 01:15:50 +08:00
ed7cf30034 Add new bot in README 2020-03-27 16:38:22 +02:00
100f6d77f6 Merge pull request #767 from Tkachov/master
Add @bot.poll_handler to be notified of new poll states
2020-03-09 13:58:23 +03:00
d2f9c51a5a Handle Poll update 2020-03-09 17:25:54 +07:00
12547efa08 Fix order for consistency in process_new_updates 2020-03-09 17:25:37 +07:00
9410a3d310 Merge pull request #762 from Lin-Buo-Ren/patch-4
Use proper language for * query mentions in README
2020-03-01 21:14:32 +03:00
a4e5a09ab2 Use proper language for * query mentions in README
Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
2020-02-27 16:49:28 +08:00
ebfba49a8f Merge pull request #761 from Lin-Buo-Ren/patch-3
Fix missing padding space in code sample comments in README
2020-02-27 11:45:59 +03:00
6e6420a331 Merge pull request #760 from HolidayMan/patch-1
Some clarification of custom listeners working
2020-02-27 11:45:04 +03:00
7ca629dc10 Fix missing padding space in code sample comments in README
Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
2020-02-27 16:41:13 +08:00
3ecb7cef3b Some clarification of custom listeners working 2020-02-27 00:59:21 +02:00
e789407774 Merge pull request #743 from Quantum-0/master
Add is_anonymous flag to Poll type
2020-02-14 16:49:54 +03:00
8f32dec5dd Merge pull request #744 from FaeeLoL/master
Add missed colon in readme
2020-02-14 16:48:44 +03:00
c57cfa3949 Add missed colon 2020-02-08 17:44:28 +03:00
dfac26706e Add is_anonymous flag to Poll type 2020-02-07 12:53:31 +03:00
385fa98bc6 Merge pull request #738 from andrey18106/patch-1
Added missed bracket
2020-01-30 01:10:51 +03:00
d68e89fc9a Added missed bracket 2020-01-28 20:56:03 +02:00
6023bae728 Merge pull request #735 from Lin-Buo-Ren/patch-2
Fix typo in README
2020-01-24 23:01:07 +03:00
b323a868f0 Fix typo in README
Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
2020-01-17 17:21:30 +08:00
583021d114 Update version to 3.6.7, 2020-01-14 16:33:05 +08:00
b1e5d00821 Merge pull request #728 from Badiboy/master
Design updates from #711
2020-01-08 20:29:12 +03:00
aa02ddb573 TAB fix
TAB fix
2020-01-08 20:17:25 +03:00
760ea5a2f0 Design updates from #711
Significant design updated from
https://github.com/eternnoir/pyTelegramBotAPI/pull/711
2020-01-08 20:06:40 +03:00
9b279dc562 Merge pull request #726 from Badiboy/master
Update test_types.py
2020-01-03 19:31:39 +03:00
5cd97ebc96 Update detailed_example.py
Vulgarity replaced.
2020-01-03 19:24:10 +03:00
b5ba2445d3 Update test_types.py
Updated test vectors for stickers.
2020-01-03 19:18:18 +03:00
7adec8bd90 Merge pull request #673 from TahaPY/master
Added Animation and is_animated for stickers
2020-01-03 17:51:53 +03:00
0603a0df4c Update types.py
Animation is moved before document to save backward compatibility. content_type = 'document' should override content_type = 'animation' to save previous behaviour.
2020-01-03 17:51:05 +03:00
59810b5e2a Merge pull request #620 from nev3rfail/send_animation
Added reduced version of sendAnimation (no width/height/thumb).
2020-01-03 17:12:29 +03:00
b999fea2ac Merge pull request #703 from voskresla/patch-1
Using Azure Functions for serverless bots.
2020-01-03 16:59:09 +03:00
a41dabf73c Merge pull request #725 from cclauss/patch-1
Travis CI: Drop EOL Py34 and add current Py38
2020-01-03 16:53:18 +03:00
5407801f62 Merge pull request #708 from xxsokolov/patch-1
Remove unused base_url from _make_request. Fixed misc error.
2020-01-03 16:52:47 +03:00
2efb33fc29 Merge branch 'master' into patch-1 2020-01-03 16:45:43 +03:00
620ea5dee0 Travis CI: Drop EOL Py34 and add current Py38 2020-01-03 14:36:08 +01:00
eaf44f1a6b Merge pull request #724 from Badiboy/master
Update version list in travis.yml
2020-01-03 02:08:00 +03:00
8c62b99057 Update .travis.yml
Travis: removed 2.6 and 3.3 (not supported). Added 3.7. Also added 3.8 (for experiment)
2020-01-03 02:05:32 +03:00
e3b126807e Merge pull request #713 from dtalkachou/patch-1
Correct work with empty base_url in make_request
2020-01-03 01:33:27 +03:00
769ff8008e Merge pull request #599 from KanerL/KanerL-patch-shipping-option
ShippingOption.add_price returns "self" (for chaining etc.).
2020-01-03 01:28:37 +03:00
0e0e2d97c0 Merge pull request #715 from Pablohn26/patch-1
Change chatid to chat_id to be the same as other examples
2020-01-03 01:19:47 +03:00
bb199024fd Merge pull request #593 from neoranger/patch-2
Update README.md
2020-01-03 01:02:35 +03:00
86644c05f7 Merge pull request #539 from Badiboy/master
"timeout" parameter for send_message
Fix kick_chat_member return type
HTML symbols not replaced
2020-01-03 00:50:24 +03:00
3a3bab5b92 Merge pull request #480 from SkymanOne/patch-1
create field forward_from_message_id in Message
2020-01-03 00:46:27 +03:00
bf844ed202 HTML symbols not replaced
HTML symbols not replaced because return is before replace.
2020-01-01 13:46:18 +03:00
fefb9d4555 Merge pull request #723 from LeoSvalov/master
Update README
2019-12-28 12:34:14 +08:00
a413a51221 Update README
Adding another bot that user pyTelegramBotAPI.
2019-12-24 16:25:58 +05:00
a71030dcdd Change chatid to chat_id to be the same as other examples
Change in README.md chatid to chat_id to be the same as other examples
2019-11-30 05:51:56 +01:00
68db599790 Delete duplicate string 2019-11-23 21:25:29 +03:00
a749acde15 Update apihelper.py #2
Merge Fixes # 684
2019-11-05 17:37:53 +03:00
5935a378ca Merge pull request #685 from cclauss/patch-1
Use ==/!= to compare str, bytes, and int literals
2019-10-30 21:26:00 +08:00
1dd94d6e6d Merge pull request #667 from desexcile/patch-2
Update Readme
2019-10-30 21:25:11 +08:00
2fb0f3fb4b Merge pull request #684 from xxsokolov/patch-1
Update apihelper.py
2019-10-30 21:24:51 +08:00
575fb9da7f Merge branch 'master' into patch-1 2019-10-30 21:24:43 +08:00
c6358f35d2 Merge pull request #688 from vryazanov/master
New content type related to Telegram Passport
2019-10-30 21:22:36 +08:00
20b87f2242 Merge pull request #701 from eternnoir/dependabot/pip/requests-2.20.0
Bump requests from 2.7.0 to 2.20.0
2019-10-30 21:22:16 +08:00
f4c215b0b8 Merge pull request #705 from keshamin/fix-578
Fixed #578
2019-10-30 21:21:49 +08:00
1a30a9a249 Fixed #578 2019-10-30 14:02:00 +03:00
e644ed910a Using Azure Functions for serverless bots.
Simple echo bot using Azure Functions as webhook.
2019-10-13 23:49:43 +03:00
8cb2da3775 Bump requests from 2.7.0 to 2.20.0
Bumps [requests](https://github.com/requests/requests) from 2.7.0 to 2.20.0.
- [Release notes](https://github.com/requests/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md)
- [Commits](https://github.com/requests/requests/compare/v2.7.0...v2.20.0)

Signed-off-by: dependabot[bot] <support@github.com>
2019-10-05 11:55:18 +00:00
f8e7c0f819 Merge branch 'master' into patch-2 2019-09-23 10:25:18 -03:00
f241ef1eac passport_data content type added 2019-08-27 11:55:14 +03:00
8f8276314e Merge pull request #1 from cmd410/master
Support for animated stickers
2019-08-16 20:42:08 +00:00
9e30cfbda6 Use ==/!= to compare str, bytes, and int literals
Identity is not the same thing as equality in Python.
2019-08-12 22:47:59 +02:00
6fb9e18385 Update apihelper.py
Hi, to indicate a third-party api-url (reverse proxy) added conditions.
Perhaps not the most elegant solution, but this functionality is very lacking.


apihelper.API_URL = "http://reverseproxy.example.com/bot{0}/{1}"
2019-08-12 17:09:52 +03:00
f0835a1a14 Support for animated stickers 2019-07-30 12:46:39 +03:00
be3b6f88e8 Added Animation 2019-07-14 18:53:59 +04:30
87e811ce3e Update Readme
Fixed source link
2019-06-29 09:39:14 +03:00
151880f391 Merge pull request #659 from OslikAi/master
Add Poll
2019-06-28 21:02:23 +08:00
bf91829088 Merge pull request #664 from vovawed/master
Added LoginUrl to types
2019-06-28 21:02:04 +08:00
56f0b0a0d4 Merge pull request #603 from nailerNAS/master
infinity_polling fix
2019-06-28 20:57:28 +08:00
2b8e77f749 Merge pull request #616 from painca/patch-1
edit message_handler doc
2019-06-28 20:56:47 +08:00
fba425265e Merge pull request #645 from setazer/patch-1
remove unnecessary f-strings
2019-06-28 20:56:29 +08:00
23069ac729 Merge pull request #644 from David-Lor/master
update bot list
2019-06-28 20:56:15 +08:00
7ab93f55a6 Merge pull request #666 from desexcile/patch-1
Update Readme
2019-06-28 20:55:46 +08:00
ba2705dc82 Merge remote-tracking branch 'origin/master' 2019-06-27 15:07:54 +03:00
3a1bdc2899 add Poll, sendPoll, stopPoll 2019-06-27 15:07:41 +03:00
4e57adbcb6 Update Readme
added @asadov_bot to Bot list using this Api
2019-06-26 10:54:59 +03:00
600002e158 Fixed bug with LoginUrl 2019-06-15 23:09:59 +03:00
3c62e9d391 Added LoginUrl to types 2019-06-15 22:59:41 +03:00
63df69aeb8 Delete my_tests.py 2019-06-06 22:23:11 +03:00
a8cf9f4ae5 Update README.md 2019-06-06 21:54:06 +03:00
b10e45f714 add Poll, sendPoll, stopPoll 2019-06-06 21:49:06 +03:00
9624b45314 add Poll, sendPoll, stopPoll 2019-06-06 21:47:08 +03:00
e26ad07965 Merge pull request #658 from FacuM/add_bot_patch
Update README.md
2019-05-31 11:24:14 +08:00
55c7b6373c Update README.md 2019-05-30 00:35:57 -03:00
ceceeb7d8c Update README.md 2019-05-24 15:05:20 +08:00
b76a69e036 Merge pull request #624 from kor0p/editMessageText
Add 'method' parameter to methods that edit message
2019-05-18 07:58:56 +08:00
e5700380bd Merge branch 'master' into master 2019-05-18 07:56:53 +08:00
47b53b8812 Merge pull request #649 from karipov/master
added creationdatebot to bots api list
2019-04-24 17:41:43 +08:00
2d0ebde481 added creationdatebot to bots api list 2019-04-24 11:29:52 +02:00
271b7e0642 Merge pull request #646 from airatk/master
Update README.md
2019-04-23 10:15:02 +08:00
f516438360 Update README.md 2019-04-21 18:34:10 +03:00
7dc9abffc6 remove unnecessary f-strings 2019-04-16 07:38:50 +07:00
2285d0466e update bot list
Remove areajugonesbot; add vigobustelegrambot
2019-04-09 11:32:15 +02:00
31dbe30489 Merge pull request #629 from iv8/patch-1
fix errors
2019-04-07 21:43:41 +08:00
iv8
c77307881d fix errors 2019-03-04 15:24:55 +08:00
1a58731fb7 Add 'method' parameter to methods that edit message 2019-02-23 16:15:20 +02:00
99df992a66 Added the method sendAnimation, which can be used instead of sendDocument to send animations, specifying their duration. 2019-02-15 18:46:18 +00:00
79e6a3166d edit message_handler doc 2019-01-20 23:04:11 +05:00
8005ca2f6c Update example for api server check webhook alive. 2018-12-29 23:49:10 +08:00
b82ed70ec9 fix syntax errors 2018-11-17 13:19:09 +02:00
18e37f3d20 sleep time timeout time instead of 5 seconds always 2018-11-17 12:58:56 +02:00
ceea457cf1 Update shipping option
Setting list of ShippingOptions like in payments_example.py
shipping_options = [
    ShippingOption(id='instant', title='WorldWide Teleporter').add_price(LabeledPrice('Teleporter', 1000)),
    ShippingOption(id='pickup', title='Local pickup').add_price(LabeledPrice('Pickup', 300))]
gives us [None,None],so It's better add_price to return self
2018-11-12 01:43:00 +02:00
4131b05733 Update README.md
Adding another bot that user pyTelegramBotAPI.
2018-11-05 15:11:31 -03:00
ad4be5c0ae Merge branch 'master' of https://github.com/eternnoir/pyTelegramBotAPI 2018-10-19 13:40:14 +03:00
a946b79839 Merge pull request #586 from khode-mohsen/patch-2
Update deep_linking.py
2018-10-19 10:08:05 +08:00
4eeca78f2f Merge pull request #585 from khode-mohsen/patch-1
Update echo_bot.py
2018-10-19 10:07:55 +08:00
2d6c2a345f Merge pull request #577 from rmed/master
Add check for parse_mode in BaseInlineQueryResultCached
2018-10-19 10:07:40 +08:00
e62eeb7ff2 Merge pull request #565 from uburuntu/analyzer-fixes
Some analyzer fixes
2018-10-19 10:06:37 +08:00
76fc8fbe5e Update deep_linking.py
add '#!/usr/bin/python' for direct execute
2018-10-19 03:47:19 +03:30
584955962e Update echo_bot.py
add '#!/usr/bin/env' for direct execute
2018-10-19 03:38:03 +03:30
b8f442d06b Update Bots using this API 2018-10-09 17:32:27 +08:00
891988be93 Added check for parse_mode in BaseInlineQueryResultCached. Should fix #571 2018-09-15 20:25:06 +02:00
8636b282d7 Merge branch 'master' into analyzer-fixes 2018-09-07 18:07:37 +03:00
36621bb22a fix: some intendation 2018-08-17 13:01:03 +03:00
99466017c5 enh: optimize imports 2018-08-17 12:54:26 +03:00
feec1dde56 fix: little style fixes 2018-08-17 12:49:37 +03:00
54eba946be fix: wrong arguments usage (fix fa038c2) 2018-08-17 12:48:59 +03:00
65a272b901 fix: python 2/3 compatibility in examples 2018-08-17 12:47:44 +03:00
6a4c7e731b fix: delete doubled Sticker class (left a new one) 2018-08-17 12:46:40 +03:00
8634e65249 Fix kick_chat_member decription
Fix kick_chat_member return value type description (should be boolean according to API and is boolean by fact).
2018-07-25 12:44:18 +03:00
27d442fabf timeout for send_message
Add optional "timeout" parameter to send_message (the same as exists in all other send_*).

Equal rights for all send functions! :)
2018-07-24 00:33:13 +03:00
d17d28a144 create field forward_from_message_id in Message
https://core.telegram.org/bots/api#message
2018-03-20 23:36:29 +03:00
36 changed files with 6366 additions and 1990 deletions

35
.github/workflows/setup_python.yml vendored Normal file
View File

@ -0,0 +1,35 @@
# This is a basic workflow to help you get started with Actions
name: Setup
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
#workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
all-setups:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.6','3.7','3.8','3.9', 'pypy-3.6', 'pypy-3.7' ] #'pypy-3.8', 'pypy-3.9' NOT SUPPORTED NOW
name: ${{ matrix.python-version }} and tests
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: |
pip3 install -r requirements.txt
python setup.py install
cd tests && py.test

6
.gitignore vendored
View File

@ -58,4 +58,8 @@ docs/_build/
# PyBuilder
target/
testMain.py
testMain.py
#VS Code
.vscode/
.DS_Store

View File

@ -1,12 +1,9 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
- "3.7"
- "3.8"
- "3.9"
- "pypy3"
install: "pip install -r requirements.txt"
script:

247
README.md
View File

@ -1,9 +1,16 @@
[![PyPi Package Version](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI)
[![PyPi downloads](https://img.shields.io/pypi/dm/pyTelegramBotAPI.svg)](https://pypi.org/project/pyTelegramBotAPI/)
# <p align="center">pyTelegramBotAPI
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.
[![Download Month](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI)
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-25-2021">5.3</a>!
##Contents
* [Getting started.](#getting-started)
* [Writing your first bot](#writing-your-first-bot)
@ -15,6 +22,7 @@
* [General use of the API](#general-use-of-the-api)
* [Message handlers](#message-handlers)
* [Callback Query handlers](#callback-query-handler)
* [Middleware handlers](#middleware-handler)
* [TeleBot](#telebot)
* [Reply markup](#reply-markup)
* [Inline Mode](#inline-mode)
@ -26,16 +34,19 @@
* [Using web hooks](#using-web-hooks)
* [Logging](#logging)
* [Proxy](#proxy)
* [API conformance](#api-conformance)
* [Change log](#change-log)
* [F.A.Q.](#faq)
* [Bot 2.0](#bot-20)
* [How can I distinguish a User and a GroupChat in message.chat?](#how-can-i-distinguish-a-user-and-a-groupchat-in-messagechat)
* [How can I handle reocurring ConnectionResetErrors?](#how-can-i-handle-reocurring-connectionreseterrors)
* [The Telegram Chat Group](#the-telegram-chat-group)
* [More examples](#more-examples)
* [Bots using this API](#bots-using-this-api)
## Getting started.
This API is tested with Python 2.6, Python 2.7, Python 3.4, Pypy and Pypy 3.
This API is tested with Python Python 3.6-3.9 and Pypy 3.
There are two ways to install the library:
* Installation using pip (a Python package manager)*:
@ -71,7 +82,7 @@ Then, open the file and create an instance of the TeleBot class.
```python
import telebot
bot = telebot.TeleBot("TOKEN")
bot = telebot.TeleBot("TOKEN", parse_mode=None) # You can set parse_mode by default. HTML or MARKDOWN
```
*Note: Make sure to actually replace TOKEN with your own API token.*
@ -140,7 +151,7 @@ Outlined below are some general use cases of the API.
#### Message handlers
A message handler is a function that is decorated with the `message_handler` decorator of a TeleBot instance. Message handlers consist of one or multiple filters.
Each filter much return True for a certain message in order for a message handler to become eligible to handle that message. A message handler is declared in the following way (provided `bot` is an instance of TeleBot):
Each filter must return True for a certain message in order for a message handler to become eligible to handle that message. A message handler is declared in the following way (provided `bot` is an instance of TeleBot):
```python
@bot.message_handler(filters)
def function_name(message):
@ -154,7 +165,7 @@ TeleBot supports the following filters:
|name|argument(s)|Condition|
|:---:|---| ---|
|content_types|list of strings (default `['text']`)|`True` if message.content_type is in the list of strings.|
|regexp|a regular expression as a string|`True` if `re.search(regexp_arg)` returns `True` and `message.content_type == 'text'` (See [Python Regular Expressions](https://docs.python.org/2/library/re.html)|
|regexp|a regular expression as a string|`True` if `re.search(regexp_arg)` returns `True` and `message.content_type == 'text'` (See [Python Regular Expressions](https://docs.python.org/2/library/re.html))|
|commands|list of strings|`True` if `message.content_type == 'text'` and `message.text` starts with a command that is in the list of strings.|
|func|a function (lambda or function reference)|`True` if the lambda or function reference returns `True`
@ -179,17 +190,17 @@ def handle_docs_audio(message):
def handle_message(message):
pass
#Handles all messages for which the lambda returns True
# Handles all messages for which the lambda returns True
@bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document'])
def handle_text_doc(message):
pass
#Which could also be defined as:
# Which could also be defined as:
def test_message(message):
return message.document.mime_type == 'text/plain'
@bot.message_handler(func=test_message, content_types=['document'])
def handle_text_doc(message)
def handle_text_doc(message):
pass
# Handlers can be stacked to create a function which will be called if either message_handler is eligible
@ -202,27 +213,80 @@ def send_something(message):
**Important: all handlers are tested in the order in which they were declared**
#### Edited Message handlers
Same as Message handlers
Handle edited messages
`@bot.edited_message_handler(filters) # <- passes a Message type object to your function`
#### channel_post_handler
Same as Message handlers
Handle channel post messages
`@bot.channel_post_handler(filters) # <- passes a Message type object to your function`
#### edited_channel_post_handler
Same as Message handlers
Handle edited channel post messages
`@bot.edited_channel_post_handler(filters) # <- passes a Message type object to your function`
#### Callback Query Handler
In bot2.0 update. You can get `callback_query` in update object. In telebot use `callback_query_handler` to process callback_querys.
Handle callback queries
```python
@bot.callback_query_handler(func=lambda call: True)
def test_callback(call):
def test_callback(call): # <- passes a CallbackQuery type object to your function
logger.info(call)
```
#### Inline Handler
Handle inline queries
`@bot.inline_handler() # <- passes a InlineQuery type object to your function`
#### Chosen Inline Handler
Handle chosen inline results
`@bot.chosen_inline_handler() # <- passes a ChosenInlineResult type object to your function`
#### Shipping Query Handler
Handle shipping queries
`@bot.shipping_query_handeler() # <- passes a ShippingQuery type object to your function`
#### Pre Checkout Query Handler
Handle pre checkoupt queries
`@bot.pre_checkout_query_handler() # <- passes a PreCheckoutQuery type object to your function`
#### Poll Handler
Handle poll updates
`@bot.poll_handler() # <- passes a Poll type object to your function`
#### Poll Answer Handler
Handle poll answers
`@bot.poll_answer_handler() # <- passes a PollAnswer type object to your function`
#### My Chat Member Handler
Handle updates of a the bot's member status in a chat
`@bot.my_chat_member_handler() # <- passes a ChatMemberUpdated type object to your function`
#### Chat Member Handler
Handle updates of a chat member's status in a chat
`@bot.chat_member_handler() # <- passes a ChatMemberUpdated type object to your function`
*Note: "chat_member" updates are not requested by default. If you want to allow all update types, set `allowed_updates` in `bot.polling()` / `bot.infinity_polling()` to `util.update_types`*
#### Middleware Handler
A middleware handler is a function that allows you to modify requests or the bot context as they pass through the
Telegram to the bot. You can imagine middleware as a chain of logic connection handled before any other handlers are
executed. Middleware processing is disabled by default, enable it by setting `apihelper.ENABLE_MIDDLEWARE = True`.
```python
apihelper.ENABLE_MIDDLEWARE = True
@bot.middleware_handler(update_types=['message'])
def modify_message(bot_instance, message):
# modifying the message before it reaches any other handler
message.another_text = message.text + ':changed'
@bot.message_handler(commands=['start'])
def start(message):
# the message is already modified when it reaches message handler
assert message.another_text == message.text + ':changed'
```
There are other examples using middleware handler in the [examples/middleware](examples/middleware) directory.
#### TeleBot
```python
import telebot
@ -235,6 +299,7 @@ tb = telebot.TeleBot(TOKEN) #create a new Telegram Bot object
# - interval: True/False (default False) - The interval between polling requests
# Note: Editing this parameter harms the bot's response time
# - timeout: integer (default 20) - Timeout in seconds for long polling.
# - allowed_updates: List of Strings (default None) - List of update types to request
tb.polling(none_stop=False, interval=0, timeout=20)
# getMe
@ -250,7 +315,10 @@ updates = tb.get_updates()
updates = tb.get_updates(1234,100,20) #get_Updates(offset, limit, timeout):
# sendMessage
tb.send_message(chatid, text)
tb.send_message(chat_id, text)
# editMessageText
tb.edit_message_text(new_text, chat_id, message_id)
# forwardMessage
tb.forward_message(to_chat_id, from_chat_id, message_id)
@ -371,7 +439,7 @@ More information about [Inline mode](https://core.telegram.org/bots/inline).
#### inline_handler
Now, you can use inline_handler to get inline_query in telebot.
Now, you can use inline_handler to get inline queries in telebot.
```python
@ -425,8 +493,20 @@ Refer [Bot Api](https://core.telegram.org/bots/api#messageentity) for extra deta
## Advanced use of the API
### Using local Bot API Sever
Since version 5.0 of the Bot API, you have the possibility to run your own [Local Bot API Server](https://core.telegram.org/bots/api#using-a-local-bot-api-server).
pyTelegramBotAPI also supports this feature.
```python
from telebot import apihelper
apihelper.API_URL = "http://localhost:4200/bot{0}/{1}"
```
**Important: Like described [here](https://core.telegram.org/bots/api#logout), you have to log out your bot from the Telegram server before switching to your local API server. in pyTelegramBotAPI use `bot.log_out()`**
*Note: 4200 is an example port*
### Asynchronous delivery of messages
There exists an implementation of TeleBot which executes all `send_xyz` and the `get_me` functions asynchronously. This can speed up you bot __significantly__, but it has unwanted side effects if used without caution.
There exists an implementation of TeleBot which executes all `send_xyz` and the `get_me` functions asynchronously. This can speed up your bot __significantly__, but it has unwanted side effects if used without caution.
To enable this behaviour, create an instance of AsyncTeleBot instead of TeleBot.
```python
tb = telebot.AsyncTeleBot("TOKEN")
@ -455,6 +535,19 @@ large_text = open("large_text.txt", "rb").read()
# Split the text each 3000 characters.
# split_string returns a list with the splitted text.
splitted_text = util.split_string(large_text, 3000)
for text in splitted_text:
tb.send_message(chat_id, text)
```
Or you can use the new `smart_split` function to get more meaningful substrings:
```python
from telebot import util
large_text = open("large_text.txt", "rb").read()
# Splits one string into multiple strings, with a maximum amount of `chars_per_string` (max. 4096)
# Splits by last '\n', '. ' or ' ' in exactly this priority.
# smart_split returns a list with the splitted text.
splitted_text = util.smart_split(large_text, chars_per_string=3000)
for text in splitted_text:
tb.send_message(chat_id, text)
```
@ -465,7 +558,10 @@ The TeleBot constructor takes the following optional arguments:
TeleBot should execute message handlers on it's polling Thread.
### The listener mechanism
As an alternative to the message handlers, one can also register a function as a listener to TeleBot. Example:
As an alternative to the message handlers, one can also register a function as a listener to TeleBot.
NOTICE: handlers won't disappear! Your message will be processed both by handlers and listeners. Also, it's impossible to predict which will work at first because of threading. If you use threaded=False, custom listeners will work earlier, after them handlers will be called.
Example:
```python
def handle_messages(messages):
for message in messages:
@ -479,7 +575,7 @@ bot.polling()
### Using web hooks
When using webhooks telegram sends one Update per call, for processing it you should call process_new_messages([update.message]) when you recieve it.
There are some examples using webhooks in the *examples/webhook_examples* directory.
There are some examples using webhooks in the [examples/webhook_examples](examples/webhook_examples) directory.
### Logging
@ -500,7 +596,7 @@ You can use proxy for request. `apihelper.proxy` object will use by call `reques
```python
from telebot import apihelper
apihelper.proxy = {'http':'http://10.10.1.10:3128'}
apihelper.proxy = {'http':'http://127.0.0.1:3128'}
```
If you want to use socket5 proxy you need install dependency `pip install requests[socks]` and make sure, that you have the latest version of `gunicorn`, `PySocks`, `pyTelegramBotAPI`, `requests` and `urllib3`.
@ -510,6 +606,45 @@ apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'}
```
## API conformance
* [Bot API 5.3](https://core.telegram.org/bots/api#june-25-2021) - ChatMemberXXX classes are full copies of ChatMember
* ✔ [Bot API 5.2](https://core.telegram.org/bots/api#april-26-2021)
* ✔ [Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021)
* ✔ [Bot API 5.0](https://core.telegram.org/bots/api-changelog#november-4-2020)
* ✔ [Bot API 4.9](https://core.telegram.org/bots/api-changelog#june-4-2020)
* ✔ [Bot API 4.8](https://core.telegram.org/bots/api-changelog#april-24-2020)
* ✔ [Bot API 4.7](https://core.telegram.org/bots/api-changelog#march-30-2020)
* ✔ [Bot API 4.6](https://core.telegram.org/bots/api-changelog#january-23-2020)
* [Bot API 4.5](https://core.telegram.org/bots/api-changelog#december-31-2019) - No nested MessageEntities and Markdown2 support
* ✔ [Bot API 4.4](https://core.telegram.org/bots/api-changelog#july-29-2019)
* ✔ [Bot API 4.3](https://core.telegram.org/bots/api-changelog#may-31-2019)
* ✔ [Bot API 4.2](https://core.telegram.org/bots/api-changelog#april-14-2019)
* [Bot API 4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) - No Passport support
* [Bot API 4.0](https://core.telegram.org/bots/api-changelog#july-26-2018) - No Passport support
* ✔ [Bot API 3.6](https://core.telegram.org/bots/api-changelog#february-13-2018)
* ✔ [Bot API 3.5](https://core.telegram.org/bots/api-changelog#november-17-2017)
* ✔ [Bot API 3.4](https://core.telegram.org/bots/api-changelog#october-11-2017)
* ✔ [Bot API 3.3](https://core.telegram.org/bots/api-changelog#august-23-2017)
* ✔ [Bot API 3.2](https://core.telegram.org/bots/api-changelog#july-21-2017)
* ✔ [Bot API 3.1](https://core.telegram.org/bots/api-changelog#june-30-2017)
* ✔ [Bot API 3.0](https://core.telegram.org/bots/api-changelog#may-18-2017)
* ✔ [Bot API 2.3.1](https://core.telegram.org/bots/api-changelog#december-4-2016)
* ✔ [Bot API 2.3](https://core.telegram.org/bots/api-changelog#november-21-2016)
* ✔ [Bot API 2.2](https://core.telegram.org/bots/api-changelog#october-3-2016)
* ✔ [Bot API 2.1](https://core.telegram.org/bots/api-changelog#may-22-2016)
* ✔ [Bot API 2.0](https://core.telegram.org/bots/api-changelog#april-9-2016)
## Change log
27.04.2020 - Poll and Dice are up to date.
Python2 conformance is not checked any more due to EOL.
11.04.2020 - Refactoring. new_chat_member is out of support. Bugfix in html_text. Started Bot API conformance checking.
06.06.2019 - Added polls support (Poll). Added functions send_poll, stop_poll
## F.A.Q.
### Bot 2.0
@ -524,20 +659,24 @@ Telegram Bot API support new type Chat for message.chat.
- Check the ```type``` attribute in ```Chat``` object:
-
```python
if message.chat.type == private:
if message.chat.type == "private":
# private chat message
if message.chat.type == group:
if message.chat.type == "group":
# group chat message
if message.chat.type == supergroup:
if message.chat.type == "supergroup":
# supergroup chat message
if message.chat.type == channel:
if message.chat.type == "channel":
# channel message
```
### How can I handle reocurring ConnectionResetErrors?
Bot instances that were idle for a long time might be rejected by the server when sending a message due to a timeout of the last used session. Add `apihelper.SESSION_TIME_TO_LIVE = 5 * 60` to your initialisation to force recreation after 5 minutes without any activity.
## The Telegram Chat Group
Get help. Discuss. Chat.
@ -557,12 +696,12 @@ Get help. Discuss. Chat.
* [Send to Kindle Bot](https://telegram.me/Send2KindleBot) by *GabrielRF* - Send to Kindle files or links to files.
* [Telegram LMGTFY_bot](https://github.com/GabrielRF/telegram-lmgtfy_bot) ([source](https://github.com/GabrielRF/telegram-lmgtfy_bot)) by *GabrielRF* - Let me Google that for you.
* [Telegram UrlProBot](https://github.com/GabrielRF/telegram-urlprobot) ([source](https://github.com/GabrielRF/telegram-urlprobot)) by *GabrielRF* - URL shortener and URL expander.
* [Telegram Proxy Bot](https://bitbucket.org/master_groosha/telegram-proxy-bot) by *Groosha* - A simple BITM (bot-in-the-middle) for Telegram acting as some kind of "proxy".
* [Telegram Proxy Bot](https://github.com/mrgigabyte/proxybot) by *mrgigabyte* - `Credits for the original version of this bot goes to` **Groosha** `, simply added certain features which I thought were needed`.
* [RadRetroRobot](https://github.com/Tronikart/RadRetroRobot) by *Tronikart* - Multifunctional Telegram Bot RadRetroRobot.
* [League of Legends bot](https://telegram.me/League_of_Legends_bot) ([source](https://github.com/i32ropie/lol)) by *i32ropie*
* [NeoBot](https://github.com/neoranger/NeoBot) by *neoranger*
* [NeoBot](https://github.com/neoranger/NeoBot) by [@NeoRanger](https://github.com/neoranger)
* [TagAlertBot](https://github.com/pitasi/TagAlertBot) by *pitasi*
* [ColorCodeBot](https://t.me/colorcodebot) ([source](https://github.com/andydecleyre/colorcodebot)) - Share code snippets as beautifully syntax-highlighted HTML and/or images.
* [ComedoresUGRbot](http://telegram.me/ComedoresUGRbot) ([source](https://github.com/alejandrocq/ComedoresUGRbot)) by [*alejandrocq*](https://github.com/alejandrocq) - Telegram bot to check the menu of Universidad de Granada dining hall.
* [picpingbot](https://web.telegram.org/#/im?p=%40picpingbot) - Fun anonymous photo exchange by Boogie Muffin.
* [TheZigZagProject](https://github.com/WebShark025/TheZigZagProject) - The 'All In One' bot for Telegram! by WebShark025
@ -576,16 +715,50 @@ Get help. Discuss. Chat.
* [EmaProject](https://github.com/halkliff/emaproject) by [*halkliff*](https://github.com/halkliff) - Ema - Eastern Media Assistant was made thinking on the ease-to-use feature. Coding here is simple, as much as is fast and powerful.
* [filmratingbot](http://t.me/filmratingbot)([source](https://github.com/jcolladosp/film-rating-bot)) by [*jcolladosp*](https://github.com/jcolladosp) - Telegram bot using the Python API that gets films rating from IMDb and metacritic
* [you2mp3bot](http://t.me/you2mp3bot)([link](https://storebot.me/bot/you2mp3bot)) - This bot can convert a Youtube video to Mp3. All you need is send the URL video.
* [areajugonesbot](http://t.me/areajugonesbot)([link](http://t.me/areajugonesbot)) - The areajugonesbot sends news published on the videogames blog Areajugones to Telegram.
* [Send2Kindlebot](http://t.me/Send2KindleBot) ([source](https://github.com/GabrielRF/Send2KindleBot)) by *GabrielRF* - Send to Kindle service.
* [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service.
* [filex_bot](http://t.me/filex_bot)([link](https://github.com/victor141516/FileXbot-telegram))
* [Spbu4UBot](http://t.me/Spbu4UBot)([link](https://github.com/EeOneDown/spbu4u)) by *EeOneDown* - Bot with timetables for SPbU students.
* [SmartySBot](http://t.me/ZDU_bot)([link](https://github.com/0xVK/SmartySBot)) by *0xVK* - Telegram timetable bot, for Zhytomyr Ivan Franko State University students.
* [SmartySBot](http://t.me/ZDU_bot)([link](https://github.com/0xVK/SmartySBot)) by *0xVK* - Telegram timetable bot, for Zhytomyr Ivan Franko State University students.
* [yandex_music_bot](http://t.me/yandex_music_bot)- Downloads tracks/albums/public playlists from Yandex.Music streaming service for free.
* [LearnIt](https://t.me/LearnItbot)([link](https://github.com/tiagonapoli/LearnIt)) - A Telegram Bot created to help people to memorize other languages vocabulary.
* [MusicQuiz_bot](https://t.me/MusicQuiz_bot) by [Etoneja](https://github.com/Etoneja) - Listen to audiosamles and try to name the performer of the song.
* [MusicQuiz_bot](https://t.me/MusicQuiz_bot) by [Etoneja](https://github.com/Etoneja) - Listen to audio samples and try to name the performer of the song.
* [Bot-Telegram-Shodan ](https://github.com/rubenleon/Bot-Telegram-Shodan) by [rubenleon](https://github.com/rubenleon)
Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh.
* [MandangoBot](https://t.me/MandangoBot) by @Alvaricias - Bot for managing Marvel Strike Force alliances (only in spanish, atm).
* [ManjaroBot](https://t.me/ManjaroBot) by [@NeoRanger](https://github.com/neoranger) - Bot for Manjaro Linux Spanish group with a lot of info for Manjaro Newbies.
* [VigoBusTelegramBot](https://t.me/vigobusbot) ([GitHub](https://github.com/Pythoneiro/VigoBus-TelegramBot)) - Bot that provides buses coming to a certain stop and their remaining time for the city of Vigo (Galicia - Spain)
* [kaishnik-bot](https://t.me/kaishnik_bot) ([source](https://github.com/airatk/kaishnik-bot)) by *airatk* - bot which shows all the necessary information to KNTRU-KAI students.
* [Creation Date](https://t.me/creationdatebot) by @karipov - interpolates account creation dates based on telegram given IDs
* [m0xbot](https://t.me/m0xbot) by [kor0p](https://github.com/kor0p) - tic-tac-toe.
* [kboardbot](https://t.me/kboardbot) by [kor0p](https://github.com/kor0p) - inline switches keyboard layout (English, Hebrew, Ukrainian, Russian).
* [Robbie](https://t.me/romdeliverybot) ([source](https://github.com/FacuM/romdeliverybot_support)) by @FacuM - Support Telegram bot for developers and maintainers.
* [AsadovBot](https://t.me/asadov_bot) ([source](https://github.com/desexcile/BotApi)) by @DesExcile - Сatalog of poems by Eduard Asadov.
* [thesaurus_com_bot](https://t.me/thesaurus_com_bot) ([source](https://github.com/LeoSvalov/words-i-learn-bot)) by @LeoSvalov - words and synonyms from [dictionary.com](https://www.dictionary.com) and [thesaurus.com](https://www.thesaurus.com) in the telegram.
* [InfoBot](https://t.me/info2019_bot) ([source](https://github.com/irevenko/info-bot)) by @irevenko - An all-round bot that displays some statistics (weather, time, crypto etc...)
* [FoodBot](https://t.me/ChensonUz_bot) ([source](https://github.com/Fliego/old_restaurant_telegram_chatbot)) by @Fliego - a simple bot for food ordering
* [Sporty](https://t.me/SportydBot) ([source](https://github.com/0xnu/sporty)) by @0xnu - Telegram bot for displaying the latest news, sports schedules and injury updates.
* [Neural style transfer](https://t.me/ebanyivolshebnikBot) ([source](https://github.com/timbyxty/StyleTransfer-tgbot)) by @timbyxty - bot for transferring style from one picture to another based on neural network.
* [JoinGroup Silencer Bot](https://t.me/joingroup_silencer_bot) ([source](https://github.com/zeph1997/Telegram-Group-Silencer-Bot)) by [@zeph1997](https://github.com/zeph1997) - A Telegram Bot to remove "join group" and "removed from group" notifications.
* [AdviceBook](https://t.me/adviceokbot) by [@barbax7](https://github.com/barbax7) - A Telegram Bot that allows you to receive random reading tips when you don't know which book to read.
* [Blue_CC_Bot](https://t.me/Blue_CC_Bot) by [@Akash](https://github.com/BLUE-DEVIL1134) - A Telegram Bot Which Checks Your Given Credit Cards And Says Which Is A Real,Card And Which Is Fake.
* [RandomInfoBot](https://t.me/RandomInfoBot) by [@Akash](https://github.com/BLUE-DEVIL1134) - A Telegram Bot Which Generates Random Information Of Humans Scraped From Over 13 Websites.
* [TasksListsBot](https://t.me/TasksListsBot) ([source](https://github.com/Pablo-Davila/TasksListsBot)) by [@Pablo-Davila](https://github.com/Pablo-Davila) - A (tasks) lists manager bot for Telegram.
* [MyElizaPsychologistBot](https://t.me/TasksListsBot) ([source](https://github.com/Pablo-Davila/MyElizaPsychologistBot)) by [@Pablo-Davila](https://github.com/Pablo-Davila) - An implementation of the famous Eliza psychologist chatbot.
* [Evdembot](https://t.me/Evdembot) by Adem Kavak. A bot that informs you about everything you want.
* [Frcstbot](https://t.me/frcstbot) ([source](https://github.com/Mrsqd/frcstbot_public)) by [Mrsqd](https://github.com/Mrsqd). A Telegram bot that will always be happy to show you the weather forecast.
* [Bot Hour](https://t.me/roadtocode_bot) a little bot that say the time in different countries by [@diegop384](https://github.com/diegop384) [repo](https://github.com/diegop384/telegrambothour)
* [moodforfood_bot](https://t.me/moodforfood_bot) This bot will provide you with a list of food place(s) near your current Telegram location, which you are prompted to share. The API for all this info is from https://foursquare.com/. by [@sophiamarani](https://github.com/sophiamarani)
* [Donation with Amazon](https://t.me/donamazonbot) by [@barbax7](https://github.com/barbax7) This bot donates amazon advertising commissions to the non-profit organization chosen by the user.
* [COVID-19 Galicia Bot](https://t.me/covid19_galicia_bot) by [@dgarcoe](https://github.com/dgarcoe) This bot provides daily data related to the COVID19 crisis in Galicia (Spain) obtained from official government sources.
* [MineGramBot](https://github.com/ModischFabrications/MineGramBot) by [ModischFabrications](https://github.com/ModischFabrications). This bot can start, stop and monitor a minecraft server.
* [Tabletop DiceBot](https://github.com/dexpiper/tabletopdicebot) by [dexpiper](https://github.com/dexpiper). This bot can roll multiple dices for RPG-like games, add positive and negative modifiers and show short descriptions to the rolls.
* [BarnameKon](https://t.me/BarnameKonBot) by [Anvaari](https://github.com/anvaari). This Bot make "Add to google calendar" link for your events. It give information about event and return link. It work for Jalali calendar and in Tehran Time. [Source code](https://github.com/anvaari/BarnameKon)
* [Price Tracker](https://t.me/trackokbot) by [@barbax7](https://github.com/barbax7). This bot tracks amazon.it product's prices the user is interested to and notify him when one price go down.
* [Torrent Hunt](https://t.me/torrenthuntbot) by [@Hemantapkh](https://github.com/hemantapkh/torrenthunt). Torrent Hunt bot is a multilingual bot with inline mode support to search and explore torrents from 1337x.to.
* Translator bot by [Areeg Fahad (source)](https://github.com/AREEG94FAHAD/translate_text_bot). This bot can be use to translate texts.
* Digital Cryptocurrency bot by [Areeg Fahad (source)](https://github.com/AREEG94FAHAD/currencies_bot). With this bot, you can now monitor the prices of more than 12 digital Cryptocurrency.
* [Anti-Tracking Bot](https://t.me/AntiTrackingBot) by [Leon Heess (source)](https://github.com/leonheess/AntiTrackingBot). Send any link, and the bot tries its best to remove all tracking from the link you sent.
* [Developer Bot](https://t.me/IndDeveloper_bot) by [Vishal Singh](https://github.com/vishal2376) [(source code)](https://github.com/vishal2376/telegram-bot) This telegram bot can do tasks like GitHub search & clone,provide c++ learning resources ,Stackoverflow search, Codeforces(profile visualizer,random problems)
* [oneIPO bot](https://github.com/aaditya2200/IPO-proj) by [Aadithya](https://github.com/aaditya2200) & [Amol Soans](https://github.com/AmolDerickSoans) This Telegram bot provides live updates , data and documents on current and upcoming IPOs(Initial Public Offerings)
**Want to have your bot listed here? Just make a pull request.**

View File

@ -0,0 +1,33 @@
import telebot
from telebot import types,util
bot = telebot.TeleBot("token")
#chat_member_handler. When status changes, telegram gives update. check status from old_chat_member and new_chat_member.
@bot.chat_member_handler()
def chat_m(message: types.ChatMemberUpdated):
old = message.old_chat_member
new = message.new_chat_member
if new.status == "member":
bot.send_message(message.chat.id,"Hello {name}!".format(name=new.user.first_name)) # Welcome message
#if bot is added to group, this handler will work
@bot.my_chat_member_handler()
def my_chat_m(message: types.ChatMemberUpdated):
old = message.old_chat_member
new = message.new_chat_member
if new.status == "member":
bot.send_message(message.chat.id,"Somebody added me to group") # Welcome message, if bot was added to group
bot.leave_chat(message.chat.id)
#content_Type_service is:
#'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created',
#'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message',
#'proximity_alert_triggered', 'voice_chat_scheduled', 'voice_chat_started', 'voice_chat_ended',
#'voice_chat_participants_invited', 'message_auto_delete_timer_changed'
# this handler deletes service messages
@bot.message_handler(content_types=util.content_type_service)
def delall(message: types.Message):
bot.delete_message(message.chat.id,message.message_id)
bot.polling(allowed_updates=util.update_types)

View File

@ -1,3 +1,5 @@
#!/usr/bin/python
# This example shows how to implement deep linking (https://core.telegram.org/bots#deep-linking)
# with the pyTelegramBotAPI.
# Note: This is not a working, production-ready sample.
@ -31,34 +33,38 @@
# steps are not shown here. Only steps 5 to 7 are illustrated, some in pseudo-code, with this example.
import telebot
import time
bot = telebot.TeleBot('TOKEN')
def extract_unique_code(text):
# Extracts the unique_code from the sent /start command.
return text.split()[1] if len(text.split()) > 1 else None
def in_storage(unique_code):
# (pseudo-code) Should check if a unique code exists in storage
return True
def get_username_from_storage(unique_code):
# (pseudo-code) Does a query to the storage, retrieving the associated username
# Should be replaced by a real database-lookup.
return "ABC" if in_storage(unique_code) else None
def save_chat_id(chat_id, username):
# (pseudo-code) Save the chat_id->username to storage
# Should be replaced by a real database query.
pass
@bot.message_handler(commands=['start'])
def send_welcome(message):
unique_code = extract_unique_code(message.text)
if unique_code: # if the '/start' command contains a unique_code
if unique_code: # if the '/start' command contains a unique_code
username = get_username_from_storage(unique_code)
if username: # if the username exists in our database
if username: # if the username exists in our database
save_chat_id(message.chat.id, username)
reply = "Hello {0}, how are you?".format(username)
else:
@ -67,4 +73,5 @@ def send_welcome(message):
reply = "Please visit me via a provided URL from the website."
bot.reply_to(message, reply)
bot.polling()

View File

@ -2,9 +2,10 @@
This is a detailed example using almost every command of the API
"""
import time
import telebot
from telebot import types
import time
TOKEN = '<token_string>'
@ -12,14 +13,14 @@ knownUsers = [] # todo: save these in a file,
userStep = {} # so they won't reset every time the bot restarts
commands = { # command description used in the "help" command
'start': 'Get used to the bot',
'help': 'Gives you information about the available commands',
'sendLongText': 'A test using the \'send_chat_action\' command',
'getImage': 'A test using multi-stage messages, custom keyboard, and media sending'
'start' : 'Get used to the bot',
'help' : 'Gives you information about the available commands',
'sendLongText': 'A test using the \'send_chat_action\' command',
'getImage' : 'A test using multi-stage messages, custom keyboard, and media sending'
}
imageSelect = types.ReplyKeyboardMarkup(one_time_keyboard=True) # create the image selection keyboard
imageSelect.add('cock', 'pussy')
imageSelect.add('Mickey', 'Minnie')
hideBoard = types.ReplyKeyboardRemove() # if sent as reply_markup, will hide the keyboard
@ -33,7 +34,7 @@ def get_user_step(uid):
else:
knownUsers.append(uid)
userStep[uid] = 0
print "New user detected, who hasn't used \"/start\" yet"
print("New user detected, who hasn't used \"/start\" yet")
return 0
@ -45,7 +46,7 @@ def listener(messages):
for m in messages:
if m.content_type == 'text':
# print the sent message to the console
print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text
print(str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text)
bot = telebot.TeleBot(TOKEN)
@ -104,15 +105,15 @@ def msg_image_select(m):
# for some reason the 'upload_photo' status isn't quite working (doesn't show at all)
bot.send_chat_action(cid, 'typing')
if text == "cock": # send the appropriate image based on the reply to the "/getImage" command
if text == 'Mickey': # send the appropriate image based on the reply to the "/getImage" command
bot.send_photo(cid, open('rooster.jpg', 'rb'),
reply_markup=hideBoard) # send file and hide keyboard, after image is sent
userStep[cid] = 0 # reset the users step back to 0
elif text == "pussy":
elif text == 'Minnie':
bot.send_photo(cid, open('kitten.jpg', 'rb'), reply_markup=hideBoard)
userStep[cid] = 0
else:
bot.send_message(cid, "Don't type bullsh*t, if I give you a predefined keyboard!")
bot.send_message(cid, "Please, use the predefined keyboard!")
bot.send_message(cid, "Please try again")
@ -128,4 +129,5 @@ def command_default(m):
# this is the standard reply to a normal message
bot.send_message(m.chat.id, "I don't understand \"" + m.text + "\"\nMaybe try the help page at /help")
bot.polling()

View File

@ -1,3 +1,5 @@
#!/usr/bin/python
# This is a simple echo bot using the decorator mechanism.
# It echoes any incoming text messages.
@ -7,6 +9,7 @@ API_TOKEN = '<api_token>'
bot = telebot.TeleBot(API_TOKEN)
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
@ -21,4 +24,5 @@ I am here to echo your kind words back to you. Just say anything nice and I'll s
def echo_message(message):
bot.reply_to(message, message.text)
bot.polling()

View File

@ -1,8 +1,9 @@
# This example show how to write an inline mode telegram bot use pyTelegramBotAPI.
import telebot
import time
import sys
import logging
import sys
import time
import telebot
from telebot import types
API_TOKEN = '<TOKEN>'
@ -50,7 +51,7 @@ def query_video(inline_query):
print(e)
@bot.inline_handler(lambda query: len(query.query) is 0)
@bot.inline_handler(lambda query: len(query.query) == 0)
def default_query(inline_query):
try:
r = types.InlineQueryResultArticle('1', 'default', types.InputTextMessageContent('default'))
@ -69,5 +70,5 @@ if __name__ == '__main__':
try:
main_loop()
except KeyboardInterrupt:
print >> sys.stderr, '\nExiting by user request.\n'
print('\nExiting by user request.\n')
sys.exit(0)

View File

@ -9,8 +9,8 @@ bot = telebot.TeleBot(TELEGRAM_TOKEN)
def gen_markup():
markup = InlineKeyboardMarkup()
markup.row_width = 2
markup.add(InlineKeyboardButton("Yes", callback_data=f"cb_yes"),
InlineKeyboardButton("No", callback_data=f"cb_no"))
markup.add(InlineKeyboardButton("Yes", callback_data="cb_yes"),
InlineKeyboardButton("No", callback_data="cb_no"))
return markup
@bot.callback_query_handler(func=lambda call: True)

View File

@ -0,0 +1,53 @@
#!/usr/bin/python
# This example shows how to implement i18n (internationalization) l10n (localization) to create
# multi-language bots with middleware handler.
#
# Note: For the sake of simplicity of this example no extra library is used. However, it is recommended to use
# better i18n systems (gettext and etc) for handling multilingual translations.
# This is not a working, production-ready sample and it is highly recommended not to use it in production.
#
# In this example let's imagine we want to introduce localization or internationalization into our project and
# we need some global function to activate the language once and to use that language in all other message
# handler functions for not repeatedly activating it.
# The middleware (i18n and l10n) is explained:
import telebot
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
TRANSLATIONS = {
'hello': {
'en': 'hello',
'ru': 'привет',
'uz': 'salom'
}
}
_lang = 'en'
def activate(lang):
global _lang
_lang = lang
def _(string):
return TRANSLATIONS[string][_lang]
bot = telebot.TeleBot('TOKEN')
@bot.middleware_handler(update_types=['message'])
def activate_language(bot_instance, message):
activate(message.from_user.language_code)
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, _('hello'))
bot.polling()

View File

@ -0,0 +1,61 @@
#!/usr/bin/python
# This example shows how to implement session creation and retrieval based on user id with middleware handler.
#
# Note: For the sake of simplicity of this example no extra library is used. However, it is recommended to use
# in-memory or on-disk storage implementations (redis, mysql, postgres and etc) for storing and retrieving structures.
# This is not a working, production-ready sample and it is highly recommended not to use it in production.
#
# In this example let's imagine we want to create a session for each user who communicates with the bot to store
# different kind of temporary data while session is active. As an example we want to track the state of the user
# with the help of this session. So, we need a way to store this session data somewhere globally to enable other
# message handler functions to be able to use it.
# The middleware session is explained:
import telebot
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
INFO_STATE = 'ON_INFO_MENU'
MAIN_STATE = 'ON_MAIN_MENU'
SESSIONS = {
-10000: {
'state': INFO_STATE
},
-11111: {
'state': MAIN_STATE
}
}
def get_or_create_session(user_id):
try:
return SESSIONS[user_id]
except KeyError:
SESSIONS[user_id] = {'state': MAIN_STATE}
return SESSIONS[user_id]
bot = telebot.TeleBot('TOKEN')
@bot.middleware_handler(update_types=['message'])
def set_session(bot_instance, message):
bot_instance.session = get_or_create_session(message.from_user.id)
@bot.message_handler(commands=['start'])
def start(message):
bot.session['state'] = MAIN_STATE
bot.send_message(message.chat.id, bot.session['state'])
@bot.message_handler(commands=['info'])
def start(message):
bot.session['state'] = INFO_STATE
bot.send_message(message.chat.id, bot.session['state'])
bot.polling()

View File

@ -1,6 +1,5 @@
import telebot
from telebot.types import LabeledPrice
from telebot.types import ShippingOption
from telebot.types import LabeledPrice, ShippingOption
token = '1234567890:AAAABBBBCCCCDDDDeeeeFFFFgggGHHHH'
provider_token = '1234567890:TEST:AAAABBBBCCCCDDDD' # @BotFather -> Bot Settings -> Payments

View File

@ -0,0 +1,69 @@
# Using Azure Functions for serverless bots.
# (Thanks to twitter.com/masyan for the idea)
# By default the Azure Functions url is https://.../api/HttpTrigger for HttpTrigger type.
# In this example we will use clear webhook url without /api/ -> https://.../HttpTrigger.
# Also we set "authLevel": "anonymous".
# For HttpTrigger type set "route" and "authLevel" in functions.json
# {
# "bindings": [
# ...
# "authLevel": "anonymous"
# "route": "HttpTrigger"
# ]
# }
# To avoid using /api/ in url set "routePrefix":"" in host.json
# {
# ...
# "extensions": {
# "http": {
# "routePrefix": ""
# }
# }
# }
import logging
import azure.functions as func
import telebot
from telebot import apihelper, types
logger = telebot.logger
telebot.logger.setLevel(logging.DEBUG)
# Set bot token
TOKEN = ''
# Uncomment this for using proxy for request
# PROXY = ''
# apihelper.proxy = {'https': PROXY}
# Set WEBHOOK as your Azure Functions url (https://...azurewebsites.net/HttpTrigger)
WEBHOOK = ''
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def start(message):
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
bot.reply_to(message, message.text)
# To avoid "error 429 too many request" set webhook only once. Or use time.sleep(1).
def main(req: func.HttpRequest) -> func.HttpResponse:
bot.set_webhook(url=WEBHOOK)
request_body_dict = req.get_json()
update = telebot.types.Update.de_json(request_body_dict)
bot.process_new_messages([update.message])
return func.HttpResponse(body='', status_code=200)
# Sometimes "requests" version is important.
# azure-functions==1.0.4
# PySocks==1.7.1
# pyTelegramBotAPI==3.6.6
# requests==2.10.0

View File

@ -0,0 +1,13 @@
import telebot
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
bot.reply_to(message, message.text)
bot.polling(skip_pending=True)# Skip pending skips old updates

View File

@ -2,7 +2,6 @@
"""
This Example will show you how to use register_next_step handler.
"""
import time
import telebot
from telebot import types
@ -69,7 +68,7 @@ def process_sex_step(message):
if (sex == u'Male') or (sex == u'Female'):
user.sex = sex
else:
raise Exception()
raise Exception("Unknown sex")
bot.send_message(chat_id, 'Nice to meet you ' + user.name + '\n Age:' + str(user.age) + '\n Sex:' + user.sex)
except Exception as e:
bot.reply_to(message, 'oooops')
@ -84,5 +83,4 @@ bot.enable_save_next_step_handlers(delay=2)
# WARNING It will work only if enable_save_next_step_handlers was called!
bot.load_next_step_handlers()
bot.polling()

View File

@ -3,9 +3,10 @@
# and goes by the name 'TeleBot (@pyTeleBot)'. Join our group to talk to him!
# WARNING: Tested with Python 2.7
import telebot
import os
import telebot
text_messages = {
'welcome':
u'Please welcome {name}!\n\n'
@ -33,8 +34,10 @@ if "TELEBOT_BOT_TOKEN" not in os.environ or "GROUP_CHAT_ID" not in os.environ:
bot = telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"])
GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"])
def is_api_group(chat_id):
return chat_id== GROUP_CHAT_ID
return chat_id == GROUP_CHAT_ID
@bot.message_handler(func=lambda m: True, content_types=['new_chat_participant'])
def on_user_joins(message):
@ -50,6 +53,7 @@ def on_user_joins(message):
bot.reply_to(message, text_messages['welcome'].format(name=name))
@bot.message_handler(commands=['info', 'help'])
def on_info(message):
if not is_api_group(message.chat.id):
@ -58,21 +62,23 @@ def on_info(message):
bot.reply_to(message, text_messages['info'])
@bot.message_handler(commands=["ping"])
def on_ping(message):
bot.reply_to(message, "Still alive and kicking!")
@bot.message_handler(commands=['start'])
def on_start(message):
if not is_api_group(message.chat.id):
bot.reply_to(message, text_messages['wrong_chat'])
return
def listener(messages):
for m in messages:
print str(m)
print(str(m))
bot.set_update_listener(listener)
bot.polling()

View File

@ -1,6 +1,6 @@
# Webhook examples using pyTelegramBotAPI
There are 4 examples in this directory using different libraries:
There are 5 examples in this directory using different libraries:
* **Python (CPython):** *webhook_cpython_echo_bot.py*
* **Pros:**
@ -37,9 +37,18 @@ There are 4 examples in this directory using different libraries:
* **Pros:**
* It's a web application framework
* Python 3 compatible
* Asynchronous, excellent perfomance
* Asynchronous, excellent performance
* Utilizes new async/await syntax
* **Cons:**
* Requires Python 3.4.2+, don't work with Python 2
*Latest update of this document: 2017-01-30*
* **Twisted (20.3.0):** *webhook_twisted_echo_bot.py*
* **Pros:**
* Asynchronous event-driven networking engine
* Very high performance
* Built-in support for many internet protocols
* **Cons:**
* Twisted is low-level, which may be good or bad depending on use case
* Considerable learning curve - reading docs is a must.
*Latest update of this document: 2020-12-17*

View File

@ -11,7 +11,6 @@ from aiohttp import web
import telebot
API_TOKEN = '<api_token>'
WEBHOOK_HOST = '<ip/host where the bot is running>'
@ -32,7 +31,6 @@ WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key
WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN)
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
@ -51,6 +49,7 @@ async def handle(request):
else:
return web.Response(status=403)
app.router.add_post('/{token}/', handle)
@ -72,7 +71,7 @@ def echo_message(message):
bot.remove_webhook()
# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Build ssl context

View File

@ -4,10 +4,11 @@
# This is a simple echo bot using decorators and webhook with CherryPy
# It echoes any incoming text messages and does not use the polling method.
import cherrypy
import telebot
import logging
import cherrypy
import telebot
API_TOKEN = '<api_token>'
@ -29,7 +30,6 @@ WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
@ -70,7 +70,7 @@ def echo_message(message):
bot.remove_webhook()
# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Disable CherryPy requests log
@ -80,9 +80,9 @@ for handler in tuple(access_log.handlers):
# Start cherrypy server
cherrypy.config.update({
'server.socket_host': WEBHOOK_LISTEN,
'server.socket_port': WEBHOOK_PORT,
'server.ssl_module': 'builtin',
'server.socket_host' : WEBHOOK_LISTEN,
'server.socket_port' : WEBHOOK_PORT,
'server.ssl_module' : 'builtin',
'server.ssl_certificate': WEBHOOK_SSL_CERT,
'server.ssl_private_key': WEBHOOK_SSL_PRIV
})

View File

@ -4,11 +4,17 @@
# This is a simple echo bot using decorators and webhook with BaseHTTPServer
# It echoes any incoming text messages and does not use the polling method.
import BaseHTTPServer
import ssl
import telebot
import logging
try:
# Python 2
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
except ImportError:
# Python 3
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import ssl
import telebot
API_TOKEN = '<api_token>'
@ -30,7 +36,6 @@ WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
@ -38,7 +43,7 @@ bot = telebot.TeleBot(API_TOKEN)
# WebhookHandler, process webhook calls
class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class WebhookHandler(BaseHTTPRequestHandler):
server_version = "WebhookHandler/1.0"
def do_HEAD(self):
@ -81,15 +86,17 @@ def echo_message(message):
# Remove webhook, it fails sometimes the set if there is a previous webhook
bot.remove_webhook()
#bot.remove_webhook()
# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Beacuse telegram bot api server will check webhook server is alive.
# Here we need set webhook after server started manually.
#bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
# certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Start server
httpd = BaseHTTPServer.HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT),
WebhookHandler)
httpd = HTTPServer((WEBHOOK_LISTEN, WEBHOOK_PORT),
WebhookHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
certfile=WEBHOOK_SSL_CERT,

View File

@ -4,11 +4,12 @@
# This is a simple echo bot using decorators and webhook with flask
# It echoes any incoming text messages and does not use the polling method.
import flask
import telebot
import logging
import time
import flask
import telebot
API_TOKEN = '<api_token>'
@ -30,7 +31,6 @@ WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
@ -77,7 +77,7 @@ bot.remove_webhook()
time.sleep(0.1)
# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Start flask server

View File

@ -1,8 +1,9 @@
import os
import telebot
from flask import Flask, request
import telebot
TOKEN = '<api_token>'
bot = telebot.TeleBot(TOKEN)
server = Flask(__name__)
@ -20,7 +21,9 @@ def echo_message(message):
@server.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
json_string = request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return "!", 200

View File

@ -4,13 +4,15 @@
# This example shows webhook echo bot with Tornado web framework
# Documenation to Tornado: http://tornadoweb.org
import telebot
import tornado.web
import tornado.ioloop
import tornado.httpserver
import tornado.options
import signal
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import telebot
API_TOKEN = '<api_token>'
WEBHOOK_CERT = "./cert.pem"
WEBHOOK_PKEY = "./pkey.pem"
@ -29,15 +31,18 @@ WEBHOOK_URL_BASE = "https://{0}:{1}/{2}".format(WEBHOOK_HOST, str(WEBHOOK_PORT),
bot = telebot.TeleBot(API_TOKEN)
class Root(tornado.web.RequestHandler):
def get(self):
self.write("Hi! This is webhook example!")
self.finish()
class webhook_serv(tornado.web.RequestHandler):
def get(self):
self.write("What are you doing here?")
self.finish()
def post(self):
if "Content-Length" in self.request.headers and \
"Content-Type" in self.request.headers and \
@ -52,21 +57,26 @@ class webhook_serv(tornado.web.RequestHandler):
else:
self.write("What are you doing here?")
self.finish()
tornado.options.define("port", default=WEBHOOK_PORT, help="run on the given port", type=int)
is_closing = False
def signal_handler(signum, frame):
global is_closing
print("Exiting...")
is_closing = True
def try_exit():
global is_closing
if is_closing:
# clean up here
tornado.ioloop.IOLoop.instance().stop()
print("Exit success!")
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
@ -74,6 +84,7 @@ def send_welcome(message):
("Hi there, I am EchoBot.\n"
"I am here to echo your kind words back to you."))
bot.remove_webhook()
bot.set_webhook(url=WEBHOOK_URL_BASE,
certificate=open(WEBHOOK_CERT, 'r'))
@ -86,9 +97,9 @@ application = tornado.web.Application([
])
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": WEBHOOK_CERT,
"keyfile": WEBHOOK_PKEY,
})
"certfile": WEBHOOK_CERT,
"keyfile" : WEBHOOK_PKEY,
})
http_server.listen(tornado.options.options.port)
tornado.ioloop.PeriodicCallback(try_exit, 100).start()
tornado.ioloop.IOLoop.instance().start()

View File

@ -0,0 +1,79 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This is an example echo bot using webhook with Twisted network framework.
# Updates are received with Twisted web server and processed in reactor thread pool.
# Relevant docs:
# https://twistedmatrix.com/documents/current/core/howto/reactor-basics.html
# https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html
import logging
import telebot
import json
from twisted.internet import ssl, reactor
from twisted.web.resource import Resource, ErrorPage
from twisted.web.server import Site, Request
API_TOKEN = '<api_token>'
WEBHOOK_HOST = '<ip or hostname>'
WEBHOOK_PORT = 8443 # 443, 80, 88 or 8443 (port need to be 'open')
WEBHOOK_LISTEN = '0.0.0.0' # In some VPS you may need to put here the IP addr
WEBHOOK_SSL_CERT = './webhook_cert.pem' # Path to the ssl certificate
WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key
# Quick'n'dirty SSL certificate generation:
#
# openssl genrsa -out webhook_pkey.pem 2048
# openssl req -new -x509 -days 3650 -key webhook_pkey.pem -out webhook_cert.pem
#
# When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply
# with the same value in you put in WEBHOOK_HOST
WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN)
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
bot = telebot.TeleBot(API_TOKEN)
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message,
("Hi there, I am EchoBot.\n"
"I am here to echo your kind words back to you."))
# Handle all other messages
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
bot.reply_to(message, message.text)
# Remove webhook, it fails sometimes the set if there is a previous webhook
bot.remove_webhook()
# Set webhook
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
certificate=open(WEBHOOK_SSL_CERT, 'r'))
# Process webhook calls
class WebhookHandler(Resource):
isLeaf = True
def render_POST(self, request: Request):
request_body_dict = json.load(request.content)
update = telebot.types.Update.de_json(request_body_dict)
reactor.callInThread(lambda: bot.process_new_updates([update]))
return b''
root = ErrorPage(403, 'Forbidden', '')
root.putChild(API_TOKEN.encode(), WebhookHandler())
site = Site(root)
sslcontext = ssl.DefaultOpenSSLContextFactory(WEBHOOK_SSL_PRIV, WEBHOOK_SSL_CERT)
reactor.listenSSL(8443, site, sslcontext)
reactor.run()

View File

@ -1,5 +1,3 @@
py==1.4.29
pytest==3.0.2
requests==2.7.0
six==1.9.0
requests==2.20.0
wheel==0.24.0

View File

@ -1,13 +1,18 @@
#!/usr/bin/env python
from setuptools import setup
from io import open
import re
def read(filename):
with open(filename, encoding='utf-8') as file:
return file.read()
with open('telebot/version.py', 'r', encoding='utf-8') as f: # Credits: LonamiWebs
version = re.search(r"^__version__\s*=\s*'(.*)'.*$",
f.read(), flags=re.MULTILINE).group(1)
setup(name='pyTelegramBotAPI',
version='3.6.6',
version=version,
description='Python Telegram bot api. ',
long_description=read('README.md'),
long_description_content_type="text/markdown",
@ -17,15 +22,14 @@ setup(name='pyTelegramBotAPI',
packages=['telebot'],
license='GPL2',
keywords='telegram bot api tools',
install_requires=['requests', 'six'],
install_requires=['requests'],
extras_require={
'json': 'ujson',
'PIL': 'Pillow',
'redis': 'redis>=3.4.1'
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Environment :: Console',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

143
telebot/handler_backends.py Normal file
View File

@ -0,0 +1,143 @@
import os
import pickle
import threading
from telebot import apihelper
class HandlerBackend(object):
"""
Class for saving (next step|reply) handlers
"""
def __init__(self, handlers=None):
if handlers is None:
handlers = {}
self.handlers = handlers
def register_handler(self, handler_group_id, handler):
raise NotImplementedError()
def clear_handlers(self, handler_group_id):
raise NotImplementedError()
def get_handlers(self, handler_group_id):
raise NotImplementedError()
class MemoryHandlerBackend(HandlerBackend):
def register_handler(self, handler_group_id, handler):
if handler_group_id in self.handlers:
self.handlers[handler_group_id].append(handler)
else:
self.handlers[handler_group_id] = [handler]
def clear_handlers(self, handler_group_id):
self.handlers.pop(handler_group_id, None)
def get_handlers(self, handler_group_id):
return self.handlers.pop(handler_group_id, None)
def load_handlers(self, filename, del_file_after_loading):
raise NotImplementedError()
class FileHandlerBackend(HandlerBackend):
def __init__(self, handlers=None, filename='./.handler-saves/handlers.save', delay=120):
super(FileHandlerBackend, self).__init__(handlers)
self.filename = filename
self.delay = delay
self.timer = threading.Timer(delay, self.save_handlers)
def register_handler(self, handler_group_id, handler):
if handler_group_id in self.handlers:
self.handlers[handler_group_id].append(handler)
else:
self.handlers[handler_group_id] = [handler]
self.start_save_timer()
def clear_handlers(self, handler_group_id):
self.handlers.pop(handler_group_id, None)
self.start_save_timer()
def get_handlers(self, handler_group_id):
handlers = self.handlers.pop(handler_group_id, None)
self.start_save_timer()
return handlers
def start_save_timer(self):
if not self.timer.is_alive():
if self.delay <= 0:
self.save_handlers()
else:
self.timer = threading.Timer(self.delay, self.save_handlers)
self.timer.start()
def save_handlers(self):
self.dump_handlers(self.handlers, self.filename)
def load_handlers(self, filename=None, del_file_after_loading=True):
if not filename:
filename = self.filename
tmp = self.return_load_handlers(filename, del_file_after_loading=del_file_after_loading)
if tmp is not None:
self.handlers.update(tmp)
@staticmethod
def dump_handlers(handlers, filename, file_mode="wb"):
dirs = filename.rsplit('/', maxsplit=1)[0]
os.makedirs(dirs, exist_ok=True)
with open(filename + ".tmp", file_mode) as file:
if (apihelper.CUSTOM_SERIALIZER is None):
pickle.dump(handlers, file)
else:
apihelper.CUSTOM_SERIALIZER.dump(handlers, file)
if os.path.isfile(filename):
os.remove(filename)
os.rename(filename + ".tmp", filename)
@staticmethod
def return_load_handlers(filename, del_file_after_loading=True):
if os.path.isfile(filename) and os.path.getsize(filename) > 0:
with open(filename, "rb") as file:
if (apihelper.CUSTOM_SERIALIZER is None):
handlers = pickle.load(file)
else:
handlers = apihelper.CUSTOM_SERIALIZER.load(file)
if del_file_after_loading:
os.remove(filename)
return handlers
class RedisHandlerBackend(HandlerBackend):
def __init__(self, handlers=None, host='localhost', port=6379, db=0, prefix='telebot', password=None):
super(RedisHandlerBackend, self).__init__(handlers)
from redis import Redis
self.prefix = prefix
self.redis = Redis(host, port, db, password)
def _key(self, handle_group_id):
return ':'.join((self.prefix, str(handle_group_id)))
def register_handler(self, handler_group_id, handler):
handlers = []
value = self.redis.get(self._key(handler_group_id))
if value:
handlers = pickle.loads(value)
handlers.append(handler)
self.redis.set(self._key(handler_group_id), pickle.dumps(handlers))
def clear_handlers(self, handler_group_id):
self.redis.delete(self._key(handler_group_id))
def get_handlers(self, handler_group_id):
handlers = None
value = self.redis.get(self._key(handler_group_id))
if value:
handlers = pickle.loads(value)
self.clear_handlers(handler_group_id)
return handlers

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +1,110 @@
# -*- coding: utf-8 -*-
import random
import re
import string
import threading
import traceback
import re
import sys
import six
from six import string_types
from typing import Any, Callable, List, Dict, Optional, Union
# Python3 queue support.
# noinspection PyPep8Naming
import queue as Queue
import logging
from telebot import types
try:
import Queue
except ImportError:
import queue as Queue
import logging
# noinspection PyPackageRequirements
from PIL import Image
from io import BytesIO
pil_imported = True
except:
pil_imported = False
MAX_MESSAGE_LENGTH = 4096
logger = logging.getLogger('TeleBot')
thread_local = threading.local()
content_type_media = [
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'video_note', 'voice', 'contact', 'dice', 'poll',
'venue', 'location'
]
content_type_service = [
'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created',
'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message',
'proximity_alert_triggered', 'voice_chat_scheduled', 'voice_chat_started', 'voice_chat_ended',
'voice_chat_participants_invited', 'message_auto_delete_timer_changed'
]
update_types = [
"update_id", "message", "edited_message", "channel_post", "edited_channel_post", "inline_query",
"chosen_inline_result", "callback_query", "shipping_query", "pre_checkout_query", "poll", "poll_answer",
"my_chat_member", "chat_member"
]
class WorkerThread(threading.Thread):
count = 0
count = 0
def __init__(self, exception_callback=None, queue=None, name=None):
if not name:
name = "WorkerThread{0}".format(self.__class__.count + 1)
self.__class__.count += 1
if not queue:
queue = Queue.Queue()
def __init__(self, exception_callback=None, queue=None, name=None):
if not name:
name = "WorkerThread{0}".format(self.__class__.count + 1)
self.__class__.count += 1
if not queue:
queue = Queue.Queue()
threading.Thread.__init__(self, name=name)
self.queue = queue
self.daemon = True
threading.Thread.__init__(self, name=name)
self.queue = queue
self.daemon = True
self.received_task_event = threading.Event()
self.done_event = threading.Event()
self.exception_event = threading.Event()
self.continue_event = threading.Event()
self.received_task_event = threading.Event()
self.done_event = threading.Event()
self.exception_event = threading.Event()
self.continue_event = threading.Event()
self.exception_callback = exception_callback
self.exc_info = None
self._running = True
self.start()
self.exception_callback = exception_callback
self.exception_info = None
self._running = True
self.start()
def run(self):
while self._running:
try:
task, args, kwargs = self.queue.get(block=True, timeout=.5)
self.continue_event.clear()
self.received_task_event.clear()
self.done_event.clear()
self.exception_event.clear()
logger.debug("Received task")
self.received_task_event.set()
def run(self):
while self._running:
try:
task, args, kwargs = self.queue.get(block=True, timeout=.5)
self.continue_event.clear()
self.received_task_event.clear()
self.done_event.clear()
self.exception_event.clear()
logger.debug("Received task")
self.received_task_event.set()
task(*args, **kwargs)
logger.debug("Task complete")
self.done_event.set()
except Queue.Empty:
pass
except Exception as e:
logger.error(type(e).__name__ + " occurred, args=" + str(e.args) + "\n" + traceback.format_exc())
self.exc_info = sys.exc_info()
self.exception_event.set()
task(*args, **kwargs)
logger.debug("Task complete")
self.done_event.set()
except Queue.Empty:
pass
except Exception as e:
logger.debug(type(e).__name__ + " occurred, args=" + str(e.args) + "\n" + traceback.format_exc())
self.exception_info = e
self.exception_event.set()
if self.exception_callback:
self.exception_callback(self, self.exception_info)
self.continue_event.wait()
if self.exception_callback:
self.exception_callback(self, self.exc_info)
self.continue_event.wait()
def put(self, task, *args, **kwargs):
self.queue.put((task, args, kwargs))
def put(self, task, *args, **kwargs):
self.queue.put((task, args, kwargs))
def raise_exceptions(self):
if self.exception_event.is_set():
raise self.exception_info
def raise_exceptions(self):
if self.exception_event.is_set():
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
def clear_exceptions(self):
self.exception_event.clear()
self.continue_event.set()
def clear_exceptions(self):
self.exception_event.clear()
self.continue_event.set()
def stop(self):
self._running = False
def stop(self):
self._running = False
class ThreadPool:
@ -93,19 +115,19 @@ class ThreadPool:
self.num_threads = num_threads
self.exception_event = threading.Event()
self.exc_info = None
self.exception_info = None
def put(self, func, *args, **kwargs):
self.tasks.put((func, args, kwargs))
def on_exception(self, worker_thread, exc_info):
self.exc_info = exc_info
self.exception_info = exc_info
self.exception_event.set()
worker_thread.continue_event.set()
def raise_exceptions(self):
if self.exception_event.is_set():
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
raise self.exception_info
def clear_exceptions(self):
self.exception_event.clear()
@ -130,15 +152,15 @@ class AsyncTask:
def _run(self):
try:
self.result = self.target(*self.args, **self.kwargs)
except:
self.result = sys.exc_info()
except Exception as e:
self.result = e
self.done = True
def wait(self):
if not self.done:
self.thread.join()
if isinstance(self.result, BaseException):
six.reraise(self.result[0], self.result[1], self.result[2])
raise self.result
else:
return self.result
@ -154,18 +176,43 @@ def async_dec():
def is_string(var):
return isinstance(var, string_types)
return isinstance(var, str)
def is_command(text):
def is_dict(var):
return isinstance(var, dict)
def is_bytes(var):
return isinstance(var, bytes)
def is_pil_image(var):
return pil_imported and isinstance(var, Image.Image)
def pil_image_to_file(image, extension='JPEG', quality='web_low'):
if pil_imported:
photoBuffer = BytesIO()
image.convert('RGB').save(photoBuffer, extension, quality=quality)
photoBuffer.seek(0)
return photoBuffer
else:
raise RuntimeError('PIL module is not imported')
def is_command(text: str) -> bool:
"""
Checks if `text` is a command. Telegram chat commands start with the '/' character.
:param text: Text to check.
:return: True if `text` is a command, else False.
"""
if text is None: return False
return text.startswith('/')
def extract_command(text):
def extract_command(text: str) -> Union[str, None]:
"""
Extracts the command from `text` (minus the '/') if `text` is a command (see is_command).
If `text` is not a command, this function returns None.
@ -179,10 +226,28 @@ def extract_command(text):
:param text: String to extract the command from
:return: the command if `text` is a command (according to is_command), else None.
"""
if text is None: return None
return text.split()[0].split('@')[0][1:] if is_command(text) else None
def split_string(text, chars_per_string):
def extract_arguments(text: str) -> str:
"""
Returns the argument after the command.
Examples:
extract_arguments("/get name"): 'name'
extract_arguments("/get"): ''
extract_arguments("/get@botName name"): 'name'
:param text: String to extract the arguments from a command
:return: the arguments if `text` is a command (according to is_command), else None.
"""
regexp = re.compile(r"/\w*(@\w*)*\s*([\s\S]*)", re.IGNORECASE)
result = regexp.match(text)
return result.group(2) if is_command(text) else None
def split_string(text: str, chars_per_string: int) -> List[str]:
"""
Splits one string into multiple strings, with a maximum amount of `chars_per_string` characters per string.
This is very useful for splitting one giant message into multiples.
@ -193,6 +258,107 @@ def split_string(text, chars_per_string):
"""
return [text[i:i + chars_per_string] for i in range(0, len(text), chars_per_string)]
def smart_split(text: str, chars_per_string: int=MAX_MESSAGE_LENGTH) -> List[str]:
"""
Splits one string into multiple strings, with a maximum amount of `chars_per_string` characters per string.
This is very useful for splitting one giant message into multiples.
If `chars_per_string` > 4096: `chars_per_string` = 4096.
Splits by '\n', '. ' or ' ' in exactly this priority.
:param text: The text to split
:param chars_per_string: The number of maximum characters per part the text is split to.
:return: The splitted text as a list of strings.
"""
def _text_before_last(substr: str) -> str:
return substr.join(part.split(substr)[:-1]) + substr
if chars_per_string > MAX_MESSAGE_LENGTH: chars_per_string = MAX_MESSAGE_LENGTH
parts = []
while True:
if len(text) < chars_per_string:
parts.append(text)
return parts
part = text[:chars_per_string]
if "\n" in part: part = _text_before_last("\n")
elif ". " in part: part = _text_before_last(". ")
elif " " in part: part = _text_before_last(" ")
parts.append(part)
text = text[len(part):]
def escape(text: str) -> str:
"""
Replaces the following chars in `text` ('&' with '&amp;', '<' with '&lt;' and '>' with '&gt;').
:param text: the text to escape
:return: the escaped text
"""
chars = {"&": "&amp;", "<": "&lt;", ">": "&gt"}
for old, new in chars.items(): text = text.replace(old, new)
return text
def user_link(user: types.User, include_id: bool=False) -> str:
"""
Returns an HTML user link. This is useful for reports.
Attention: Don't forget to set parse_mode to 'HTML'!
Example:
bot.send_message(your_user_id, user_link(message.from_user) + ' started the bot!', parse_mode='HTML')
:param user: the user (not the user_id)
:param include_id: include the user_id
:return: HTML user link
"""
name = escape(user.first_name)
return (f"<a href='tg://user?id={user.id}'>{name}</a>"
+ (f" (<pre>{user.id}</pre>)" if include_id else ""))
def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.InlineKeyboardMarkup:
"""
Returns a reply markup from a dict in this format: {'text': kwargs}
This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)'
Example:
quick_markup({
'Twitter': {'url': 'https://twitter.com'},
'Facebook': {'url': 'https://facebook.com'},
'Back': {'callback_data': 'whatever'}
}, row_width=2):
returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
and a back button below
kwargs can be:
{
'url': None,
'callback_data': None,
'switch_inline_query': None,
'switch_inline_query_current_chat': None,
'callback_game': None,
'pay': None,
'login_url': None
}
:param values: a dict containing all buttons to create in this format: {text: kwargs} {str:}
:param row_width: int row width
:return: InlineKeyboardMarkup
"""
markup = types.InlineKeyboardMarkup(row_width=row_width)
buttons = [
types.InlineKeyboardButton(text=text, **kwargs)
for text, kwargs in values.items()
]
markup.add(*buttons)
return markup
# CREDITS TO http://stackoverflow.com/questions/12317940#answer-12320352
def or_set(self):
self._set()
@ -205,16 +371,20 @@ def or_clear(self):
def orify(e, changed_callback):
e._set = e.set
e._clear = e.clear
if not hasattr(e, "_set"):
e._set = e.set
if not hasattr(e, "_clear"):
e._clear = e.clear
e.changed = changed_callback
e.set = lambda: or_set(e)
e.clear = lambda: or_clear(e)
def OrEvent(*events):
or_event = threading.Event()
def changed():
bools = [e.is_set() for e in events]
bools = [ev.is_set() for ev in events]
if any(bools):
or_event.set()
else:
@ -231,22 +401,6 @@ def OrEvent(*events):
changed()
return or_event
def extract_arguments(text):
"""
Returns the argument after the command.
Examples:
extract_arguments("/get name"): 'name'
extract_arguments("/get"): ''
extract_arguments("/get@botName name"): 'name'
:param text: String to extract the arguments from a command
:return: the arguments if `text` is a command (according to is_command), else None.
"""
regexp = re.compile("\/\w*(@\w*)*\s*([\s\S]*)",re.IGNORECASE)
result = regexp.match(text)
return result.group(2) if is_command(text) else None
def per_thread(key, construct_value, reset=False):
if reset or not hasattr(thread_local, key):
@ -256,5 +410,33 @@ def per_thread(key, construct_value, reset=False):
return getattr(thread_local, key)
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
# https://stackoverflow.com/a/312464/9935473
for i in range(0, len(lst), n):
yield lst[i:i + n]
def generate_random_token():
return ''.join(random.sample(string.ascii_letters, 16))
return ''.join(random.sample(string.ascii_letters, 16))
def deprecated(warn: bool=False, alternative: Optional[Callable]=None):
"""
Use this decorator to mark functions as deprecated.
When the function is used, an info (or warning if `warn` is True) is logged.
:param warn: If True a warning is logged else an info
:param alternative: The new function to use instead
"""
def decorator(function):
def wrapper(*args, **kwargs):
if not warn:
logger.info(f"`{function.__name__}` is deprecated."
+ (f" Use `{alternative.__name__}` instead" if alternative else ""))
else:
logger.warn(f"`{function.__name__}` is deprecated."
+ (f" Use `{alternative.__name__}` instead" if alternative else ""))
return function(*args, **kwargs)
return wrapper
return decorator

3
telebot/version.py Normal file
View File

@ -0,0 +1,3 @@
# Versions should comply with PEP440.
# This line is parsed in setup.py:
__version__ = '3.8.3'

View File

@ -0,0 +1,275 @@
import sys
sys.path.append('../')
REDIS_TESTS = False
import os
import time
import pytest
import telebot
from telebot import types
from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend
if REDIS_TESTS:
from telebot.handler_backends import RedisHandlerBackend
@pytest.fixture()
def telegram_bot():
return telebot.TeleBot('', threaded=False)
@pytest.fixture
def private_chat():
return types.Chat(id=11, type='private')
@pytest.fixture
def user():
return types.User(id=10, is_bot=False, first_name='Some User')
@pytest.fixture()
def message(user, private_chat):
params = {'text': '/start'}
return types.Message(
message_id=1, from_user=user, date=None, chat=private_chat, content_type='text', options=params, json_string=""
)
@pytest.fixture()
def reply_to_message(user, private_chat, message):
params = {'text': '/start'}
reply_message = types.Message(
message_id=2, from_user=user, date=None, chat=private_chat, content_type='text', options=params, json_string=""
)
reply_message.reply_to_message = message
return reply_message
@pytest.fixture()
def update_type(message):
edited_message = None
channel_post = None
edited_channel_post = None
inline_query = None
chosen_inline_result = None
callback_query = None
shipping_query = None
pre_checkout_query = None
poll = None
poll_answer = None
my_chat_member = None
chat_member = None
return types.Update(1001234038283, message, edited_message, channel_post, edited_channel_post, inline_query,
chosen_inline_result, callback_query, shipping_query, pre_checkout_query, poll, poll_answer,
my_chat_member, chat_member)
@pytest.fixture()
def reply_to_message_update_type(reply_to_message):
edited_message = None
channel_post = None
edited_channel_post = None
inline_query = None
chosen_inline_result = None
callback_query = None
shipping_query = None
pre_checkout_query = None
poll = None
poll_answer = None
my_chat_member = None
chat_member = None
return types.Update(1001234038284, reply_to_message, edited_message, channel_post, edited_channel_post,
inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query,
poll, poll_answer, my_chat_member, chat_member)
def next_handler(message):
message.text = 'entered next_handler'
def test_memory_handler_backend_default_backend(telegram_bot):
assert telegram_bot.reply_backend.__class__ == MemoryHandlerBackend
assert telegram_bot.next_step_backend.__class__ == MemoryHandlerBackend
def test_memory_handler_backend_register_next_step_handler(telegram_bot, private_chat, update_type):
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
assert len(telegram_bot.next_step_backend.handlers[private_chat.id]) == 1
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered next_handler'
assert private_chat.id not in telegram_bot.next_step_backend.handlers
def test_memory_handler_backend_clear_next_step_handler(telegram_bot, private_chat, update_type):
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
assert len(telegram_bot.next_step_backend.handlers[private_chat.id]) == 1
telegram_bot.clear_step_handler_by_chat_id(private_chat.id)
assert private_chat.id not in telegram_bot.next_step_backend.handlers
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
def test_memory_handler_backend_register_reply_handler(telegram_bot, private_chat, update_type,
reply_to_message_update_type):
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_for_reply_by_message_id(message.message_id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
assert len(telegram_bot.reply_backend.handlers[update_type.message.message_id]) == 1
telegram_bot.process_new_updates([reply_to_message_update_type])
assert reply_to_message_update_type.message.text == 'entered next_handler'
assert private_chat.id not in telegram_bot.reply_backend.handlers
def test_memory_handler_backend_clear_reply_handler(telegram_bot, private_chat, update_type,
reply_to_message_update_type):
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_for_reply_by_message_id(message.message_id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
assert len(telegram_bot.reply_backend.handlers[update_type.message.message_id]) == 1
telegram_bot.clear_reply_handlers_by_message_id(update_type.message.message_id)
assert update_type.message.message_id not in telegram_bot.reply_backend.handlers
telegram_bot.process_new_updates([reply_to_message_update_type])
assert reply_to_message_update_type.message.text == 'entered start'
def test_file_handler_backend_register_next_step_handler(telegram_bot, private_chat, update_type):
telegram_bot.next_step_backend=FileHandlerBackend(filename='./.handler-saves/step1.save', delay=0.1)
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
time.sleep(0.2)
assert os.path.exists(telegram_bot.next_step_backend.filename)
assert len(telegram_bot.next_step_backend.handlers[private_chat.id]) == 1
telegram_bot.next_step_backend.handlers = {}
telegram_bot.next_step_backend.load_handlers()
assert len(telegram_bot.next_step_backend.handlers[private_chat.id]) == 1
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered next_handler'
assert private_chat.id not in telegram_bot.next_step_backend.handlers
time.sleep(0.2)
if os.path.exists(telegram_bot.next_step_backend.filename):
os.remove(telegram_bot.next_step_backend.filename)
def test_file_handler_backend_clear_next_step_handler(telegram_bot, private_chat, update_type):
telegram_bot.next_step_backend=FileHandlerBackend(filename='./.handler-saves/step2.save', delay=0.1)
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
assert len(telegram_bot.next_step_backend.handlers[private_chat.id]) == 1
time.sleep(0.2)
assert os.path.exists(telegram_bot.next_step_backend.filename)
telegram_bot.clear_step_handler_by_chat_id(private_chat.id)
time.sleep(0.2)
telegram_bot.next_step_backend.load_handlers()
assert private_chat.id not in telegram_bot.next_step_backend.handlers
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
time.sleep(0.2)
if os.path.exists(telegram_bot.next_step_backend.filename):
os.remove(telegram_bot.next_step_backend.filename)
def test_redis_handler_backend_register_next_step_handler(telegram_bot, private_chat, update_type):
if not REDIS_TESTS:
pytest.skip('please install redis and configure redis server, then enable REDIS_TESTS')
telegram_bot.next_step_backend = RedisHandlerBackend(prefix='pyTelegramBotApi:step_backend1')
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered next_handler'
def test_redis_handler_backend_clear_next_step_handler(telegram_bot, private_chat, update_type):
if not REDIS_TESTS:
pytest.skip('please install redis and configure redis server, then enable REDIS_TESTS')
telegram_bot.next_step_backend = RedisHandlerBackend(prefix='pyTelegramBotApi:step_backend2')
@telegram_bot.message_handler(commands=['start'])
def start(message):
message.text = 'entered start'
telegram_bot.register_next_step_handler_by_chat_id(message.chat.id, next_handler)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'
telegram_bot.clear_step_handler_by_chat_id(private_chat.id)
telegram_bot.process_new_updates([update_type])
assert update_type.message.text == 'entered start'

View File

@ -6,6 +6,7 @@ sys.path.append('../')
import time
import pytest
import os
from datetime import datetime, timedelta
import telebot
from telebot import types
@ -18,6 +19,14 @@ if not should_skip:
CHAT_ID = os.environ['CHAT_ID']
GROUP_ID = os.environ['GROUP_ID']
def _new_test():
pass
@util.deprecated(alternative=_new_test)
def _test():
pass
@pytest.mark.skipif(should_skip, reason="No environment variables configured")
class TestTeleBot:
@ -48,7 +57,8 @@ class TestTeleBot:
bot = telebot.TeleBot('')
msg = self.create_text_message(r'https://web.telegram.org/')
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
# noinspection PyUnusedLocal
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
def command_url(message):
msg.text = 'got'
@ -60,6 +70,7 @@ class TestTeleBot:
bot = telebot.TeleBot('')
msg = self.create_text_message(r'lambda_text')
# noinspection PyUnusedLocal
@bot.message_handler(func=lambda message: r'lambda' in message.text)
def command_url(message):
msg.text = 'got'
@ -72,6 +83,7 @@ class TestTeleBot:
bot = telebot.TeleBot('')
msg = self.create_text_message(r'text')
# noinspection PyUnusedLocal
@bot.message_handler(func=lambda message: r'lambda' in message.text)
def command_url(message):
msg.text = 'got'
@ -84,7 +96,8 @@ class TestTeleBot:
bot = telebot.TeleBot('')
msg = self.create_text_message(r'web.telegram.org/')
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
# noinspection PyUnusedLocal
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
def command_url(message):
msg.text = 'got'
@ -121,6 +134,16 @@ class TestTeleBot:
ret_msg = tb.send_document(CHAT_ID, ret_msg.document.file_id)
assert ret_msg.message_id
def test_send_file_with_filename(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data)
assert ret_msg.message_id
ret_msg = tb.send_document(CHAT_ID, file_data, visible_file_name="test.jpg")
assert ret_msg.message_id
def test_send_file_dis_noti(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = telebot.TeleBot(TOKEN)
@ -241,6 +264,12 @@ class TestTeleBot:
ret_msg = tb.send_message(CHAT_ID, text)
assert ret_msg.message_id
def test_send_dice(self):
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_dice(CHAT_ID, emoji='🎯')
assert ret_msg.message_id
assert ret_msg.content_type == 'dice'
def test_send_message_dis_noti(self):
text = 'CI Test Message'
tb = telebot.TeleBot(TOKEN)
@ -283,6 +312,13 @@ class TestTeleBot:
ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id)
assert ret_msg.forward_from
def test_copy_message(self):
text = 'CI copy_message Test Message'
tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, text)
ret_msg = tb.copy_message(CHAT_ID, CHAT_ID, msg.message_id)
assert ret_msg
def test_forward_message_dis_noti(self):
text = 'CI forward_message Test Message'
tb = telebot.TeleBot(TOKEN)
@ -390,6 +426,23 @@ class TestTeleBot:
cn = tb.get_chat_members_count(GROUP_ID)
assert cn > 1
def test_export_chat_invite_link(self):
tb = telebot.TeleBot(TOKEN)
il = tb.export_chat_invite_link(GROUP_ID)
assert isinstance(il, str)
def test_create_revoke_detailed_chat_invite_link(self):
tb = telebot.TeleBot(TOKEN)
cil = tb.create_chat_invite_link(GROUP_ID,
(datetime.now() + timedelta(minutes=1)).timestamp(), member_limit=5)
assert isinstance(cil.invite_link, str)
assert cil.creator.id == tb.get_me().id
assert isinstance(cil.expire_date, (float, int))
assert cil.member_limit == 5
assert not cil.is_revoked
rcil = tb.revoke_chat_invite_link(GROUP_ID, cil.invite_link)
assert rcil.is_revoked
def test_edit_markup(self):
text = 'CI Test Message'
tb = telebot.TeleBot(TOKEN)
@ -402,11 +455,33 @@ class TestTeleBot:
new_msg = tb.edit_message_reply_markup(chat_id=CHAT_ID, message_id=ret_msg.message_id, reply_markup=markup)
assert new_msg.message_id
def create_text_message(self, text):
@staticmethod
def create_text_message(text):
params = {'text': text}
chat = types.User(11, False, 'test')
return types.Message(1, None, None, chat, 'text', params, "")
@staticmethod
def create_message_update(text):
params = {'text': text}
chat = types.User(11, False, 'test')
message = types.Message(1, None, None, chat, 'text', params, "")
edited_message = None
channel_post = None
edited_channel_post = None
inline_query = None
chosen_inline_result = None
callback_query = None
shipping_query = None
pre_checkout_query = None
poll = None
poll_answer = None
my_chat_member = None
chat_member = None
return types.Update(-1001234038283, message, edited_message, channel_post, edited_channel_post, inline_query,
chosen_inline_result, callback_query, shipping_query, pre_checkout_query, poll, poll_answer,
my_chat_member, chat_member)
def test_is_string_unicode(self):
s1 = u'string'
assert util.is_string(s1)
@ -488,3 +563,72 @@ class TestTeleBot:
tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown')
assert ret_msg.caption_entities[0].type == 'italic'
def test_chat_commands(self):
tb = telebot.TeleBot(TOKEN)
command, description, lang = 'command_1', 'description of command 1', 'en'
scope = telebot.types.BotCommandScopeChat(CHAT_ID)
ret_msg = tb.set_my_commands([telebot.types.BotCommand(command, description)], scope, lang)
assert ret_msg is True
ret_msg = tb.get_my_commands(scope, lang)
assert ret_msg[0].command == command
assert ret_msg[0].description == description
ret_msg = tb.delete_my_commands(scope, lang)
assert ret_msg is True
ret_msg = tb.get_my_commands(scope, lang)
assert ret_msg == []
def test_typed_middleware_handler(self):
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
tb = telebot.TeleBot('')
update = self.create_message_update('/help')
# noinspection PyUnusedLocal
@tb.middleware_handler(update_types=['message'])
def middleware(tb_instance, message):
message.text = 'got'
@tb.message_handler(func=lambda m: m.text == 'got')
def command_handler(message):
message.text = message.text + message.text
tb.process_new_updates([update])
time.sleep(1)
assert update.message.text == 'got' * 2
def test_default_middleware_handler(self):
from telebot import apihelper
apihelper.ENABLE_MIDDLEWARE = True
tb = telebot.TeleBot('')
update = self.create_message_update('/help')
# noinspection PyUnusedLocal
@tb.middleware_handler()
def middleware(tb_instance, mw_update):
mw_update.message.text = 'got'
@tb.message_handler(func=lambda m: m.text == 'got')
def command_handler(message):
message.text = message.text + message.text
tb.process_new_updates([update])
time.sleep(1)
assert update.message.text == 'got' * 2
def test_deprecated_dec(self):
_test()
def test_chat_permissions(self):
return # CHAT_ID is private chat, no permissions can be set
#tb = telebot.TeleBot(TOKEN)
#permissions = types.ChatPermissions(can_send_messages=True, can_send_polls=False)
#msg = tb.set_chat_permissions(CHAT_ID, permissions)

View File

@ -6,9 +6,10 @@ from telebot import types
def test_json_user():
jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","username":"rdss_bot","is_bot":true}'
jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","last_name":")))","username":"rdss_bot","is_bot":true}'
u = types.User.de_json(jsonstring)
assert u.id == 101176298
assert u.full_name == 'RDSSBOT )))'
def test_json_message():
@ -17,6 +18,37 @@ def test_json_message():
assert msg.text == 'HIHI'
def test_json_message_with_reply_markup():
jsonstring = r'{"message_id":48,"from":{"id":153587469,"is_bot":false,"first_name":"Neko","username":"Neko"},"chat":{"id":153587469,"first_name":"Neko","username":"Neko","type":"private"},"date":1598879570,"text":"test","reply_markup":{"inline_keyboard":[[{"text":"Google","url":"http://www.google.com"},{"text":"Yahoo","url":"http://www.yahoo.com"}]]}}'
msg = types.Message.de_json(jsonstring)
assert msg.content_type == 'text'
assert msg.reply_markup.keyboard[0][0].text == 'Google'
def test_json_InlineKeyboardMarkup():
jsonstring = r'{"inline_keyboard":[[{"text":"Google","url":"http://www.google.com"},{"text":"Yahoo","url":"http://www.yahoo.com"}]]}'
markup = types.InlineKeyboardMarkup.de_json(jsonstring)
assert markup.keyboard[0][0].text == 'Google'
assert markup.keyboard[0][1].url == 'http://www.yahoo.com'
def test_json_InlineKeyboardButton():
jsonstring = r'{"text":"Google","url":"http://www.google.com"}'
button = types.InlineKeyboardButton.de_json(jsonstring)
assert button.text == 'Google'
assert button.url == 'http://www.google.com'
def test_json_message_with_dice():
jsonstring = r'{"message_id":5560,"from":{"id":879343317,"is_bot":false,"first_name":"George","last_name":"Forse","username":"dr_fxrse","language_code":"ru"},"chat":{"id":879343317,"first_name":"George","last_name":"Forse","username":"dr_fxrse","type":"private"},"date":1586926330,"dice":{"value": 4, "emoji": "\ud83c\udfaf"}}'
msg = types.Message.de_json(jsonstring)
assert msg.content_type == 'dice'
assert isinstance(msg.dice, types.Dice)
assert msg.dice.value == 4
assert msg.dice.emoji == '🎯'
def test_json_message_group():
json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI"}'
msg = types.Message.de_json(json_string)
@ -32,14 +64,14 @@ def test_json_GroupChat():
def test_json_Document():
json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_size":446}'
json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}'
doc = types.Document.de_json(json_string)
assert doc.thumb is None
assert doc.file_name == 'Text File'
def test_json_Message_Audio():
json_string = r'{"message_id":131,"from":{"id":12775,"first_name":"dd","username":"dd","is_bot":true },"chat":{"id":10834,"first_name":"dd","type":"private","type":"private","last_name":"dd","username":"dd"},"date":1439978364,"audio":{"duration":1,"mime_type":"audio\/mpeg","title":"pyTelegram","performer":"eternnoir","file_id":"BQADBQADDH1JaB8-1KyWUss2-Ag","file_size":20096}}'
json_string = r'{"message_id":131,"from":{"id":12775,"first_name":"dd","username":"dd","is_bot":true },"chat":{"id":10834,"first_name":"dd","type":"private","type":"private","last_name":"dd","username":"dd"},"date":1439978364,"audio":{"duration":1,"mime_type":"audio\/mpeg","title":"pyTelegram","performer":"eternnoir","file_id":"BQADBQADDH1JaB8-1KyWUss2-Ag","file_unique_id": "AgADawEAAn8VSFY","file_size":20096}}'
msg = types.Message.de_json(json_string)
assert msg.audio.duration == 1
assert msg.content_type == 'audio'
@ -48,7 +80,7 @@ def test_json_Message_Audio():
def test_json_Message_Sticker():
json_string = r'{"message_id":98,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10734,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435479551,"sticker":{"width":550,"height":368,"thumb":{"file_id":"AAQFABPJLB0sAAQq17w-li3bzoIfAAIC","file_size":1822,"width":90,"height":60},"file_id":"BQADBQADNAIAAsYifgYdGJOa6bGAsQI","file_size":30320}}'
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "thumb": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
msg = types.Message.de_json(json_string)
assert msg.sticker.height == 368
assert msg.sticker.thumb.height == 60
@ -56,29 +88,29 @@ def test_json_Message_Sticker():
def test_json_Message_Sticker_without_thumb():
json_string = r'{"message_id":98,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10734,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435479551,"sticker":{"width":550,"height":368,"file_id":"BQADBQADNAIAAsYifgYdGJOa6bGAsQI","file_size":30320}}'
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
msg = types.Message.de_json(json_string)
assert msg.sticker.height == 368
assert msg.sticker.thumb == None
assert msg.sticker.thumb is None
assert msg.content_type == 'sticker'
def test_json_Message_Document():
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_size":446}}'
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}'
msg = types.Message.de_json(json_string)
assert msg.document.file_name == 'Text File'
assert msg.content_type == 'document'
def test_json_Message_Photo():
json_string = r'{"message_id":96,"from":{"id":109734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10734,"first_name":"Fd","type":"private","last_name":"dd","username":"dd"},"date":1435478191,"photo":[{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_size":615,"width":90,"height":67},{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_size":10174,"width":320,"height":240},{"file_id":"dd-A_LsTIABFNx-FUOaEa_3AABAQABAg","file_size":53013,"width":759,"height":570}]}'
json_string = r'{"message_id":96,"from":{"id":109734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10734,"first_name":"Fd","type":"private","last_name":"dd","username":"dd"},"date":1435478191,"photo":[{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":615,"width":90,"height":67},{"file_id":"AgADBQADIagxG8YifgYv8yLSj76i-dd","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":10174,"width":320,"height":240},{"file_id":"dd-A_LsTIABFNx-FUOaEa_3AABAQABAg","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":53013,"width":759,"height":570}]}'
msg = types.Message.de_json(json_string)
assert len(msg.photo) == 3
assert msg.content_type == 'photo'
def test_json_Message_Video():
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumb":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_size":260699}}'
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumb":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}'
msg = types.Message.de_json(json_string)
assert msg.video
assert msg.video.duration == 3
@ -94,25 +126,26 @@ def test_json_Message_Location():
def test_json_UserProfilePhotos():
json_string = r'{"total_count":1,"photos":[[{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATZH_SpyZjzIwdVAAIC","file_size":6150,"width":160,"height":160},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATOiTNi_YoJMghVAAIC","file_size":13363,"width":320,"height":320},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAQW4DyFv0-lhglVAAIC","file_size":28347,"width":640,"height":640},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAT50RvJCg0GQApVAAIC","file_size":33953,"width":800,"height":800}]]}'
json_string = r'{"total_count":1,"photos":[[{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATZH_SpyZjzIwdVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":6150,"width":160,"height":160},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAATOiTNi_YoJMghVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":13363,"width":320,"height":320},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAQW4DyFv0-lhglVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":28347,"width":640,"height":640},{"file_id":"AgADAgADqacxG6wpRwABvEB6fpeIcKS4HAIkAAT50RvJCg0GQApVAAIC","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":33953,"width":800,"height":800}]]}'
upp = types.UserProfilePhotos.de_json(json_string)
assert upp.photos[0][0].width == 160
assert upp.photos[0][-1].height == 800
def test_json_contact():
json_string = r'{"phone_number":"00011111111","first_name":"dd","last_name":"ddl","user_id":8633}'
json_string = r'{"phone_number":"00011111111","first_name":"dd","last_name":"ddl","user_id":8633,"vcard":"SomeContactString"}'
contact = types.Contact.de_json(json_string)
assert contact.first_name == 'dd'
assert contact.last_name == 'ddl'
def test_json_voice():
json_string = r'{"duration": 0,"mime_type": "audio/ogg","file_id": "AwcccccccDH1JaB7w_gyFjYQxVAg","file_size": 10481}'
json_string = r'{"duration": 0,"mime_type": "audio/ogg","file_id": "AwcccccccDH1JaB7w_gyFjYQxVAg","file_unique_id": "AgADbAEAAn8VSFY","file_size": 10481}'
voice = types.Voice.de_json(json_string)
assert voice.duration == 0
assert voice.file_size == 10481
def test_json_update():
json_string = r'{"update_id":938203,"message":{"message_id":241,"from":{"is_bot":true,"id":9734,"first_name":"Fk","last_name":"Wg","username":"nir"},"chat":{"id":1111,"first_name":"Fk","type":"private","last_name":"Wg","username":"oir"},"date":1441447009,"text":"HIHI"}}'
update = types.Update.de_json(json_string)
@ -120,6 +153,7 @@ def test_json_update():
assert update.message.message_id == 241
assert update.message.from_user.id == 9734
def test_json_chat():
json_string = r'{"id": -111111,"title": "Test Title","type": "group"}'
chat = types.Chat.de_json(json_string)
@ -127,6 +161,7 @@ def test_json_chat():
assert chat.type == 'group'
assert chat.title == 'Test Title'
def test_InlineQueryResultCachedPhoto():
iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid')
json_str = iq.to_json()
@ -143,6 +178,7 @@ def test_InlineQueryResultCachedPhoto_with_title():
assert 'Title' in json_str
assert 'caption' not in json_str
def test_InlineQueryResultCachedPhoto_with_markup():
markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com"))
@ -155,3 +191,52 @@ def test_InlineQueryResultCachedPhoto_with_markup():
assert 'caption' not in json_str
assert 'reply_markup' in json_str
def test_json_poll_1():
jsonstring = r'{"message_id": 395020,"from": {"id": 111,"is_bot": false,"first_name": "FN","last_name": "LN","username": "Badiboy","language_code": "ru"},"chat": {"id": 111,"first_name": "FN","last_name": "LN","username": "Badiboy","type": "private"},"date": 1587841239,"poll": {"id": "5272018969396510722","question": "Test poll 1","options": [{"text": "Answer 1","voter_count": 0},{"text": "Answer 2","voter_count": 0}],"total_voter_count": 0,"is_closed": false,"is_anonymous": true,"type": "regular","allows_multiple_answers": true}}'
msg = types.Message.de_json(jsonstring)
assert msg.poll is not None
assert isinstance(msg.poll, types.Poll)
assert msg.poll.id == '5272018969396510722'
assert msg.poll.question is not None
assert msg.poll.options is not None
assert len(msg.poll.options) == 2
assert msg.poll.allows_multiple_answers is True
def test_json_poll_answer():
jsonstring = r'{"poll_id": "5895675970559410186", "user": {"id": 329343347, "is_bot": false, "first_name": "Test", "username": "test_user", "last_name": "User", "language_code": "en"}, "option_ids": [1]}'
__import__('pprint').pprint(__import__('json').loads(jsonstring))
poll_answer = types.PollAnswer.de_json(jsonstring)
assert poll_answer.poll_id == '5895675970559410186'
assert isinstance(poll_answer.user, types.User)
assert poll_answer.option_ids == [1]
def test_KeyboardButtonPollType():
markup = types.ReplyKeyboardMarkup()
markup.add(types.KeyboardButton('send me a poll', request_poll=types.KeyboardButtonPollType(type='quiz')))
json_str = markup.to_json()
assert 'request_poll' in json_str
assert 'quiz' in json_str
def test_json_chat_invite_link():
json_string = r'{"invite_link": "https://t.me/joinchat/z-abCdEFghijKlMn", "creator": {"id": 329343347, "is_bot": false, "first_name": "Test", "username": "test_user", "last_name": "User", "language_code": "en"}, "is_primary": false, "is_revoked": false, "expire_date": 1624119999, "member_limit": 10}'
invite_link = types.ChatInviteLink.de_json(json_string)
assert invite_link.invite_link == 'https://t.me/joinchat/z-abCdEFghijKlMn'
assert isinstance(invite_link.creator, types.User)
assert not invite_link.is_primary
assert not invite_link.is_revoked
assert invite_link.expire_date == 1624119999
assert invite_link.member_limit == 10
def test_chat_member_updated():
json_string = r'{"chat": {"id": -1234567890123, "type": "supergroup", "title": "No Real Group", "username": "NoRealGroup"}, "from": {"id": 133869498, "is_bot": false, "first_name": "Vincent"}, "date": 1624119999, "old_chat_member": {"user": {"id": 77777777, "is_bot": false, "first_name": "Pepe"}, "status": "member"}, "new_chat_member": {"user": {"id": 77777777, "is_bot": false, "first_name": "Pepe"}, "status": "administrator"}}'
cm_updated = types.ChatMemberUpdated.de_json(json_string)
assert cm_updated.chat.id == -1234567890123
assert cm_updated.from_user.id == 133869498
assert cm_updated.date == 1624119999
assert cm_updated.old_chat_member.status == "member"
assert cm_updated.new_chat_member.status == "administrator"