telekit 2.6.0a9__tar.gz → 2.6.1__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.0a9 → telekit-2.6.1}/CHANGELOG.md +19 -0
  2. {telekit-2.6.0a9/telekit.egg-info → telekit-2.6.1}/PKG-INFO +53 -38
  3. {telekit-2.6.0a9 → telekit-2.6.1}/README.md +33 -37
  4. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/__version__.py +1 -1
  5. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_callback_query_handler.py +18 -3
  6. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/telekit_dsl.py +1 -1
  7. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/senders.py +26 -5
  8. {telekit-2.6.0a9 → telekit-2.6.1/telekit.egg-info}/PKG-INFO +53 -38
  9. {telekit-2.6.0a9 → telekit-2.6.1}/LICENSE +0 -0
  10. {telekit-2.6.0a9 → telekit-2.6.1}/MANIFEST.in +0 -0
  11. {telekit-2.6.0a9 → telekit-2.6.1}/setup.cfg +0 -0
  12. {telekit-2.6.0a9 → telekit-2.6.1}/setup.py +0 -0
  13. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/__init__.py +0 -0
  14. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_buildtext/__init__.py +0 -0
  15. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_buildtext/formatter.py +0 -0
  16. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_buildtext/styles.py +0 -0
  17. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chain.py +0 -0
  18. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chain_base.py +0 -0
  19. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chain_entry_logic.py +0 -0
  20. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chain_inline_keyboards_logic.py +0 -0
  21. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chapters/__init__.py +0 -0
  22. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_chapters/chapters.py +0 -0
  23. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_file_cache.py +0 -0
  24. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_handler.py +0 -0
  25. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_init.py +0 -0
  26. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_inline_buttons.py +0 -0
  27. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_inline_keyboard.py +0 -0
  28. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_input_handler.py +0 -0
  29. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_logger.py +0 -0
  30. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_on.py +0 -0
  31. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_reply_keyboard.py +0 -0
  32. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_rich.py +0 -0
  33. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_snapvault/__init__.py +0 -0
  34. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_snapvault/snapcode.py +0 -0
  35. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_snapvault/snapvault.py +0 -0
  36. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_state.py +0 -0
  37. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/__init__.py +0 -0
  38. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/mixin.py +0 -0
  39. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/__init__.py +0 -0
  40. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/builder.py +0 -0
  41. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/canvas_parser.py +0 -0
  42. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/lexer.py +0 -0
  43. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/nodes.py +0 -0
  44. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/parser.py +0 -0
  45. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/parser/token.py +0 -0
  46. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_telekit_dsl/telekit_orm.py +0 -0
  47. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_text_builder.py +0 -0
  48. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_timeout.py +0 -0
  49. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_trait.py +0 -0
  50. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/_user.py +0 -0
  51. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/chat.py +0 -0
  52. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/debug.py +0 -0
  53. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/dices.py +0 -0
  54. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/__init__.py +0 -0
  55. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/__init__.py +0 -0
  56. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/article.py +0 -0
  57. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/calendar.py +0 -0
  58. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/complete_hotel.py +0 -0
  59. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/counter.py +0 -0
  60. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/dsl.py +0 -0
  61. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/entry.py +0 -0
  62. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/faq.py +0 -0
  63. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/hotel.py +0 -0
  64. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/on_text.py +0 -0
  65. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/pages.py +0 -0
  66. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/pyapi.py +0 -0
  67. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/qr.py +0 -0
  68. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/quiz.py +0 -0
  69. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/rich.py +0 -0
  70. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/spells.py +0 -0
  71. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/start.py +0 -0
  72. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/style.py +0 -0
  73. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_handlers/text_document.py +0 -0
  74. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/example/example_server.py +0 -0
  75. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/html_text.py +0 -0
  76. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/inline_buttons.py +0 -0
  77. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/parameters.py +0 -0
  78. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/reply_buttons.py +0 -0
  79. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/requirements.txt +0 -0
  80. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/scheduler.py +0 -0
  81. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/server.py +0 -0
  82. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/styles.py +0 -0
  83. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/traits/__init__.py +0 -0
  84. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/traits/calendar_pick.py +0 -0
  85. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/traits/paginated_choice.py +0 -0
  86. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/traits/paginated_text.py +0 -0
  87. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/traits/track_handoff_origin.py +0 -0
  88. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/types.py +0 -0
  89. {telekit-2.6.0a9 → telekit-2.6.1}/telekit/utils.py +0 -0
  90. {telekit-2.6.0a9 → telekit-2.6.1}/telekit.egg-info/SOURCES.txt +0 -0
  91. {telekit-2.6.0a9 → telekit-2.6.1}/telekit.egg-info/dependency_links.txt +0 -0
  92. {telekit-2.6.0a9 → telekit-2.6.1}/telekit.egg-info/requires.txt +0 -0
  93. {telekit-2.6.0a9 → telekit-2.6.1}/telekit.egg-info/top_level.txt +0 -0
@@ -1,3 +1,22 @@
1
+ ## File ID Caching, Rich HTML, New Timeout Engine
2
+
3
+ **Telekit 2.6** speeds up file sending, makes bots more resilient and adds Rich HTML messages. What's new:
4
+
5
+ 1. **File ID caching.** Local files are uploaded to Telegram once and reused on every next send.
6
+ 2. **Rich HTML messages** (Bot API 10.1+).
7
+ 3. **New timeout engine.** No more `can't start new thread` with ~1000 active chats (#6).
8
+ 4. **Smart restarts.** The new `restart` parameter (`"always"`, `"network"`, `"never"`) with exponential backoff keeps the server alive through network failures.
9
+ 5. **Keyboards in senders.** `set_keyboard()` and `to_markup()` let you attach keyboards to a plain `sender` without a chain.
10
+ 6. **Full `.env` support.** Comments, quotes, multi-line values and `$VAR` interpolation.
11
+ 7. **Better logging.** Rich output when `rich` is installed, bot tokens masked in logs, no duplicated records.
12
+ 8. **Handoff shortcuts.** `handle_handoff()` and `handle_handoff_back_or()` work without closures.
13
+
14
+ ### v2.6.1 – Fixes #7
15
+ - In groups, any chat member can now press the button (previously effectively broken for everyone).
16
+
17
+ ### v2.6.0
18
+ - Stable release. See the `a0`–`a9` entries below for the full list of changes.
19
+
1
20
  ### v2.6.0 `a9` – Keyboards in Senders
2
21
  - 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
22
  - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telekit
3
- Version: 2.6.0a9
3
+ Version: 2.6.1
4
4
  Summary: Declarative, developer-friendly framework for building Telegram bots
5
5
  Home-page: https://github.com/Romashkaa/telekit
6
6
  Author: romashka
@@ -134,41 +134,7 @@ def handle_name(self, name: str):
134
134
 
135
135
  ### Inline Keyboards
136
136
 
137
- The fastest way to add buttons to a message. Pass a `dict` where each key is the button label and each value is the callback to run when pressed:
138
-
139
- ```python
140
- self.chain.set_inline_keyboard(
141
- {
142
- "✏️ Change": self.change_name,
143
- "❌ Delete": self.delete,
144
- }
145
- )
146
- ```
147
-
148
- `row_width` controls how many buttons appear per row:
149
-
150
- ```python
151
- self.chain.set_inline_keyboard(
152
- {
153
- "One": self.one,
154
- "Two": self.two,
155
- "Three": self.three,
156
- "Four": self.four,
157
- "Five": self.five,
158
- },
159
- row_width=(3, 2) # first row: 3 buttons, second row: 2
160
- )
161
- ```
162
-
163
- ```
164
- ╭──────────┬──────────┬──────────╮
165
- │ One │ Two │ Three │
166
- ├──────────┴──┬───────┴──────────┤
167
- │ Four │ Five │
168
- ╰─────────────┴──────────────────╯
169
- ```
170
-
171
- For precise row layout or conditional buttons, use `InlineKeyboard`, a builder you compose step by step:
137
+ Build a keyboard with `InlineKeyboard`, a fluent builder you compose step by step, and attach it with `set_keyboard`. Each `add_callback` takes a button label and the callback to run when it is pressed. Call `.row()` to start a new row:
172
138
 
173
139
  ```python
174
140
  self.chain.set_keyboard(
@@ -190,6 +156,33 @@ self.chain.set_keyboard(
190
156
 
191
157
  > `InlineKeyboard` is built by chaining method calls. Just call `.row()` to start a new row.
192
158
 
159
+ **Grid layout**
160
+
161
+ Wrap buttons in `.grid(width=...)` / `.grid_end()` to split them into rows of a fixed width automatically:
162
+
163
+ ```python
164
+ self.chain.set_keyboard(
165
+ InlineKeyboard()
166
+ .grid(width=3)
167
+ .add_callback("One", self.one)
168
+ .add_callback("Two", self.two)
169
+ .add_callback("Three", self.three)
170
+ .add_callback("Four", self.four)
171
+ .add_callback("Five", self.five)
172
+ .grid_end()
173
+ )
174
+ ```
175
+
176
+ ```
177
+ ╭──────────┬──────────┬──────────╮
178
+ │ One │ Two │ Three │
179
+ ├──────────┴──┬───────┴──────────┤
180
+ │ Four │ Five │
181
+ ╰─────────────┴──────────────────╯
182
+ ```
183
+
184
+ Use `.column()` / `.column_end()` to put every button on its own row, and `.extend(...)` to add many buttons at once from a dict or list. Pass `when=...` to any method to add a button or row conditionally.
185
+
193
186
  **Not just callback buttons**
194
187
 
195
188
  | **Method** | **Description** |
@@ -269,14 +262,17 @@ class DialogueHandler(telekit.Handler):
269
262
 
270
263
  def handle_feeling(self, feeling: str) -> None:
271
264
  self.chain.sender.set_text(f"Got it, {self.user_name.title()}! You feel: {feeling}")
272
- self.chain.set_inline_keyboard({"↺ Restart": self.handle_hello})
265
+ self.chain.set_keyboard(
266
+ InlineKeyboard()
267
+ .add_callback("↺ Restart", self.handle_hello)
268
+ )
273
269
  self.chain.send()
274
270
  ```
275
271
 
276
272
  How it works:
277
273
 
278
274
  - The handler reacts to `"hello"`, `"hi"`, or `"hey"` in any case.
279
- - `handle_hello` asks for the user's name.ч
275
+ - `handle_hello` asks for the user's name.
280
276
  - `set_entry_suggestions` attaches the user's Telegram `first_name` as a suggestion button.
281
277
  - `handle_name` stores the name in `self.user_name`.
282
278
  - `handle_feeling` closes the flow and adds a "↺ Restart" button that routes back to the start.
@@ -480,6 +476,25 @@ Telekit focuses on one job: making Telegram bot development easier.
480
476
 
481
477
  # Changelog
482
478
 
479
+ ## File ID Caching, Rich HTML, New Timeout Engine
480
+
481
+ **Telekit 2.6** speeds up file sending, makes bots more resilient and adds Rich HTML messages. What's new:
482
+
483
+ 1. **File ID caching.** Local files are uploaded to Telegram once and reused on every next send.
484
+ 2. **Rich HTML messages** (Bot API 10.1+).
485
+ 3. **New timeout engine.** No more `can't start new thread` with ~1000 active chats (#6).
486
+ 4. **Smart restarts.** The new `restart` parameter (`"always"`, `"network"`, `"never"`) with exponential backoff keeps the server alive through network failures.
487
+ 5. **Keyboards in senders.** `set_keyboard()` and `to_markup()` let you attach keyboards to a plain `sender` without a chain.
488
+ 6. **Full `.env` support.** Comments, quotes, multi-line values and `$VAR` interpolation.
489
+ 7. **Better logging.** Rich output when `rich` is installed, bot tokens masked in logs, no duplicated records.
490
+ 8. **Handoff shortcuts.** `handle_handoff()` and `handle_handoff_back_or()` work without closures.
491
+
492
+ ### v2.6.1 – Fixes #7
493
+ - In groups, any chat member can now press the button (previously effectively broken for everyone).
494
+
495
+ ### v2.6.0
496
+ - Stable release. See the `a0`–`a9` entries below for the full list of changes.
497
+
483
498
  ### v2.6.0 `a9` – Keyboards in Senders
484
499
  - 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
500
  - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
@@ -97,41 +97,7 @@ def handle_name(self, name: str):
97
97
 
98
98
  ### Inline Keyboards
99
99
 
100
- The fastest way to add buttons to a message. Pass a `dict` where each key is the button label and each value is the callback to run when pressed:
101
-
102
- ```python
103
- self.chain.set_inline_keyboard(
104
- {
105
- "✏️ Change": self.change_name,
106
- "❌ Delete": self.delete,
107
- }
108
- )
109
- ```
110
-
111
- `row_width` controls how many buttons appear per row:
112
-
113
- ```python
114
- self.chain.set_inline_keyboard(
115
- {
116
- "One": self.one,
117
- "Two": self.two,
118
- "Three": self.three,
119
- "Four": self.four,
120
- "Five": self.five,
121
- },
122
- row_width=(3, 2) # first row: 3 buttons, second row: 2
123
- )
124
- ```
125
-
126
- ```
127
- ╭──────────┬──────────┬──────────╮
128
- │ One │ Two │ Three │
129
- ├──────────┴──┬───────┴──────────┤
130
- │ Four │ Five │
131
- ╰─────────────┴──────────────────╯
132
- ```
133
-
134
- For precise row layout or conditional buttons, use `InlineKeyboard`, a builder you compose step by step:
100
+ Build a keyboard with `InlineKeyboard`, a fluent builder you compose step by step, and attach it with `set_keyboard`. Each `add_callback` takes a button label and the callback to run when it is pressed. Call `.row()` to start a new row:
135
101
 
136
102
  ```python
137
103
  self.chain.set_keyboard(
@@ -153,6 +119,33 @@ self.chain.set_keyboard(
153
119
 
154
120
  > `InlineKeyboard` is built by chaining method calls. Just call `.row()` to start a new row.
155
121
 
122
+ **Grid layout**
123
+
124
+ Wrap buttons in `.grid(width=...)` / `.grid_end()` to split them into rows of a fixed width automatically:
125
+
126
+ ```python
127
+ self.chain.set_keyboard(
128
+ InlineKeyboard()
129
+ .grid(width=3)
130
+ .add_callback("One", self.one)
131
+ .add_callback("Two", self.two)
132
+ .add_callback("Three", self.three)
133
+ .add_callback("Four", self.four)
134
+ .add_callback("Five", self.five)
135
+ .grid_end()
136
+ )
137
+ ```
138
+
139
+ ```
140
+ ╭──────────┬──────────┬──────────╮
141
+ │ One │ Two │ Three │
142
+ ├──────────┴──┬───────┴──────────┤
143
+ │ Four │ Five │
144
+ ╰─────────────┴──────────────────╯
145
+ ```
146
+
147
+ Use `.column()` / `.column_end()` to put every button on its own row, and `.extend(...)` to add many buttons at once from a dict or list. Pass `when=...` to any method to add a button or row conditionally.
148
+
156
149
  **Not just callback buttons**
157
150
 
158
151
  | **Method** | **Description** |
@@ -232,14 +225,17 @@ class DialogueHandler(telekit.Handler):
232
225
 
233
226
  def handle_feeling(self, feeling: str) -> None:
234
227
  self.chain.sender.set_text(f"Got it, {self.user_name.title()}! You feel: {feeling}")
235
- self.chain.set_inline_keyboard({"↺ Restart": self.handle_hello})
228
+ self.chain.set_keyboard(
229
+ InlineKeyboard()
230
+ .add_callback("↺ Restart", self.handle_hello)
231
+ )
236
232
  self.chain.send()
237
233
  ```
238
234
 
239
235
  How it works:
240
236
 
241
237
  - The handler reacts to `"hello"`, `"hi"`, or `"hey"` in any case.
242
- - `handle_hello` asks for the user's name.ч
238
+ - `handle_hello` asks for the user's name.
243
239
  - `set_entry_suggestions` attaches the user's Telegram `first_name` as a suggestion button.
244
240
  - `handle_name` stores the name in `self.user_name`.
245
241
  - `handle_feeling` closes the flow and adds a "↺ Restart" button that routes back to the start.
@@ -2,4 +2,4 @@
2
2
  # PyPI history: https://pypi.org/project/telekit/#history
3
3
  # ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
4
4
 
5
- __version__ = "2.6.0a9"
5
+ __version__ = "2.6.1"
@@ -72,13 +72,28 @@ class CallbackQueryHandler:
72
72
  # Inline Buttons Handling
73
73
  # –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
74
74
 
75
+ @classmethod
76
+ def _get_chat_id(cls, call: CallbackQuery) -> int:
77
+ """
78
+ Returns the chat id the callbacks are registered under.
79
+
80
+ Falls back to the user id when the callback has no message
81
+ (e.g. inline-mode messages, where only inline_message_id is set).
82
+ """
83
+ message = call.message
84
+ if message is not None and getattr(message, "chat", None) is not None:
85
+ return message.chat.id
86
+ return call.from_user.id
87
+
75
88
  @classmethod
76
89
  def _handle_inline_button(cls, call: CallbackQuery):
77
90
  if not call.data:
78
91
  cls.bot.answer_callback_query(call.id, text=cls._invalid_data_answer[0], show_alert=cls._invalid_data_answer[1])
79
92
  return
80
-
81
- button_callbacks: dict[str, Callable] | None = cls.user_button_callbacks.get(call.from_user.id)
93
+
94
+ chat_id: int = cls._get_chat_id(call)
95
+
96
+ button_callbacks: dict[str, Callable] | None = cls.user_button_callbacks.get(chat_id)
82
97
 
83
98
  if not button_callbacks:
84
99
  cls.bot.answer_callback_query(call.id, text=cls._button_is_no_active_answer[0], show_alert=cls._button_is_no_active_answer[1])
@@ -91,7 +106,7 @@ class CallbackQueryHandler:
91
106
  return
92
107
 
93
108
  if not getattr(callback, "_persistent", False):
94
- cls.remove_user_button_callbacks(call.from_user.id)
109
+ cls.remove_user_button_callbacks(chat_id)
95
110
 
96
111
  callback(call)
97
112
 
@@ -50,7 +50,7 @@ class TelekitDSL:
50
50
  cls.analyze_file(path)
51
51
  cls.on.command(*on_commands).invoke(cls.start_script)
52
52
 
53
- class_name = f"_DLSFromPath_{id(path)}"
53
+ class_name = f"_DSLFromPath_{id(path)}"
54
54
  class_dict = {
55
55
  "init_handler": init_handler
56
56
  }
@@ -33,7 +33,7 @@ from telebot.types import (
33
33
  InputMediaPhoto, InputFile,
34
34
  InputMediaAudio, InputMediaDocument,
35
35
  InputMediaVideo, InputMediaAnimation,
36
- ReplyKeyboardMarkup
36
+ ReplyKeyboardMarkup, InlineKeyboardMarkup
37
37
  )
38
38
 
39
39
  from telekit.debug import Debug
@@ -167,7 +167,7 @@ class BaseSender:
167
167
  reply_markup = None,
168
168
 
169
169
  is_temporary: bool = False,
170
- delele_temporaries: bool = True,
170
+ delete_temporaries: bool = True,
171
171
 
172
172
  parse_mode: Literal["html", "markdown"] | ParseMode | None = "html",
173
173
  reply_to_message_id: int | None = None,
@@ -207,7 +207,7 @@ class BaseSender:
207
207
  self.reply_markup = reply_markup
208
208
 
209
209
  self.is_temporary = is_temporary
210
- self.delele_temporaries = delele_temporaries
210
+ self.delele_temporaries = delete_temporaries
211
211
 
212
212
  self.set_parse_mode(parse_mode)
213
213
  self.reply_to_message_id = reply_to_message_id
@@ -541,9 +541,30 @@ class BaseSender:
541
541
  """
542
542
  self.text = text
543
543
 
544
- def set_reply_markup(self, reply_markup):
544
+ def set_reply_markup(self, reply_markup: Union[ReplyKeyboardMarkup, InlineKeyboardMarkup]):
545
545
  """
546
- Sets Inline keyboards, reply keyboards, or other markup objects
546
+ Sets Inline keyboards, reply keyboards, or other markup objects as-is.
547
+
548
+ This is a low-level method: ``reply_markup`` is stored without any
549
+ conversion, so it must already be a compiled Telegram markup object
550
+ (e.g. ``InlineKeyboardMarkup`` or ``ReplyKeyboardMarkup``).
551
+
552
+ .. tip::
553
+ In most cases use :meth:`set_keyboard` instead. It accepts
554
+ :class:`InlineKeyboard` and :class:`ReplyKeyboard` builders directly
555
+ and compiles them for you.
556
+
557
+ If you do want to pass a builder here, compile it first with
558
+ ``to_markup()``::
559
+
560
+ keyboard = InlineKeyboard().add_link("Docs", "https://example.com")
561
+
562
+ sender.set_reply_markup(keyboard.to_markup())
563
+
564
+ # equivalent, and shorter:
565
+ sender.set_keyboard(keyboard)
566
+
567
+ :param reply_markup: A compiled markup object ready to be sent.
547
568
  """
548
569
  self.reply_markup = reply_markup
549
570
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telekit
3
- Version: 2.6.0a9
3
+ Version: 2.6.1
4
4
  Summary: Declarative, developer-friendly framework for building Telegram bots
5
5
  Home-page: https://github.com/Romashkaa/telekit
6
6
  Author: romashka
@@ -134,41 +134,7 @@ def handle_name(self, name: str):
134
134
 
135
135
  ### Inline Keyboards
136
136
 
137
- The fastest way to add buttons to a message. Pass a `dict` where each key is the button label and each value is the callback to run when pressed:
138
-
139
- ```python
140
- self.chain.set_inline_keyboard(
141
- {
142
- "✏️ Change": self.change_name,
143
- "❌ Delete": self.delete,
144
- }
145
- )
146
- ```
147
-
148
- `row_width` controls how many buttons appear per row:
149
-
150
- ```python
151
- self.chain.set_inline_keyboard(
152
- {
153
- "One": self.one,
154
- "Two": self.two,
155
- "Three": self.three,
156
- "Four": self.four,
157
- "Five": self.five,
158
- },
159
- row_width=(3, 2) # first row: 3 buttons, second row: 2
160
- )
161
- ```
162
-
163
- ```
164
- ╭──────────┬──────────┬──────────╮
165
- │ One │ Two │ Three │
166
- ├──────────┴──┬───────┴──────────┤
167
- │ Four │ Five │
168
- ╰─────────────┴──────────────────╯
169
- ```
170
-
171
- For precise row layout or conditional buttons, use `InlineKeyboard`, a builder you compose step by step:
137
+ Build a keyboard with `InlineKeyboard`, a fluent builder you compose step by step, and attach it with `set_keyboard`. Each `add_callback` takes a button label and the callback to run when it is pressed. Call `.row()` to start a new row:
172
138
 
173
139
  ```python
174
140
  self.chain.set_keyboard(
@@ -190,6 +156,33 @@ self.chain.set_keyboard(
190
156
 
191
157
  > `InlineKeyboard` is built by chaining method calls. Just call `.row()` to start a new row.
192
158
 
159
+ **Grid layout**
160
+
161
+ Wrap buttons in `.grid(width=...)` / `.grid_end()` to split them into rows of a fixed width automatically:
162
+
163
+ ```python
164
+ self.chain.set_keyboard(
165
+ InlineKeyboard()
166
+ .grid(width=3)
167
+ .add_callback("One", self.one)
168
+ .add_callback("Two", self.two)
169
+ .add_callback("Three", self.three)
170
+ .add_callback("Four", self.four)
171
+ .add_callback("Five", self.five)
172
+ .grid_end()
173
+ )
174
+ ```
175
+
176
+ ```
177
+ ╭──────────┬──────────┬──────────╮
178
+ │ One │ Two │ Three │
179
+ ├──────────┴──┬───────┴──────────┤
180
+ │ Four │ Five │
181
+ ╰─────────────┴──────────────────╯
182
+ ```
183
+
184
+ Use `.column()` / `.column_end()` to put every button on its own row, and `.extend(...)` to add many buttons at once from a dict or list. Pass `when=...` to any method to add a button or row conditionally.
185
+
193
186
  **Not just callback buttons**
194
187
 
195
188
  | **Method** | **Description** |
@@ -269,14 +262,17 @@ class DialogueHandler(telekit.Handler):
269
262
 
270
263
  def handle_feeling(self, feeling: str) -> None:
271
264
  self.chain.sender.set_text(f"Got it, {self.user_name.title()}! You feel: {feeling}")
272
- self.chain.set_inline_keyboard({"↺ Restart": self.handle_hello})
265
+ self.chain.set_keyboard(
266
+ InlineKeyboard()
267
+ .add_callback("↺ Restart", self.handle_hello)
268
+ )
273
269
  self.chain.send()
274
270
  ```
275
271
 
276
272
  How it works:
277
273
 
278
274
  - The handler reacts to `"hello"`, `"hi"`, or `"hey"` in any case.
279
- - `handle_hello` asks for the user's name.ч
275
+ - `handle_hello` asks for the user's name.
280
276
  - `set_entry_suggestions` attaches the user's Telegram `first_name` as a suggestion button.
281
277
  - `handle_name` stores the name in `self.user_name`.
282
278
  - `handle_feeling` closes the flow and adds a "↺ Restart" button that routes back to the start.
@@ -480,6 +476,25 @@ Telekit focuses on one job: making Telegram bot development easier.
480
476
 
481
477
  # Changelog
482
478
 
479
+ ## File ID Caching, Rich HTML, New Timeout Engine
480
+
481
+ **Telekit 2.6** speeds up file sending, makes bots more resilient and adds Rich HTML messages. What's new:
482
+
483
+ 1. **File ID caching.** Local files are uploaded to Telegram once and reused on every next send.
484
+ 2. **Rich HTML messages** (Bot API 10.1+).
485
+ 3. **New timeout engine.** No more `can't start new thread` with ~1000 active chats (#6).
486
+ 4. **Smart restarts.** The new `restart` parameter (`"always"`, `"network"`, `"never"`) with exponential backoff keeps the server alive through network failures.
487
+ 5. **Keyboards in senders.** `set_keyboard()` and `to_markup()` let you attach keyboards to a plain `sender` without a chain.
488
+ 6. **Full `.env` support.** Comments, quotes, multi-line values and `$VAR` interpolation.
489
+ 7. **Better logging.** Rich output when `rich` is installed, bot tokens masked in logs, no duplicated records.
490
+ 8. **Handoff shortcuts.** `handle_handoff()` and `handle_handoff_back_or()` work without closures.
491
+
492
+ ### v2.6.1 – Fixes #7
493
+ - In groups, any chat member can now press the button (previously effectively broken for everyone).
494
+
495
+ ### v2.6.0
496
+ - Stable release. See the `a0`–`a9` entries below for the full list of changes.
497
+
483
498
  ### v2.6.0 `a9` – Keyboards in Senders
484
499
  - 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
500
  - Added `ReplyKeyboard.to_markup()`: a public counterpart of the internal `_compile()` that returns a `ReplyKeyboardMarkup`
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
File without changes
File without changes