ng-bot-api 0.1.0__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 (204) hide show
  1. ng_bot_api-0.1.0/.gitignore +8 -0
  2. ng_bot_api-0.1.0/LICENSE +21 -0
  3. ng_bot_api-0.1.0/PKG-INFO +179 -0
  4. ng_bot_api-0.1.0/README.md +146 -0
  5. ng_bot_api-0.1.0/examples/echo_bot.py +23 -0
  6. ng_bot_api-0.1.0/examples/inline_keyboard.py +40 -0
  7. ng_bot_api-0.1.0/examples/sync_echo_bot.py +9 -0
  8. ng_bot_api-0.1.0/examples/webhook_bot.py +36 -0
  9. ng_bot_api-0.1.0/pyproject.toml +49 -0
  10. ng_bot_api-0.1.0/src/ng_bot_api/__init__.py +56 -0
  11. ng_bot_api-0.1.0/src/ng_bot_api/api_version.py +2 -0
  12. ng_bot_api-0.1.0/src/ng_bot_api/async_bot.py +97 -0
  13. ng_bot_api-0.1.0/src/ng_bot_api/core/__init__.py +31 -0
  14. ng_bot_api-0.1.0/src/ng_bot_api/core/base.py +36 -0
  15. ng_bot_api-0.1.0/src/ng_bot_api/core/caller.py +17 -0
  16. ng_bot_api-0.1.0/src/ng_bot_api/core/decoding.py +85 -0
  17. ng_bot_api-0.1.0/src/ng_bot_api/core/encoding.py +42 -0
  18. ng_bot_api-0.1.0/src/ng_bot_api/core/errors.py +75 -0
  19. ng_bot_api-0.1.0/src/ng_bot_api/core/input_file.py +56 -0
  20. ng_bot_api-0.1.0/src/ng_bot_api/core/polling.py +39 -0
  21. ng_bot_api-0.1.0/src/ng_bot_api/core/registry.py +72 -0
  22. ng_bot_api-0.1.0/src/ng_bot_api/core/request.py +67 -0
  23. ng_bot_api-0.1.0/src/ng_bot_api/core/typespec.py +57 -0
  24. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/__init__.py +17 -0
  25. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/dispatcher.py +95 -0
  26. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/filter_base.py +78 -0
  27. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/filters.py +124 -0
  28. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/handler.py +34 -0
  29. ng_bot_api-0.1.0/src/ng_bot_api/dispatcher/router.py +69 -0
  30. ng_bot_api-0.1.0/src/ng_bot_api/methods/__init__.py +115 -0
  31. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_01.py +99 -0
  32. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_02.py +114 -0
  33. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_03.py +85 -0
  34. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_04.py +110 -0
  35. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_05.py +114 -0
  36. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_06.py +74 -0
  37. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_07.py +114 -0
  38. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_08.py +106 -0
  39. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_09.py +97 -0
  40. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_10.py +92 -0
  41. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_11.py +107 -0
  42. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_12.py +119 -0
  43. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_13.py +119 -0
  44. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_14.py +113 -0
  45. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_15.py +117 -0
  46. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_16.py +115 -0
  47. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_17.py +121 -0
  48. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_18.py +118 -0
  49. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_19.py +128 -0
  50. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_20.py +115 -0
  51. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_21.py +127 -0
  52. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_22.py +110 -0
  53. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_23.py +116 -0
  54. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_24.py +118 -0
  55. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_25.py +109 -0
  56. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_26.py +124 -0
  57. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_27.py +119 -0
  58. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_28.py +119 -0
  59. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_29.py +108 -0
  60. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_30.py +115 -0
  61. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_31.py +112 -0
  62. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_32.py +126 -0
  63. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_33.py +105 -0
  64. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_34.py +117 -0
  65. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_35.py +122 -0
  66. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_36.py +121 -0
  67. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_37.py +126 -0
  68. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_38.py +112 -0
  69. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_39.py +84 -0
  70. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_40.py +125 -0
  71. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_41.py +115 -0
  72. ng_bot_api-0.1.0/src/ng_bot_api/methods/async_42.py +30 -0
  73. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_01.py +99 -0
  74. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_02.py +114 -0
  75. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_03.py +85 -0
  76. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_04.py +110 -0
  77. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_05.py +114 -0
  78. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_06.py +74 -0
  79. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_07.py +114 -0
  80. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_08.py +106 -0
  81. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_09.py +97 -0
  82. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_10.py +92 -0
  83. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_11.py +107 -0
  84. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_12.py +119 -0
  85. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_13.py +119 -0
  86. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_14.py +113 -0
  87. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_15.py +117 -0
  88. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_16.py +115 -0
  89. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_17.py +121 -0
  90. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_18.py +118 -0
  91. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_19.py +128 -0
  92. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_20.py +115 -0
  93. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_21.py +127 -0
  94. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_22.py +110 -0
  95. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_23.py +116 -0
  96. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_24.py +118 -0
  97. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_25.py +109 -0
  98. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_26.py +124 -0
  99. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_27.py +119 -0
  100. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_28.py +119 -0
  101. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_29.py +108 -0
  102. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_30.py +115 -0
  103. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_31.py +112 -0
  104. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_32.py +126 -0
  105. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_33.py +105 -0
  106. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_34.py +117 -0
  107. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_35.py +122 -0
  108. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_36.py +121 -0
  109. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_37.py +126 -0
  110. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_38.py +112 -0
  111. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_39.py +84 -0
  112. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_40.py +125 -0
  113. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_41.py +115 -0
  114. ng_bot_api-0.1.0/src/ng_bot_api/methods/sync_42.py +30 -0
  115. ng_bot_api-0.1.0/src/ng_bot_api/py.typed +0 -0
  116. ng_bot_api-0.1.0/src/ng_bot_api/sync_bot.py +95 -0
  117. ng_bot_api-0.1.0/src/ng_bot_api/types/__init__.py +82 -0
  118. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_01.py +102 -0
  119. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_02.py +141 -0
  120. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_03.py +311 -0
  121. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_04.py +84 -0
  122. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_05.py +134 -0
  123. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_06.py +126 -0
  124. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_07.py +119 -0
  125. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_08.py +120 -0
  126. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_09.py +115 -0
  127. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_10.py +109 -0
  128. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_11.py +121 -0
  129. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_12.py +120 -0
  130. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_13.py +128 -0
  131. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_14.py +124 -0
  132. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_15.py +129 -0
  133. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_16.py +121 -0
  134. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_17.py +124 -0
  135. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_18.py +128 -0
  136. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_19.py +115 -0
  137. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_20.py +123 -0
  138. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_21.py +101 -0
  139. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_22.py +121 -0
  140. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_23.py +128 -0
  141. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_24.py +107 -0
  142. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_25.py +100 -0
  143. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_26.py +81 -0
  144. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_27.py +114 -0
  145. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_28.py +125 -0
  146. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_29.py +118 -0
  147. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_30.py +113 -0
  148. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_31.py +120 -0
  149. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_32.py +124 -0
  150. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_33.py +125 -0
  151. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_34.py +113 -0
  152. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_35.py +125 -0
  153. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_36.py +119 -0
  154. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_37.py +126 -0
  155. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_38.py +118 -0
  156. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_39.py +121 -0
  157. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_40.py +121 -0
  158. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_41.py +116 -0
  159. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_42.py +112 -0
  160. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_43.py +110 -0
  161. ng_bot_api-0.1.0/src/ng_bot_api/types/available_types_44.py +30 -0
  162. ng_bot_api-0.1.0/src/ng_bot_api/types/games_01.py +57 -0
  163. ng_bot_api-0.1.0/src/ng_bot_api/types/getting_updates_01.py +123 -0
  164. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_01.py +124 -0
  165. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_02.py +91 -0
  166. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_03.py +116 -0
  167. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_04.py +126 -0
  168. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_05.py +124 -0
  169. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_06.py +124 -0
  170. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_07.py +119 -0
  171. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_08.py +104 -0
  172. ng_bot_api-0.1.0/src/ng_bot_api/types/inline_mode_09.py +84 -0
  173. ng_bot_api-0.1.0/src/ng_bot_api/types/payments_01.py +124 -0
  174. ng_bot_api-0.1.0/src/ng_bot_api/types/payments_02.py +124 -0
  175. ng_bot_api-0.1.0/src/ng_bot_api/types/payments_03.py +119 -0
  176. ng_bot_api-0.1.0/src/ng_bot_api/types/payments_04.py +70 -0
  177. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_01.py +126 -0
  178. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_02.py +125 -0
  179. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_03.py +115 -0
  180. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_04.py +116 -0
  181. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_05.py +128 -0
  182. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_06.py +125 -0
  183. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_07.py +114 -0
  184. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_08.py +118 -0
  185. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_09.py +124 -0
  186. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_10.py +125 -0
  187. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_11.py +122 -0
  188. ng_bot_api-0.1.0/src/ng_bot_api/types/rich_messages_12.py +122 -0
  189. ng_bot_api-0.1.0/src/ng_bot_api/types/stickers_01.py +107 -0
  190. ng_bot_api-0.1.0/src/ng_bot_api/types/telegram_passport_01.py +120 -0
  191. ng_bot_api-0.1.0/src/ng_bot_api/types/telegram_passport_02.py +113 -0
  192. ng_bot_api-0.1.0/src/ng_bot_api/types/telegram_passport_03.py +24 -0
  193. ng_bot_api-0.1.0/src/ng_bot_api/types/unions_01.py +140 -0
  194. ng_bot_api-0.1.0/src/ng_bot_api/types/unions_02.py +132 -0
  195. ng_bot_api-0.1.0/src/ng_bot_api/types/unions_03.py +134 -0
  196. ng_bot_api-0.1.0/src/ng_bot_api/types/unions_04.py +149 -0
  197. ng_bot_api-0.1.0/src/ng_bot_api/types/unions_05.py +96 -0
  198. ng_bot_api-0.1.0/src/ng_bot_api/webhook.py +78 -0
  199. ng_bot_api-0.1.0/tests/conftest.py +70 -0
  200. ng_bot_api-0.1.0/tests/test_dispatcher_webhook.py +92 -0
  201. ng_bot_api-0.1.0/tests/test_polling_files.py +80 -0
  202. ng_bot_api-0.1.0/tests/test_requests.py +73 -0
  203. ng_bot_api-0.1.0/tests/test_unions.py +75 -0
  204. ng_bot_api-0.1.0/tests/test_upload.py +69 -0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NetGram
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.5
2
+ Name: ng-bot-api
3
+ Version: 0.1.0
4
+ Summary: Official typed Python client for the NetGram Bot API (Telegram Bot API compatible): sync + asyncio, long polling, webhooks, dispatcher
5
+ Project-URL: Homepage, https://netgram.su
6
+ Project-URL: Documentation, https://netgram.su
7
+ Project-URL: Repository, https://github.com/NetGram-su/ng-bot-api
8
+ Author: NetGram
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: asyncio,bot,bot-api,netgram,telegram
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Communications :: Chat
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: httpx<1,>=0.25
27
+ Provides-Extra: aiohttp
28
+ Requires-Dist: aiohttp>=3.9; extra == 'aiohttp'
29
+ Provides-Extra: dev
30
+ Requires-Dist: mypy>=1.10; extra == 'dev'
31
+ Requires-Dist: pytest>=8; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # ng-bot-api
35
+
36
+ Official typed Python client for the **NetGram Bot API** — a 1:1 implementation of the
37
+ [Telegram Bot API](https://core.telegram.org/bots/api) (currently **Bot API 10.5**, 194 methods, 426 types).
38
+
39
+ - sync (`Bot`) and asyncio (`AsyncBot`) clients on top of [httpx](https://www.python-httpx.org/)
40
+ - every method and type generated from the official spec, with docstrings and type hints (`py.typed`)
41
+ - file uploads (`InputFile`, automatic `attach://` for media groups), file downloads
42
+ - long polling, framework-agnostic webhook handler (ASGI app / aiohttp handler)
43
+ - small dispatcher with routers and filters (`Command`, `CallbackData`, `Text`, `Regexp`, `ChatType`)
44
+ - typed errors (`TooManyRequestsError.retry_after`, `ForbiddenError`, ...)
45
+ - default server `https://api.netgram.su`, any Bot API compatible server can be used via `api_url`
46
+
47
+ [Русская версия ниже](#ng-bot-api-ru)
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install ng-bot-api # import name: ng_bot_api
53
+ pip install "ng-bot-api[aiohttp]" # + aiohttp for the webhook example
54
+ ```
55
+
56
+ ## Quick start
57
+
58
+ ```python
59
+ import os
60
+ from ng_bot_api import AsyncBot, Command, Dispatcher
61
+ from ng_bot_api.types import Message
62
+
63
+ dp = Dispatcher()
64
+
65
+ @dp.message(Command("start"))
66
+ async def start(message: Message, bot: AsyncBot, command):
67
+ await bot.send_message(message.chat.id, "Hello! Payload: " + str(command.args))
68
+
69
+ @dp.message()
70
+ async def echo(message: Message, bot: AsyncBot):
71
+ await bot.send_message(message.chat.id, message.text or "?")
72
+
73
+ dp.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
74
+ ```
75
+
76
+ Synchronous client:
77
+
78
+ ```python
79
+ from ng_bot_api import Bot, InputFile
80
+
81
+ with Bot(token) as bot:
82
+ bot.send_photo(chat_id, InputFile.from_path("cat.jpg"), caption="Cat")
83
+ for update in bot.iter_updates():
84
+ ...
85
+ ```
86
+
87
+ Handlers receive the event first and can declare `bot`, `update`, `event_type` and names injected by
88
+ filters: `command` (`Command`), `callback_args` (`CallbackData`), `match` (`Regexp`).
89
+ Filters combine with `&`, `|`, `~`; any callable `event -> bool` works as a filter.
90
+
91
+ ## Keyboards and callbacks
92
+
93
+ ```python
94
+ from ng_bot_api import CallbackData
95
+ from ng_bot_api.types import InlineKeyboardButton, InlineKeyboardMarkup
96
+
97
+ markup = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text="Buy", callback_data="buy:42")]])
98
+ await bot.send_message(chat_id, "Shop", reply_markup=markup)
99
+
100
+ @dp.callback_query(CallbackData("buy"))
101
+ async def buy(query, bot, callback_args):
102
+ await bot.answer_callback_query(query.id, text="Item " + callback_args[0])
103
+ ```
104
+
105
+ ## Webhook
106
+
107
+ ```python
108
+ from ng_bot_api import WebhookHandler
109
+
110
+ handler = WebhookHandler(dp.webhook_callback(bot), secret_token="random-secret")
111
+ app = handler.asgi_app("/webhook") # run with uvicorn / hypercorn
112
+ aiohttp_view = handler.aiohttp_handler() # or app.router.add_post("/webhook", aiohttp_view)
113
+ await bot.set_webhook("https://example.com/webhook", secret_token="random-secret")
114
+ ```
115
+
116
+ `WebhookHandler.handle(body, headers)` returns `(status, body)` and can be wired into any framework.
117
+
118
+ ## Custom server
119
+
120
+ ```python
121
+ bot = AsyncBot(token, api_url="https://api.telegram.org") # works with Telegram too
122
+ ```
123
+
124
+ ## Errors
125
+
126
+ ```python
127
+ from ng_bot_api import BotApiError, TooManyRequestsError
128
+
129
+ try:
130
+ await bot.send_message(chat_id, "hi")
131
+ except TooManyRequestsError as error:
132
+ await asyncio.sleep(error.retry_after)
133
+ except BotApiError as error:
134
+ print(error.error_code, error.description)
135
+ ```
136
+
137
+ Field `from` is exposed as `from_user`. Objects convert with `to_dict()` / `from_dict()`.
138
+ Examples: [`examples/`](examples). License: MIT.
139
+
140
+ ---
141
+
142
+ <a id="ng-bot-api-ru"></a>
143
+ # ng-bot-api (RU)
144
+
145
+ Официальная типизированная Python-библиотека для **NetGram Bot API** — полной копии
146
+ [Telegram Bot API](https://core.telegram.org/bots/api) (сейчас **Bot API 10.5**: 194 метода, 426 типов).
147
+
148
+ - синхронный `Bot` и асинхронный `AsyncBot` (httpx);
149
+ - все методы и типы сгенерированы из официальной спецификации, с подсказками типов и докстрингами;
150
+ - загрузка файлов (`InputFile`, автоматический `attach://` для альбомов) и скачивание (`download_file`);
151
+ - long polling (`iter_updates`, `Dispatcher.run_polling`) и вебхуки (`WebhookHandler`: ASGI или aiohttp);
152
+ - диспетчер с роутерами и фильтрами `Command`, `CallbackData`, `Text`, `Regexp`, `ChatType`;
153
+ - типизированные ошибки: `TooManyRequestsError.retry_after`, `ForbiddenError` и т.д.;
154
+ - сервер по умолчанию `https://api.netgram.su`, другой задаётся через `api_url`.
155
+
156
+ ## Установка
157
+
158
+ ```bash
159
+ pip install ng-bot-api
160
+ ```
161
+
162
+ ## Пример: эхо-бот
163
+
164
+ ```python
165
+ import os
166
+ from ng_bot_api import AsyncBot, Dispatcher
167
+
168
+ dp = Dispatcher()
169
+
170
+ @dp.message()
171
+ async def echo(message, bot):
172
+ await bot.send_message(message.chat.id, message.text or "?")
173
+
174
+ dp.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
175
+ ```
176
+
177
+ Токен бота выдаёт системный бот NetGram для создания ботов. Для работы с Telegram передайте
178
+ `api_url="https://api.telegram.org"`. Полные примеры — в папке [`examples/`](examples):
179
+ эхо-бот, inline-клавиатура с callback-кнопками, вебхук на aiohttp. Лицензия MIT.
@@ -0,0 +1,146 @@
1
+ # ng-bot-api
2
+
3
+ Official typed Python client for the **NetGram Bot API** — a 1:1 implementation of the
4
+ [Telegram Bot API](https://core.telegram.org/bots/api) (currently **Bot API 10.5**, 194 methods, 426 types).
5
+
6
+ - sync (`Bot`) and asyncio (`AsyncBot`) clients on top of [httpx](https://www.python-httpx.org/)
7
+ - every method and type generated from the official spec, with docstrings and type hints (`py.typed`)
8
+ - file uploads (`InputFile`, automatic `attach://` for media groups), file downloads
9
+ - long polling, framework-agnostic webhook handler (ASGI app / aiohttp handler)
10
+ - small dispatcher with routers and filters (`Command`, `CallbackData`, `Text`, `Regexp`, `ChatType`)
11
+ - typed errors (`TooManyRequestsError.retry_after`, `ForbiddenError`, ...)
12
+ - default server `https://api.netgram.su`, any Bot API compatible server can be used via `api_url`
13
+
14
+ [Русская версия ниже](#ng-bot-api-ru)
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install ng-bot-api # import name: ng_bot_api
20
+ pip install "ng-bot-api[aiohttp]" # + aiohttp for the webhook example
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ ```python
26
+ import os
27
+ from ng_bot_api import AsyncBot, Command, Dispatcher
28
+ from ng_bot_api.types import Message
29
+
30
+ dp = Dispatcher()
31
+
32
+ @dp.message(Command("start"))
33
+ async def start(message: Message, bot: AsyncBot, command):
34
+ await bot.send_message(message.chat.id, "Hello! Payload: " + str(command.args))
35
+
36
+ @dp.message()
37
+ async def echo(message: Message, bot: AsyncBot):
38
+ await bot.send_message(message.chat.id, message.text or "?")
39
+
40
+ dp.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
41
+ ```
42
+
43
+ Synchronous client:
44
+
45
+ ```python
46
+ from ng_bot_api import Bot, InputFile
47
+
48
+ with Bot(token) as bot:
49
+ bot.send_photo(chat_id, InputFile.from_path("cat.jpg"), caption="Cat")
50
+ for update in bot.iter_updates():
51
+ ...
52
+ ```
53
+
54
+ Handlers receive the event first and can declare `bot`, `update`, `event_type` and names injected by
55
+ filters: `command` (`Command`), `callback_args` (`CallbackData`), `match` (`Regexp`).
56
+ Filters combine with `&`, `|`, `~`; any callable `event -> bool` works as a filter.
57
+
58
+ ## Keyboards and callbacks
59
+
60
+ ```python
61
+ from ng_bot_api import CallbackData
62
+ from ng_bot_api.types import InlineKeyboardButton, InlineKeyboardMarkup
63
+
64
+ markup = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text="Buy", callback_data="buy:42")]])
65
+ await bot.send_message(chat_id, "Shop", reply_markup=markup)
66
+
67
+ @dp.callback_query(CallbackData("buy"))
68
+ async def buy(query, bot, callback_args):
69
+ await bot.answer_callback_query(query.id, text="Item " + callback_args[0])
70
+ ```
71
+
72
+ ## Webhook
73
+
74
+ ```python
75
+ from ng_bot_api import WebhookHandler
76
+
77
+ handler = WebhookHandler(dp.webhook_callback(bot), secret_token="random-secret")
78
+ app = handler.asgi_app("/webhook") # run with uvicorn / hypercorn
79
+ aiohttp_view = handler.aiohttp_handler() # or app.router.add_post("/webhook", aiohttp_view)
80
+ await bot.set_webhook("https://example.com/webhook", secret_token="random-secret")
81
+ ```
82
+
83
+ `WebhookHandler.handle(body, headers)` returns `(status, body)` and can be wired into any framework.
84
+
85
+ ## Custom server
86
+
87
+ ```python
88
+ bot = AsyncBot(token, api_url="https://api.telegram.org") # works with Telegram too
89
+ ```
90
+
91
+ ## Errors
92
+
93
+ ```python
94
+ from ng_bot_api import BotApiError, TooManyRequestsError
95
+
96
+ try:
97
+ await bot.send_message(chat_id, "hi")
98
+ except TooManyRequestsError as error:
99
+ await asyncio.sleep(error.retry_after)
100
+ except BotApiError as error:
101
+ print(error.error_code, error.description)
102
+ ```
103
+
104
+ Field `from` is exposed as `from_user`. Objects convert with `to_dict()` / `from_dict()`.
105
+ Examples: [`examples/`](examples). License: MIT.
106
+
107
+ ---
108
+
109
+ <a id="ng-bot-api-ru"></a>
110
+ # ng-bot-api (RU)
111
+
112
+ Официальная типизированная Python-библиотека для **NetGram Bot API** — полной копии
113
+ [Telegram Bot API](https://core.telegram.org/bots/api) (сейчас **Bot API 10.5**: 194 метода, 426 типов).
114
+
115
+ - синхронный `Bot` и асинхронный `AsyncBot` (httpx);
116
+ - все методы и типы сгенерированы из официальной спецификации, с подсказками типов и докстрингами;
117
+ - загрузка файлов (`InputFile`, автоматический `attach://` для альбомов) и скачивание (`download_file`);
118
+ - long polling (`iter_updates`, `Dispatcher.run_polling`) и вебхуки (`WebhookHandler`: ASGI или aiohttp);
119
+ - диспетчер с роутерами и фильтрами `Command`, `CallbackData`, `Text`, `Regexp`, `ChatType`;
120
+ - типизированные ошибки: `TooManyRequestsError.retry_after`, `ForbiddenError` и т.д.;
121
+ - сервер по умолчанию `https://api.netgram.su`, другой задаётся через `api_url`.
122
+
123
+ ## Установка
124
+
125
+ ```bash
126
+ pip install ng-bot-api
127
+ ```
128
+
129
+ ## Пример: эхо-бот
130
+
131
+ ```python
132
+ import os
133
+ from ng_bot_api import AsyncBot, Dispatcher
134
+
135
+ dp = Dispatcher()
136
+
137
+ @dp.message()
138
+ async def echo(message, bot):
139
+ await bot.send_message(message.chat.id, message.text or "?")
140
+
141
+ dp.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
142
+ ```
143
+
144
+ Токен бота выдаёт системный бот NetGram для создания ботов. Для работы с Telegram передайте
145
+ `api_url="https://api.telegram.org"`. Полные примеры — в папке [`examples/`](examples):
146
+ эхо-бот, inline-клавиатура с callback-кнопками, вебхук на aiohttp. Лицензия MIT.
@@ -0,0 +1,23 @@
1
+ import os
2
+
3
+ from ng_bot_api import AsyncBot, Command, Dispatcher
4
+ from ng_bot_api.types import Message
5
+
6
+ dispatcher = Dispatcher()
7
+
8
+
9
+ @dispatcher.message(Command("start"))
10
+ async def start(message: Message, bot: AsyncBot) -> None:
11
+ await bot.send_message(message.chat.id, "Hi! Send me any text and I will repeat it.")
12
+
13
+
14
+ @dispatcher.message()
15
+ async def echo(message: Message, bot: AsyncBot) -> None:
16
+ if message.text:
17
+ await bot.send_message(message.chat.id, message.text)
18
+ else:
19
+ await bot.copy_message(message.chat.id, message.chat.id, message.message_id)
20
+
21
+
22
+ if __name__ == "__main__":
23
+ dispatcher.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
@@ -0,0 +1,40 @@
1
+ import os
2
+
3
+ from ng_bot_api import AsyncBot, CallbackData, Command, Dispatcher
4
+ from ng_bot_api.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message
5
+
6
+ dispatcher = Dispatcher()
7
+
8
+
9
+ def counter_keyboard(value: int) -> InlineKeyboardMarkup:
10
+ return InlineKeyboardMarkup(
11
+ inline_keyboard=[
12
+ [
13
+ InlineKeyboardButton(text="-1", callback_data="count:" + str(value - 1)),
14
+ InlineKeyboardButton(text="+1", callback_data="count:" + str(value + 1)),
15
+ ],
16
+ [InlineKeyboardButton(text="NetGram", url="https://netgram.su")],
17
+ ]
18
+ )
19
+
20
+
21
+ @dispatcher.message(Command("start", "counter"))
22
+ async def start(message: Message, bot: AsyncBot) -> None:
23
+ await bot.send_message(message.chat.id, "Counter: 0", reply_markup=counter_keyboard(0))
24
+
25
+
26
+ @dispatcher.callback_query(CallbackData("count"))
27
+ async def count(query: CallbackQuery, bot: AsyncBot, callback_args: list[str]) -> None:
28
+ value = int(callback_args[0])
29
+ if query.message is not None:
30
+ await bot.edit_message_text(
31
+ text="Counter: " + str(value),
32
+ chat_id=query.message.chat.id,
33
+ message_id=query.message.message_id,
34
+ reply_markup=counter_keyboard(value),
35
+ )
36
+ await bot.answer_callback_query(query.id, text=str(value))
37
+
38
+
39
+ if __name__ == "__main__":
40
+ dispatcher.run_polling(AsyncBot(os.environ["BOT_TOKEN"]))
@@ -0,0 +1,9 @@
1
+ import os
2
+
3
+ from ng_bot_api import Bot
4
+
5
+ with Bot(os.environ["BOT_TOKEN"]) as bot:
6
+ print("Running as @" + str(bot.get_me().username))
7
+ for update in bot.iter_updates(allowed_updates=["message"]):
8
+ if update.message and update.message.text:
9
+ bot.send_message(update.message.chat.id, update.message.text)
@@ -0,0 +1,36 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from aiohttp import web
5
+
6
+ from ng_bot_api import AsyncBot, Dispatcher, WebhookHandler
7
+ from ng_bot_api.types import Message
8
+
9
+ dispatcher = Dispatcher()
10
+
11
+
12
+ @dispatcher.message()
13
+ async def echo(message: Message, bot: AsyncBot) -> None:
14
+ await bot.send_message(message.chat.id, message.text or "?")
15
+
16
+
17
+ async def main() -> None:
18
+ bot = AsyncBot(os.environ["BOT_TOKEN"])
19
+ secret = os.environ["WEBHOOK_SECRET"]
20
+ handler = WebhookHandler(dispatcher.webhook_callback(bot), secret_token=secret)
21
+ app = web.Application()
22
+ app.router.add_post("/webhook", handler.aiohttp_handler())
23
+ runner = web.AppRunner(app)
24
+ await runner.setup()
25
+ await web.TCPSite(runner, "0.0.0.0", int(os.environ.get("PORT", "8080"))).start()
26
+ await bot.set_webhook(os.environ["WEBHOOK_URL"], secret_token=secret)
27
+ try:
28
+ await asyncio.Event().wait()
29
+ finally:
30
+ await bot.delete_webhook()
31
+ await bot.shutdown()
32
+ await runner.cleanup()
33
+
34
+
35
+ if __name__ == "__main__":
36
+ asyncio.run(main())
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "ng-bot-api"
7
+ version = "0.1.0"
8
+ description = "Official typed Python client for the NetGram Bot API (Telegram Bot API compatible): sync + asyncio, long polling, webhooks, dispatcher"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "NetGram" }]
14
+ keywords = ["netgram", "telegram", "bot", "bot-api", "asyncio"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Framework :: AsyncIO",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Communications :: Chat",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ "Typing :: Typed",
29
+ ]
30
+ dependencies = ["httpx>=0.25,<1"]
31
+
32
+ [project.optional-dependencies]
33
+ aiohttp = ["aiohttp>=3.9"]
34
+ dev = ["pytest>=8", "mypy>=1.10"]
35
+
36
+ [project.urls]
37
+ Homepage = "https://netgram.su"
38
+ Documentation = "https://netgram.su"
39
+ Repository = "https://github.com/NetGram-su/ng-bot-api"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["src/ng_bot_api"]
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ include = ["src/ng_bot_api", "tests", "examples", "README.md", "LICENSE", "pyproject.toml"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+ pythonpath = ["src", "tests"]
@@ -0,0 +1,56 @@
1
+ """Official Python client for the NetGram Bot API (a 1:1 Telegram Bot API implementation)."""
2
+
3
+ from . import types
4
+ from .api_version import api_release_date, api_version
5
+ from .async_bot import AsyncBot
6
+ from .core import (
7
+ BadRequestError,
8
+ BotApiError,
9
+ BotObject,
10
+ ConflictError,
11
+ ForbiddenError,
12
+ InputFile,
13
+ NetworkError,
14
+ NgBotApiError,
15
+ NotFoundError,
16
+ ServerError,
17
+ TooManyRequestsError,
18
+ UnauthorizedError,
19
+ defaultApiUrl,
20
+ )
21
+ from .dispatcher import CallbackData, ChatType, Command, CommandObject, Dispatcher, Filter, Regexp, Router, Text
22
+ from .sync_bot import Bot
23
+ from .webhook import WebhookHandler
24
+
25
+ __version__ = "0.1.0"
26
+
27
+ __all__ = [
28
+ "AsyncBot",
29
+ "BadRequestError",
30
+ "Bot",
31
+ "BotApiError",
32
+ "BotObject",
33
+ "CallbackData",
34
+ "ChatType",
35
+ "Command",
36
+ "CommandObject",
37
+ "ConflictError",
38
+ "Dispatcher",
39
+ "Filter",
40
+ "ForbiddenError",
41
+ "InputFile",
42
+ "NetworkError",
43
+ "NgBotApiError",
44
+ "NotFoundError",
45
+ "Regexp",
46
+ "Router",
47
+ "ServerError",
48
+ "Text",
49
+ "TooManyRequestsError",
50
+ "UnauthorizedError",
51
+ "WebhookHandler",
52
+ "api_release_date",
53
+ "api_version",
54
+ "defaultApiUrl",
55
+ "types",
56
+ ]
@@ -0,0 +1,2 @@
1
+ api_version = '10.5'
2
+ api_release_date = 'November 22, 2026'
@@ -0,0 +1,97 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import os
5
+ import pathlib
6
+ from typing import Any, AsyncIterator, Sequence
7
+
8
+ import httpx
9
+
10
+ from .core.errors import NetworkError
11
+ from .core.polling import PollingState
12
+ from .core.request import defaultApiUrl, file_url, method_url, parse_response, prepare
13
+ from .methods import AsyncMethods
14
+ from .types import File, Update
15
+
16
+
17
+ class AsyncBot(AsyncMethods):
18
+ """Asynchronous (asyncio) Bot API client.
19
+
20
+ Use as ``async with AsyncBot(token) as bot: ...``. The default server is
21
+ ``https://api.netgram.su``; pass ``api_url`` to use another Bot API compatible server.
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ token: str,
27
+ *,
28
+ api_url: str = defaultApiUrl,
29
+ timeout: float = 30.0,
30
+ client: httpx.AsyncClient | None = None,
31
+ ) -> None:
32
+ self.token = token
33
+ self.api_url = api_url
34
+ self.timeout = timeout
35
+ self._owns_client = client is None
36
+ self._client = client or httpx.AsyncClient(timeout=timeout)
37
+
38
+ async def _call(self, method: str, params: dict[str, Any], returns: str) -> Any:
39
+ prepared = prepare(method, params)
40
+ timeout = self.timeout + prepared.poll_timeout if prepared.poll_timeout else self.timeout
41
+ try:
42
+ url = method_url(self.api_url, self.token, method)
43
+ response = await self._client.post(url, timeout=timeout, **prepared.httpx_arguments())
44
+ payload = response.json()
45
+ except httpx.HTTPError as error:
46
+ raise NetworkError(str(error)) from error
47
+ except ValueError as error:
48
+ raise NetworkError("Invalid JSON in response: " + str(error)) from error
49
+ return parse_response(method, response.status_code, payload, returns)
50
+
51
+ def file_url(self, file: File | str) -> str:
52
+ """Return the download URL of a file obtained with ``get_file``."""
53
+ path = file.file_path if isinstance(file, File) else file
54
+ if not path:
55
+ raise ValueError("The file has no file_path, call get_file first")
56
+ return file_url(self.api_url, self.token, path)
57
+
58
+ async def download_file(self, file: File | str, destination: str | os.PathLike[str] | None = None) -> bytes:
59
+ """Download a file by ``File`` object or ``file_path``; optionally save it to ``destination``."""
60
+ try:
61
+ response = await self._client.get(self.file_url(file), timeout=self.timeout)
62
+ response.raise_for_status()
63
+ except httpx.HTTPError as error:
64
+ raise NetworkError(str(error)) from error
65
+ if destination is not None:
66
+ pathlib.Path(destination).write_bytes(response.content)
67
+ return response.content
68
+
69
+ async def iter_updates(
70
+ self,
71
+ *,
72
+ timeout: int = 30,
73
+ limit: int | None = None,
74
+ allowed_updates: Sequence[str] | None = None,
75
+ offset: int | None = None,
76
+ ) -> AsyncIterator[Update]:
77
+ """Yield incoming updates forever using long polling (``getUpdates``)."""
78
+ state = PollingState(timeout=timeout, limit=limit, allowed_updates=allowed_updates, offset=offset)
79
+ while True:
80
+ try:
81
+ updates = state.accept(await self.get_updates(**state.request()))
82
+ except Exception as error:
83
+ await asyncio.sleep(state.delay_after(error))
84
+ continue
85
+ for update in updates:
86
+ yield update
87
+
88
+ async def shutdown(self) -> None:
89
+ """Close the underlying HTTP client (does not call the ``close`` Bot API method)."""
90
+ if self._owns_client:
91
+ await self._client.aclose()
92
+
93
+ async def __aenter__(self) -> AsyncBot:
94
+ return self
95
+
96
+ async def __aexit__(self, *exc_info: object) -> None:
97
+ await self.shutdown()