telekit 2.6.0a8__tar.gz → 2.6.0a9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. {telekit-2.6.0a8 → telekit-2.6.0a9}/CHANGELOG.md +19 -14
  2. {telekit-2.6.0a8/telekit.egg-info → telekit-2.6.0a9}/PKG-INFO +20 -15
  3. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/__version__.py +1 -1
  4. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_inline_keyboard.py +93 -0
  5. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_reply_keyboard.py +34 -3
  6. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/reply_buttons.py +1 -1
  7. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/senders.py +37 -2
  8. {telekit-2.6.0a8 → telekit-2.6.0a9/telekit.egg-info}/PKG-INFO +20 -15
  9. {telekit-2.6.0a8 → telekit-2.6.0a9}/LICENSE +0 -0
  10. {telekit-2.6.0a8 → telekit-2.6.0a9}/MANIFEST.in +0 -0
  11. {telekit-2.6.0a8 → telekit-2.6.0a9}/README.md +0 -0
  12. {telekit-2.6.0a8 → telekit-2.6.0a9}/setup.cfg +0 -0
  13. {telekit-2.6.0a8 → telekit-2.6.0a9}/setup.py +0 -0
  14. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/__init__.py +0 -0
  15. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_buildtext/__init__.py +0 -0
  16. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_buildtext/formatter.py +0 -0
  17. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_buildtext/styles.py +0 -0
  18. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_callback_query_handler.py +0 -0
  19. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chain.py +0 -0
  20. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chain_base.py +0 -0
  21. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chain_entry_logic.py +0 -0
  22. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chain_inline_keyboards_logic.py +0 -0
  23. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chapters/__init__.py +0 -0
  24. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_chapters/chapters.py +0 -0
  25. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_file_cache.py +0 -0
  26. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_handler.py +0 -0
  27. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_init.py +0 -0
  28. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_inline_buttons.py +0 -0
  29. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_input_handler.py +0 -0
  30. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_logger.py +0 -0
  31. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_on.py +0 -0
  32. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_rich.py +0 -0
  33. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_snapvault/__init__.py +0 -0
  34. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_snapvault/snapcode.py +0 -0
  35. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_snapvault/snapvault.py +0 -0
  36. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_state.py +0 -0
  37. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/__init__.py +0 -0
  38. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/mixin.py +0 -0
  39. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/__init__.py +0 -0
  40. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/builder.py +0 -0
  41. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/canvas_parser.py +0 -0
  42. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/lexer.py +0 -0
  43. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/nodes.py +0 -0
  44. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/parser.py +0 -0
  45. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/parser/token.py +0 -0
  46. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/telekit_dsl.py +0 -0
  47. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_telekit_dsl/telekit_orm.py +0 -0
  48. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_text_builder.py +0 -0
  49. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_timeout.py +0 -0
  50. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_trait.py +0 -0
  51. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/_user.py +0 -0
  52. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/chat.py +0 -0
  53. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/debug.py +0 -0
  54. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/dices.py +0 -0
  55. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/__init__.py +0 -0
  56. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/__init__.py +0 -0
  57. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/article.py +0 -0
  58. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/calendar.py +0 -0
  59. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/complete_hotel.py +0 -0
  60. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/counter.py +0 -0
  61. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/dsl.py +0 -0
  62. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/entry.py +0 -0
  63. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/faq.py +0 -0
  64. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/hotel.py +0 -0
  65. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/on_text.py +0 -0
  66. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/pages.py +0 -0
  67. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/pyapi.py +0 -0
  68. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/qr.py +0 -0
  69. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/quiz.py +0 -0
  70. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/rich.py +0 -0
  71. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/spells.py +0 -0
  72. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/start.py +0 -0
  73. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/style.py +0 -0
  74. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_handlers/text_document.py +0 -0
  75. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/example/example_server.py +0 -0
  76. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/html_text.py +0 -0
  77. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/inline_buttons.py +0 -0
  78. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/parameters.py +0 -0
  79. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/requirements.txt +0 -0
  80. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/scheduler.py +0 -0
  81. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/server.py +0 -0
  82. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/styles.py +0 -0
  83. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/traits/__init__.py +0 -0
  84. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/traits/calendar_pick.py +0 -0
  85. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/traits/paginated_choice.py +0 -0
  86. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/traits/paginated_text.py +0 -0
  87. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/traits/track_handoff_origin.py +0 -0
  88. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/types.py +0 -0
  89. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit/utils.py +0 -0
  90. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit.egg-info/SOURCES.txt +0 -0
  91. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit.egg-info/dependency_links.txt +0 -0
  92. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit.egg-info/requires.txt +0 -0
  93. {telekit-2.6.0a8 → telekit-2.6.0a9}/telekit.egg-info/top_level.txt +0 -0
@@ -1,5 +1,17 @@
1
- ### v2.6.0 `a7`
2
- #### Server
1
+ ### v2.6.0 `a9` – Keyboards in Senders
2
+ - Added `InlineKeyboard.to_markup()`: compiles the keyboard into a ready-to-send `InlineKeyboardMarkup`. Only buttons that don't need a chain to register handlers are supported (`StaticButton`, `LinkButton` and its subclasses, `WebAppButton`, `SuggestButton`, `CopyTextButton`); callback-based buttons (`CallbackButton`, `InvokeButton`, `AnswerButton`, `AlertButton`, `NotificationButton`) raise `TypeError` and should be used via `chain.set_inline_keyboard()`
3
+ - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
4
+ - Added `set_keyboard()` to `BaseSender`: a shortcut for `set_reply_markup(keyboard.to_markup())` that accepts both `InlineKeyboard` and `ReplyKeyboard`, so keyboards can be passed to a plain `sender` without a chain
5
+
6
+ ### v2.6.0 `a7` – Sender, Server, Logging
7
+ #### Sender: automatic `file_id` caching
8
+ - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
9
+ - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
10
+ - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
11
+ - Changed missing local files to raise on `send()` instead of in the setter
12
+ - A rejected cached `file_id` is dropped and the send is retried with the original file
13
+ - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
14
+ #### Server: restarts and network protection
3
15
  - Added `restart` parameter to `Server`: `"always"` (default), `"network"` or `"never"`; accepts `RestartMode` or the matching string
4
16
  - Deprecated `Server(auto_restart=...)`: `True` is now `restart="always"`, `False` is `restart="never"`; emits `DeprecationWarning` and a log warning. Cannot be combined with `restart` (`TypeError`)
5
17
  - Added network protection to `Server.polling()` and `Server.long_polling()`: restarts are now delayed by exponential backoff (5 s up to 60 s, reset after 120 s of stable work) instead of a fixed 10 s / 5 s. Tunable via `Server.RESTART_DELAY_MIN`, `RESTART_DELAY_MAX` and `STABLE_AFTER`
@@ -16,40 +28,33 @@
16
28
  - Changed `telekit` loggers to `propagate=False`: records no longer reach the root logger, so they are not duplicated when the app configures it. Attach custom handlers to `logging.getLogger("telekit")`
17
29
  - Changed `enable_file_logging()` to be idempotent, to create parent folders, and to use one format (with `filename:lineno`) for all files, including `server.log`
18
30
  - Fixed `UserLogger` reporting its own module as the log source
19
- #### Sender
20
- - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
21
- - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
22
- - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
23
- - Changed missing local files to raise on `send()` instead of in the setter
24
- - A rejected cached `file_id` is dropped and the send is retried with the original file
25
- - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
26
31
 
27
- ### v2.6.0 `a6` (fixes #6)
32
+ ### v2.6.0 `a6` (fixes #6) – Timeout engine
28
33
  - Reworked the timeout engine to fix thread exhaustion with many concurrent chats (#6): every `set_timeout()` used to start its own `threading.Timer` (one OS thread per waiting chat), so ~1000 active users crashed the bot with `can't start new thread`
29
34
  - Timeout callback exceptions are now logged
30
35
  - Added `configure_timeouts(max_workers, *, idle_timeout, log_worker_changes, warn_on_max_workers)` to tune the worker pool, log worker start/stop, and control the "all workers busy" warning (enabled by default)
31
36
 
32
- ### v2.6.0 `a4`
37
+ ### v2.6.0 `a4` – Handoff shortcuts
33
38
  - Added `handle_handoff()` to `Handler`: a shortcut for `handoff(handler).handle()` that takes the target handler as an argument, so it can be passed to `add_callback()` without an extra closure
34
39
  - Added `handle_handoff_back_or()` to `TrackHandoffOrigin`: a closure-free counterpart of `handoff_back_or()`
35
40
  - Reworked `handoff_back_or()` as a thin `functools.partial` wrapper around `handle_handoff_back_or()`
36
41
  - Fixed the `handoff_back_or()` docstring: the returned callable forwards its arguments to `handle()` instead of being zero-argument
37
42
  - Converted the `handoff()` docstring to reST
38
43
 
39
- ### v2.6.0 `a3`
44
+ ### v2.6.0 `a3` – Rich HTML
40
45
  - Added support for Rich HTML messages (Bot API 10.1+)
41
46
  - Added the `_rich.py` module for Rich HTML parsing and serialization
42
47
  - Added new rich tags to `styles.py` for enhanced text formatting
43
48
  - Added the `rich.py` example handler demonstrating Rich HTML: inline styles, blocks, lists, tables, media, and sender integration
44
49
 
45
- ### v2.6.0 `a2`
50
+ ### v2.6.0 `a2` – Env parsing
46
51
  - Reworked `.env` and token/canvas file reading in `utils`
47
52
  - Added full `.env` syntax support: comments, `export`, quotes and escapes, multi-line values, `$VAR` interpolation
48
53
  - Added the `cache` parameter (default `True`) and `clear_cache()`
49
54
  - Added detailed errors with fix suggestions and creation commands, and new `Env*Error` exceptions
50
55
  - Changed `load_env()` to raise `EnvFileNotFoundError` for a missing file instead of returning `{}`
51
56
 
52
- ### v2.6.0 `a1`
57
+ ### v2.6.0 `a1` – Module loader
53
58
  - Added a module-loading utility to `utils`
54
59
 
55
60
  ### v2.6.0 `a0`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telekit
3
- Version: 2.6.0a8
3
+ Version: 2.6.0a9
4
4
  Summary: Declarative, developer-friendly framework for building Telegram bots
5
5
  Home-page: https://github.com/Romashkaa/telekit
6
6
  Author: romashka
@@ -480,8 +480,20 @@ Telekit focuses on one job: making Telegram bot development easier.
480
480
 
481
481
  # Changelog
482
482
 
483
- ### v2.6.0 `a7`
484
- #### Server
483
+ ### v2.6.0 `a9` – Keyboards in Senders
484
+ - Added `InlineKeyboard.to_markup()`: compiles the keyboard into a ready-to-send `InlineKeyboardMarkup`. Only buttons that don't need a chain to register handlers are supported (`StaticButton`, `LinkButton` and its subclasses, `WebAppButton`, `SuggestButton`, `CopyTextButton`); callback-based buttons (`CallbackButton`, `InvokeButton`, `AnswerButton`, `AlertButton`, `NotificationButton`) raise `TypeError` and should be used via `chain.set_inline_keyboard()`
485
+ - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
486
+ - Added `set_keyboard()` to `BaseSender`: a shortcut for `set_reply_markup(keyboard.to_markup())` that accepts both `InlineKeyboard` and `ReplyKeyboard`, so keyboards can be passed to a plain `sender` without a chain
487
+
488
+ ### v2.6.0 `a7` – Sender, Server, Logging
489
+ #### Sender: automatic `file_id` caching
490
+ - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
491
+ - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
492
+ - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
493
+ - Changed missing local files to raise on `send()` instead of in the setter
494
+ - A rejected cached `file_id` is dropped and the send is retried with the original file
495
+ - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
496
+ #### Server: restarts and network protection
485
497
  - Added `restart` parameter to `Server`: `"always"` (default), `"network"` or `"never"`; accepts `RestartMode` or the matching string
486
498
  - Deprecated `Server(auto_restart=...)`: `True` is now `restart="always"`, `False` is `restart="never"`; emits `DeprecationWarning` and a log warning. Cannot be combined with `restart` (`TypeError`)
487
499
  - Added network protection to `Server.polling()` and `Server.long_polling()`: restarts are now delayed by exponential backoff (5 s up to 60 s, reset after 120 s of stable work) instead of a fixed 10 s / 5 s. Tunable via `Server.RESTART_DELAY_MIN`, `RESTART_DELAY_MAX` and `STABLE_AFTER`
@@ -498,40 +510,33 @@ Telekit focuses on one job: making Telegram bot development easier.
498
510
  - Changed `telekit` loggers to `propagate=False`: records no longer reach the root logger, so they are not duplicated when the app configures it. Attach custom handlers to `logging.getLogger("telekit")`
499
511
  - Changed `enable_file_logging()` to be idempotent, to create parent folders, and to use one format (with `filename:lineno`) for all files, including `server.log`
500
512
  - Fixed `UserLogger` reporting its own module as the log source
501
- #### Sender
502
- - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
503
- - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
504
- - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
505
- - Changed missing local files to raise on `send()` instead of in the setter
506
- - A rejected cached `file_id` is dropped and the send is retried with the original file
507
- - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
508
513
 
509
- ### v2.6.0 `a6` (fixes #6)
514
+ ### v2.6.0 `a6` (fixes #6) – Timeout engine
510
515
  - Reworked the timeout engine to fix thread exhaustion with many concurrent chats (#6): every `set_timeout()` used to start its own `threading.Timer` (one OS thread per waiting chat), so ~1000 active users crashed the bot with `can't start new thread`
511
516
  - Timeout callback exceptions are now logged
512
517
  - Added `configure_timeouts(max_workers, *, idle_timeout, log_worker_changes, warn_on_max_workers)` to tune the worker pool, log worker start/stop, and control the "all workers busy" warning (enabled by default)
513
518
 
514
- ### v2.6.0 `a4`
519
+ ### v2.6.0 `a4` – Handoff shortcuts
515
520
  - Added `handle_handoff()` to `Handler`: a shortcut for `handoff(handler).handle()` that takes the target handler as an argument, so it can be passed to `add_callback()` without an extra closure
516
521
  - Added `handle_handoff_back_or()` to `TrackHandoffOrigin`: a closure-free counterpart of `handoff_back_or()`
517
522
  - Reworked `handoff_back_or()` as a thin `functools.partial` wrapper around `handle_handoff_back_or()`
518
523
  - Fixed the `handoff_back_or()` docstring: the returned callable forwards its arguments to `handle()` instead of being zero-argument
519
524
  - Converted the `handoff()` docstring to reST
520
525
 
521
- ### v2.6.0 `a3`
526
+ ### v2.6.0 `a3` – Rich HTML
522
527
  - Added support for Rich HTML messages (Bot API 10.1+)
523
528
  - Added the `_rich.py` module for Rich HTML parsing and serialization
524
529
  - Added new rich tags to `styles.py` for enhanced text formatting
525
530
  - Added the `rich.py` example handler demonstrating Rich HTML: inline styles, blocks, lists, tables, media, and sender integration
526
531
 
527
- ### v2.6.0 `a2`
532
+ ### v2.6.0 `a2` – Env parsing
528
533
  - Reworked `.env` and token/canvas file reading in `utils`
529
534
  - Added full `.env` syntax support: comments, `export`, quotes and escapes, multi-line values, `$VAR` interpolation
530
535
  - Added the `cache` parameter (default `True`) and `clear_cache()`
531
536
  - Added detailed errors with fix suggestions and creation commands, and new `Env*Error` exceptions
532
537
  - Changed `load_env()` to raise `EnvFileNotFoundError` for a missing file instead of returning `{}`
533
538
 
534
- ### v2.6.0 `a1`
539
+ ### v2.6.0 `a1` – Module loader
535
540
  - Added a module-loading utility to `utils`
536
541
 
537
542
  ### v2.6.0 `a0`
@@ -2,4 +2,4 @@
2
2
  # PyPI history: https://pypi.org/project/telekit/#history
3
3
  # ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
4
4
 
5
- __version__ = "2.6.0a8"
5
+ __version__ = "2.6.0a9"
@@ -1,8 +1,59 @@
1
1
  from typing import Callable, Any, Literal
2
2
 
3
+ from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
4
+
3
5
  from telekit.inline_buttons import *
4
6
 
7
+
5
8
  class InlineKeyboard:
9
+ """
10
+ A fluent builder for Telegram inline keyboards.
11
+
12
+ Supports all button types available in the Telegram Bot API for inline
13
+ keyboards, as well as row/column layout helpers and bulk-add methods.
14
+
15
+ The finished keyboard can be attached to a message in two ways: through
16
+ a chain, or directly through a sender. The difference is in which buttons
17
+ each of them supports.
18
+
19
+ Usage in a chain (callback buttons are supported)::
20
+
21
+ keyboard = (
22
+ InlineKeyboard()
23
+ .add_callback("✅ Confirm", self.on_confirm)
24
+ .add_callback("✕ Cancel", self.on_cancel)
25
+ .row()
26
+ .add_link("📖 Docs", "https://example.com")
27
+ )
28
+
29
+ self.chain.set_keyboard(keyboard)
30
+
31
+ Usage with a standalone sender (buttons without callbacks only)::
32
+
33
+ keyboard = (
34
+ InlineKeyboard()
35
+ .add_link("📖 Docs", "https://example.com")
36
+ .add_copy("📋 Copy", "hello")
37
+ .row()
38
+ .add_webapp("🚀 Open app", "https://example.com/app")
39
+ )
40
+
41
+ sender.set_keyboard(keyboard)
42
+
43
+ .. note::
44
+ A standalone sender has no chain to register button handlers, so
45
+ :meth:`to_markup` supports only :class:`StaticButton`,
46
+ :class:`LinkButton` (and its subclasses), :class:`WebAppButton`,
47
+ :class:`SuggestButton` and :class:`CopyTextButton`. Callback-based
48
+ buttons (:class:`CallbackButton`, :class:`InvokeButton`,
49
+ :class:`AnswerButton`, :class:`AlertButton`, :class:`NotificationButton`)
50
+ raise :class:`TypeError`; attach such a keyboard through
51
+ ``chain.set_keyboard()`` instead.
52
+
53
+ :param inline_keyboard: Pre-built rows of ``(text, InlineButton)`` tuples
54
+ used to seed the builder.
55
+ :type inline_keyboard: list[list[tuple[str, InlineButton]]] or None
56
+ """
6
57
  def __init__(self, inline_keyboard: list[list[tuple[str, InlineButton]]] | None = None):
7
58
  self._rows: list[list[tuple[str, InlineButton]]] = []
8
59
 
@@ -109,6 +160,48 @@ class InlineKeyboard:
109
160
  def _compile(self) -> list[list[tuple[str, InlineButton]]]:
110
161
  self.row()
111
162
  return self._rows
163
+
164
+ def to_markup(self) -> InlineKeyboardMarkup:
165
+ """
166
+ Compiles the keyboard into a ready-to-send `InlineKeyboardMarkup`.
167
+
168
+ The result can be passed directly to `sender.set_reply_markup(...)`.
169
+
170
+ Only buttons that don't need a chain/handler are supported:
171
+ `StaticButton`, `LinkButton` (and subclasses), `WebAppButton`,
172
+ `SuggestButton`, `CopyTextButton`.
173
+
174
+ Callback-based buttons (`CallbackButton`, `InvokeButton`,
175
+ `AnswerButton`, `AlertButton`, `NotificationButton`) require a chain
176
+ to register their handlers, so they raise `TypeError` here.
177
+
178
+ Example::
179
+
180
+ kb = (
181
+ InlineKeyboard()
182
+ .add_link("Docs", "https://example.com")
183
+ .add_copy("Copy", "hello")
184
+ )
185
+ sender.set_reply_markup(kb.to_markup())
186
+ sender.send()
187
+ """
188
+ markup = InlineKeyboardMarkup()
189
+
190
+ for row in self._compile():
191
+ buttons: list[InlineKeyboardButton] = []
192
+
193
+ for caption, button in row:
194
+ if isinstance(button, CallbackButton):
195
+ raise TypeError(
196
+ f"{type(button).__name__} cannot be compiled via to_markup(): "
197
+ f"callback buttons need a chain to register handlers. "
198
+ f"Use chain.set_inline_keyboard(...) instead."
199
+ )
200
+ buttons.append(button._compile(caption))
201
+
202
+ markup.row(*buttons)
203
+
204
+ return markup
112
205
 
113
206
  def add(self, text: str, inline_button: InlineButton | None = None, *, when: bool | int = True):
114
207
  """
@@ -22,16 +22,19 @@ class ReplyKeyboard:
22
22
 
23
23
  Basic usage::
24
24
 
25
- markup = (
25
+ keyboard = (
26
26
  ReplyKeyboard(resize_keyboard=True)
27
27
  .add_contact("📱 Share phone")
28
28
  .add_location("📍 My location")
29
29
  .row()
30
30
  .add_text("Option A")
31
31
  .add_text("Option B")
32
- .build()
33
32
  )
34
- bot.send_message(chat_id, "Choose:", reply_markup=markup)
33
+ # Attach the keyboard via a chain:
34
+ chain.set_keyboard(keyboard)
35
+
36
+ # Or attach it directly to a standalone sender:
37
+ sender.set_keyboard(keyboard)
35
38
 
36
39
  :param keyboard: Pre-built rows of ``(text, ReplyButton)`` tuples to seed
37
40
  the builder with. Useful for composing keyboards programmatically.
@@ -184,6 +187,34 @@ class ReplyKeyboard:
184
187
  if self._grid_width and self._grid_count() >= self._grid_width:
185
188
  self.row()
186
189
 
190
+ def to_markup(self) -> ReplyKeyboardMarkup:
191
+ """
192
+ Compiles the keyboard into a ready-to-send :class:`telebot.types.ReplyKeyboardMarkup`.
193
+
194
+ The result can be passed directly to :meth:`Sender.set_reply_markup`,
195
+ or you can use :meth:`Sender.set_keyboard` as a shortcut.
196
+
197
+ Any pending row is flushed automatically, so calling :meth:`row`
198
+ at the end of the chain is not required.
199
+
200
+ :returns: The compiled reply keyboard markup.
201
+ :rtype: :class:`telebot.types.ReplyKeyboardMarkup`
202
+
203
+ Example::
204
+
205
+ markup = (
206
+ ReplyKeyboard(resize_keyboard=True)
207
+ .add_contact("📱 Share phone")
208
+ .add_location("📍 My location")
209
+ .row()
210
+ .add_text("Option A")
211
+ .add_text("Option B")
212
+ .to_markup()
213
+ )
214
+ sender.set_reply_markup(markup)
215
+ """
216
+ return self._compile()
217
+
187
218
  # ── Generic add ───────────────────────────────────────────────────────────
188
219
 
189
220
  def add(
@@ -94,6 +94,7 @@ class LocationButton(ReplyButton):
94
94
  """
95
95
  return KeyboardButton(text, request_location=True)
96
96
 
97
+ # Telebot API fix
97
98
  class _FixedKeyboardButtonPollType(KeyboardButtonPollType):
98
99
  def to_dict(self):
99
100
  # FIX: Bad Request: can't parse keyboard button: Field "type" must be of type String.
@@ -123,7 +124,6 @@ class PollButton(ReplyButton):
123
124
  :type text: str
124
125
  :rtype: :class:`telebot.types.KeyboardButton`
125
126
  """
126
- print(f"{self.poll_type=}")
127
127
  return KeyboardButton(
128
128
  text,
129
129
  request_poll=_FixedKeyboardButtonPollType(type=self.poll_type),
@@ -19,12 +19,12 @@
19
19
 
20
20
  from typing import Any, Literal, NoReturn, TYPE_CHECKING, Union
21
21
  import textwrap
22
- import json
23
22
  import io
24
23
 
25
24
  if TYPE_CHECKING:
26
25
  from string.templatelib import Template # pyright: ignore[reportMissingImports]
27
-
26
+ from telekit._inline_keyboard import InlineKeyboard
27
+ from telekit._reply_keyboard import ReplyKeyboard
28
28
 
29
29
  from telebot import TeleBot, apihelper
30
30
  from telebot.types import (
@@ -547,6 +547,41 @@ class BaseSender:
547
547
  """
548
548
  self.reply_markup = reply_markup
549
549
 
550
+ def set_keyboard(self, keyboard: Union["InlineKeyboard", "ReplyKeyboard"]) -> None:
551
+ """
552
+ Sets an inline or reply keyboard as the message's reply markup.
553
+
554
+ Compiles ``keyboard`` via its ``to_markup()`` method and stores the
555
+ result in :attr:`reply_markup`. This is a shortcut for
556
+ ``sender.set_reply_markup(keyboard.to_markup())``.
557
+
558
+ .. note::
559
+ For :class:`InlineKeyboard`, only buttons that don't need a chain
560
+ to register handlers are supported: :class:`StaticButton`,
561
+ :class:`LinkButton` (and its subclasses), :class:`WebAppButton`,
562
+ :class:`SuggestButton` and :class:`CopyTextButton`.
563
+ Use ``chain.set_inline_keyboard(...)`` for callback-based buttons.
564
+
565
+ :param keyboard: The keyboard to attach to the message.
566
+ :type keyboard: :class:`InlineKeyboard` | :class:`ReplyKeyboard`
567
+
568
+ :raises TypeError: If an :class:`InlineKeyboard` contains a callback-based
569
+ button (:class:`CallbackButton`, :class:`InvokeButton`,
570
+ :class:`AnswerButton`, :class:`AlertButton`, :class:`NotificationButton`).
571
+
572
+ Example::
573
+
574
+ sender.set_keyboard(
575
+ InlineKeyboard().add_link("Docs", "https://example.com")
576
+ )
577
+
578
+ sender.set_keyboard(
579
+ ReplyKeyboard().add_text("Yes").add_text("No")
580
+ )
581
+ sender.send()
582
+ """
583
+ self.reply_markup = keyboard.to_markup()
584
+
550
585
  def set_temporary(self, is_temp: bool):
551
586
  """
552
587
  Marks message as temporary; will be deleted later if `delete_temporaries` is True.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telekit
3
- Version: 2.6.0a8
3
+ Version: 2.6.0a9
4
4
  Summary: Declarative, developer-friendly framework for building Telegram bots
5
5
  Home-page: https://github.com/Romashkaa/telekit
6
6
  Author: romashka
@@ -480,8 +480,20 @@ Telekit focuses on one job: making Telegram bot development easier.
480
480
 
481
481
  # Changelog
482
482
 
483
- ### v2.6.0 `a7`
484
- #### Server
483
+ ### v2.6.0 `a9` – Keyboards in Senders
484
+ - Added `InlineKeyboard.to_markup()`: compiles the keyboard into a ready-to-send `InlineKeyboardMarkup`. Only buttons that don't need a chain to register handlers are supported (`StaticButton`, `LinkButton` and its subclasses, `WebAppButton`, `SuggestButton`, `CopyTextButton`); callback-based buttons (`CallbackButton`, `InvokeButton`, `AnswerButton`, `AlertButton`, `NotificationButton`) raise `TypeError` and should be used via `chain.set_inline_keyboard()`
485
+ - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
486
+ - Added `set_keyboard()` to `BaseSender`: a shortcut for `set_reply_markup(keyboard.to_markup())` that accepts both `InlineKeyboard` and `ReplyKeyboard`, so keyboards can be passed to a plain `sender` without a chain
487
+
488
+ ### v2.6.0 `a7` – Sender, Server, Logging
489
+ #### Sender: automatic `file_id` caching
490
+ - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
491
+ - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
492
+ - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
493
+ - Changed missing local files to raise on `send()` instead of in the setter
494
+ - A rejected cached `file_id` is dropped and the send is retried with the original file
495
+ - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
496
+ #### Server: restarts and network protection
485
497
  - Added `restart` parameter to `Server`: `"always"` (default), `"network"` or `"never"`; accepts `RestartMode` or the matching string
486
498
  - Deprecated `Server(auto_restart=...)`: `True` is now `restart="always"`, `False` is `restart="never"`; emits `DeprecationWarning` and a log warning. Cannot be combined with `restart` (`TypeError`)
487
499
  - Added network protection to `Server.polling()` and `Server.long_polling()`: restarts are now delayed by exponential backoff (5 s up to 60 s, reset after 120 s of stable work) instead of a fixed 10 s / 5 s. Tunable via `Server.RESTART_DELAY_MIN`, `RESTART_DELAY_MAX` and `STABLE_AFTER`
@@ -498,40 +510,33 @@ Telekit focuses on one job: making Telegram bot development easier.
498
510
  - Changed `telekit` loggers to `propagate=False`: records no longer reach the root logger, so they are not duplicated when the app configures it. Attach custom handlers to `logging.getLogger("telekit")`
499
511
  - Changed `enable_file_logging()` to be idempotent, to create parent folders, and to use one format (with `filename:lineno`) for all files, including `server.log`
500
512
  - Fixed `UserLogger` reporting its own module as the log source
501
- #### Sender
502
- - Added a `FileIdCache` that stores Telegram `file_id` for local files (photo, document, video, animation, audio, voice, video note), so repeated sends skip the upload
503
- - Added `BaseSender.configure_file_cache()`: a class method that sets the database path, table name and global on/off switch
504
- - Added `Sender.set_use_file_cache()`: a per-sender override of the global setting (`None` restores it)
505
- - Changed missing local files to raise on `send()` instead of in the setter
506
- - A rejected cached `file_id` is dropped and the send is retried with the original file
507
- - Notes: URLs, `bytes` and file-like objects are not cached; rich messages and media groups are unaffected. A changed file is detected by `size/mtime`, with a `SHA-256` comparison as a fallback
508
513
 
509
- ### v2.6.0 `a6` (fixes #6)
514
+ ### v2.6.0 `a6` (fixes #6) – Timeout engine
510
515
  - Reworked the timeout engine to fix thread exhaustion with many concurrent chats (#6): every `set_timeout()` used to start its own `threading.Timer` (one OS thread per waiting chat), so ~1000 active users crashed the bot with `can't start new thread`
511
516
  - Timeout callback exceptions are now logged
512
517
  - Added `configure_timeouts(max_workers, *, idle_timeout, log_worker_changes, warn_on_max_workers)` to tune the worker pool, log worker start/stop, and control the "all workers busy" warning (enabled by default)
513
518
 
514
- ### v2.6.0 `a4`
519
+ ### v2.6.0 `a4` – Handoff shortcuts
515
520
  - Added `handle_handoff()` to `Handler`: a shortcut for `handoff(handler).handle()` that takes the target handler as an argument, so it can be passed to `add_callback()` without an extra closure
516
521
  - Added `handle_handoff_back_or()` to `TrackHandoffOrigin`: a closure-free counterpart of `handoff_back_or()`
517
522
  - Reworked `handoff_back_or()` as a thin `functools.partial` wrapper around `handle_handoff_back_or()`
518
523
  - Fixed the `handoff_back_or()` docstring: the returned callable forwards its arguments to `handle()` instead of being zero-argument
519
524
  - Converted the `handoff()` docstring to reST
520
525
 
521
- ### v2.6.0 `a3`
526
+ ### v2.6.0 `a3` – Rich HTML
522
527
  - Added support for Rich HTML messages (Bot API 10.1+)
523
528
  - Added the `_rich.py` module for Rich HTML parsing and serialization
524
529
  - Added new rich tags to `styles.py` for enhanced text formatting
525
530
  - Added the `rich.py` example handler demonstrating Rich HTML: inline styles, blocks, lists, tables, media, and sender integration
526
531
 
527
- ### v2.6.0 `a2`
532
+ ### v2.6.0 `a2` – Env parsing
528
533
  - Reworked `.env` and token/canvas file reading in `utils`
529
534
  - Added full `.env` syntax support: comments, `export`, quotes and escapes, multi-line values, `$VAR` interpolation
530
535
  - Added the `cache` parameter (default `True`) and `clear_cache()`
531
536
  - Added detailed errors with fix suggestions and creation commands, and new `Env*Error` exceptions
532
537
  - Changed `load_env()` to raise `EnvFileNotFoundError` for a missing file instead of returning `{}`
533
538
 
534
- ### v2.6.0 `a1`
539
+ ### v2.6.0 `a1` – Module loader
535
540
  - Added a module-loading utility to `utils`
536
541
 
537
542
  ### v2.6.0 `a0`
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes