grammy 1.4.2 β 1.5.2
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.
- package/README.md +27 -16
- package/out/context.d.ts +21 -3
- package/out/context.js +28 -6
- package/out/convenience/frameworks.node.d.ts +39 -0
- package/out/convenience/frameworks.node.js +64 -0
- package/out/convenience/keyboard.d.ts +2 -2
- package/out/convenience/keyboard.js +2 -2
- package/out/convenience/session.d.ts +2 -2
- package/out/convenience/webhook.d.ts +73 -2
- package/out/convenience/webhook.js +18 -63
- package/out/core/api.d.ts +20 -0
- package/out/core/api.js +43 -109
- package/out/core/client.js +9 -6
- package/out/core/payload.js +5 -9
- package/out/filter.d.ts +7 -3
- package/out/filter.js +2 -1
- package/out/platform.node.d.ts +16 -8
- package/out/platform.node.js +49 -23
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
_<h2 align="center"> [:mag: Documentation](https://grammy.dev) | [:page_with_curl: API Reference](https://doc.deno.land/https
|
|
7
|
+
_<h2 align="center"> [:mag: Documentation](https://grammy.dev) | [:page_with_curl: API Reference](https://doc.deno.land/https://deno.land/x/grammy/mod.ts) | [:busts_in_silhouette: Group Chat](https://telegram.me/grammyjs) | [:new: News](https://telegram.me/grammyjs_news)</h2>_
|
|
8
8
|
|
|
9
9
|
<div align="center">
|
|
10
10
|
|
|
11
11
|
<!-- deno-fmt-ignore-start -->
|
|
12
12
|
|
|
13
|
-
[](https://core.telegram.org/bots/api)
|
|
14
14
|
[](https://www.npmjs.org/package/grammy) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
15
|
-
[](#contributors-)
|
|
16
16
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
17
17
|
|
|
18
18
|
<!-- deno-fmt-ignore-end -->
|
|
@@ -25,7 +25,7 @@ You want grammY because it is easy to use. It is very powerful and always up to
|
|
|
25
25
|
|
|
26
26
|
Are you ready? π€π
|
|
27
27
|
|
|
28
|
-
Bots are written in [TypeScript](https://www.typescriptlang.org/) (or JavaScript) and run on [Node.js](https://nodejs.org/).
|
|
28
|
+
Bots are written in [TypeScript](https://www.typescriptlang.org/) (or JavaScript) and run on [Node.js](https://nodejs.org/) or [Deno](#deno-support).
|
|
29
29
|
|
|
30
30
|
## Quickstart
|
|
31
31
|
|
|
@@ -66,7 +66,7 @@ Congrats! You just wrote a Telegram bot :)
|
|
|
66
66
|
|
|
67
67
|
## Going Further
|
|
68
68
|
|
|
69
|
-
grammY has an excellent [documentation](https://grammy.dev), and an [API Reference](https://doc.deno.land/https
|
|
69
|
+
grammY has an excellent [documentation](https://grammy.dev), and an [API Reference](https://doc.deno.land/https://deno.land/x/grammy/mod.ts). It even integrates with your code editor, e.g. [VSCode](https://code.visualstudio.com/). You can hover over any element of grammY to get a detailed description of what that thing does or means.
|
|
70
70
|
|
|
71
71
|
If you are still stuck, just join the [Telegram chat](https://t.me/grammyjs) and ask for help. People are nice there and we appreciate your question, no matter what it is :)
|
|
72
72
|
|
|
@@ -78,7 +78,7 @@ Here are some more resources to support you:
|
|
|
78
78
|
|
|
79
79
|
βmain project website and documentation.
|
|
80
80
|
|
|
81
|
-
### [grammY API Reference](https://doc.deno.land/https
|
|
81
|
+
### [grammY API Reference](https://doc.deno.land/https://deno.land/x/grammy/mod.ts)
|
|
82
82
|
|
|
83
83
|
βreference of everything that grammY exports.
|
|
84
84
|
|
|
@@ -90,6 +90,8 @@ Here are some more resources to support you:
|
|
|
90
90
|
|
|
91
91
|
βTelegram chat where you can ask any question about grammY or bots in general. We are also open for feedback, ideas, and contributions!
|
|
92
92
|
|
|
93
|
+
The Russian commnity chat can be found [here](https://t.me/grammyjs_ru).
|
|
94
|
+
|
|
93
95
|
### [grammY News Channel](https://t.me/grammyjs_news)
|
|
94
96
|
|
|
95
97
|
βTelegram channel where updates to grammY and the ecosystem are posted.
|
|
@@ -100,9 +102,11 @@ Here are some more resources to support you:
|
|
|
100
102
|
|
|
101
103
|
## Deno Support
|
|
102
104
|
|
|
103
|
-
All grammY packages published by [@grammyjs](https://github.com/grammyjs) run natively
|
|
105
|
+
All grammY packages published by [@grammyjs](https://github.com/grammyjs) run natively on [Deno](https://deno.land). We are compiling every codebase to still run on Node.js.
|
|
106
|
+
|
|
107
|
+
However, given that most bot developers are still using Node.js, all documentation is written Node.js-first. We may migrate it if Deno overtakes Node.js. If you are already on Deno today, import grammY from [`https://deno.land/x/grammy/mod.ts`](https://deno.land/x/grammy).
|
|
104
108
|
|
|
105
|
-
|
|
109
|
+
You may also be interested in [why we support Deno](https://grammy.dev/resources/faq.html#why-do-you-support-deno).
|
|
106
110
|
|
|
107
111
|
## [Contribution Guide Β»](./CONTRIBUTING.md)
|
|
108
112
|
|
|
@@ -126,7 +130,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
126
130
|
<tr>
|
|
127
131
|
<td align="center"><a href="https://edjopato.de/"><img src="https://avatars.githubusercontent.com/u/7953011?v=4?s=100" width="100px;" alt=""/><br /><sub><b>EdJoPaTo</b></sub></a><br /><a href="#plugin-EdJoPaTo" title="Plugin/utility libraries">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=EdJoPaTo" title="Documentation">π</a> <a href="#ideas-EdJoPaTo" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AEdJoPaTo" title="Reviewed Pull Requests">π</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3AEdJoPaTo" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=EdJoPaTo" title="Code">π»</a> <a href="#question-EdJoPaTo" title="Answering Questions">π¬</a></td>
|
|
128
132
|
<td align="center"><a href="https://github.com/Amir-Zouerami"><img src="https://avatars.githubusercontent.com/u/53701884?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amir Zouerami</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Amir-Zouerami" title="Documentation">π</a> <a href="#plugin-Amir-Zouerami" title="Plugin/utility libraries">π</a></td>
|
|
129
|
-
<td align="center"><a href="https://github.com/rojserbest"><img src="https://avatars.githubusercontent.com/u/49933115?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Roj</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=rojserbest" title="Documentation">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Arojserbest" title="Reviewed Pull Requests">π</a> <a href="#infra-rojserbest" title="Infrastructure (Hosting, Build-Tools, etc)">π</a></td>
|
|
133
|
+
<td align="center"><a href="https://github.com/rojserbest"><img src="https://avatars.githubusercontent.com/u/49933115?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Roj</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=rojserbest" title="Documentation">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Arojserbest" title="Reviewed Pull Requests">π</a> <a href="#infra-rojserbest" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#translation-rojserbest" title="Translation">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=rojserbest" title="Code">π»</a></td>
|
|
130
134
|
<td align="center"><a href="https://github.com/jokasimr"><img src="https://avatars.githubusercontent.com/u/20954731?v=4?s=100" width="100px;" alt=""/><br /><sub><b>jokasimr</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ajokasimr" title="Bug reports">π</a></td>
|
|
131
135
|
<td align="center"><a href="https://github.com/CikiMomogi"><img src="https://avatars.githubusercontent.com/u/74030149?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ciki Momogi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=CikiMomogi" title="Documentation">π</a></td>
|
|
132
136
|
<td align="center"><a href="https://github.com/AndreoliBR"><img src="https://avatars.githubusercontent.com/u/15970011?v=4?s=100" width="100px;" alt=""/><br /><sub><b>AndreoliBR</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AAndreoliBR" title="Reviewed Pull Requests">π</a></td>
|
|
@@ -142,7 +146,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
142
146
|
<td align="center"><a href="https://github.com/deptyped"><img src="https://avatars.githubusercontent.com/u/26162440?v=4?s=100" width="100px;" alt=""/><br /><sub><b>deptyped</b></sub></a><br /><a href="#example-deptyped" title="Examples">π‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=deptyped" title="Documentation">π</a> <a href="#tutorial-deptyped" title="Tutorials">β
</a> <a href="#question-deptyped" title="Answering Questions">π¬</a></td>
|
|
143
147
|
</tr>
|
|
144
148
|
<tr>
|
|
145
|
-
<td align="center"><a href="https://github.com/dzek69"><img src="https://avatars.githubusercontent.com/u/4936805?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacek Nowacki</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=dzek69" title="Documentation">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=dzek69" title="Code">π»</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3Adzek69" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adzek69" title="Reviewed Pull Requests">π</a></td>
|
|
149
|
+
<td align="center"><a href="https://github.com/dzek69"><img src="https://avatars.githubusercontent.com/u/4936805?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacek Nowacki</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=dzek69" title="Documentation">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=dzek69" title="Code">π»</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3Adzek69" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adzek69" title="Reviewed Pull Requests">π</a> <a href="#ideas-dzek69" title="Ideas, Planning, & Feedback">π€</a></td>
|
|
146
150
|
<td align="center"><a href="https://blog.outv.im"><img src="https://avatars.githubusercontent.com/u/19144373?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Outvi V</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=outloudvi" title="Code">π»</a></td>
|
|
147
151
|
<td align="center"><a href="https://bandism.net/"><img src="https://avatars.githubusercontent.com/u/22633385?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ikko Ashimine</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=eltociear" title="Documentation">π</a></td>
|
|
148
152
|
<td align="center"><a href="https://github.com/amberlionk"><img src="https://avatars.githubusercontent.com/u/29119723?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yevhen Denesiuk</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Aamberlionk" title="Reviewed Pull Requests">π</a> <a href="https://github.com/grammyjs/grammY/issues?q=author%3Aamberlionk" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=amberlionk" title="Code">π»</a></td>
|
|
@@ -154,17 +158,24 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
154
158
|
<td align="center"><a href="https://github.com/chimit"><img src="https://avatars.githubusercontent.com/u/839349?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chimit</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=chimit" title="Documentation">π</a></td>
|
|
155
159
|
<td align="center"><a href="https://github.com/CalsiBotDev"><img src="https://avatars.githubusercontent.com/u/55633371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Calsi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=CalsiBotDev" title="Documentation">π</a></td>
|
|
156
160
|
<td align="center"><a href="https://zohren.xyz"><img src="https://avatars.githubusercontent.com/u/15788906?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Zohren</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Ajfowl" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=jfowl" title="Code">π»</a></td>
|
|
157
|
-
<td align="center"><a href="https://zhemu.buzz/"><img src="https://avatars.githubusercontent.com/u/56839018?v=4?s=100" width="100px;" alt=""/><br /><sub><b>linbuxiao</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=linbuxiao" title="Documentation">π</a></td>
|
|
158
|
-
<td align="center"><a href="https://github.com/JiquanWang99"><img src="https://avatars.githubusercontent.com/u/63894579?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JiquanWang99</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=JiquanWang99" title="Documentation">π</a></td>
|
|
161
|
+
<td align="center"><a href="https://zhemu.buzz/"><img src="https://avatars.githubusercontent.com/u/56839018?v=4?s=100" width="100px;" alt=""/><br /><sub><b>linbuxiao</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=linbuxiao" title="Documentation">π</a> <a href="#translation-linbuxiao" title="Translation">π</a></td>
|
|
162
|
+
<td align="center"><a href="https://github.com/JiquanWang99"><img src="https://avatars.githubusercontent.com/u/63894579?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JiquanWang99</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=JiquanWang99" title="Documentation">π</a> <a href="#translation-JiquanWang99" title="Translation">π</a></td>
|
|
159
163
|
<td align="center"><a href="http://bor691.ir/"><img src="https://avatars.githubusercontent.com/u/4184939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Borhan Hafez</b></sub></a><br /><a href="#plugin-zumoshi" title="Plugin/utility libraries">π</a></td>
|
|
160
|
-
<td align="center"><a href="https://blog.limx.dev/"><img src="https://avatars.githubusercontent.com/u/6434137?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WingLim</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=WingLim" title="Documentation">π</a></td>
|
|
164
|
+
<td align="center"><a href="https://blog.limx.dev/"><img src="https://avatars.githubusercontent.com/u/6434137?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WingLim</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=WingLim" title="Documentation">π</a> <a href="#translation-WingLim" title="Translation">π</a></td>
|
|
161
165
|
</tr>
|
|
162
166
|
<tr>
|
|
163
|
-
<td align="center"><a href="https://github.com/taotie111"><img src="https://avatars.githubusercontent.com/u/44166322?v=4?s=100" width="100px;" alt=""/><br /><sub><b>taotie111</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=taotie111" title="Documentation">π</a></td>
|
|
167
|
+
<td align="center"><a href="https://github.com/taotie111"><img src="https://avatars.githubusercontent.com/u/44166322?v=4?s=100" width="100px;" alt=""/><br /><sub><b>taotie111</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=taotie111" title="Documentation">π</a> <a href="#translation-taotie111" title="Translation">π</a></td>
|
|
164
168
|
<td align="center"><a href="https://www.linkedin.com/in/merlin-brandes-42328717a/"><img src="https://avatars.githubusercontent.com/u/14237330?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Merlin</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=FatalMerlin" title="Documentation">π</a></td>
|
|
165
169
|
<td align="center"><a href="https://darve.sh"><img src="https://avatars.githubusercontent.com/u/22394081?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Darvesh</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adarvesh" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=darvesh" title="Code">π»</a></td>
|
|
166
|
-
<td align="center"><a href="http://telegram.me/dcdunkan"><img src="https://avatars.githubusercontent.com/u/70066170?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dcdunkan</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adcdunkan" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Code">π»</a></td>
|
|
167
|
-
<td align="center"><a href="https://xuann.wang/"><img src="https://avatars.githubusercontent.com/u/44045911?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kid</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kidonng" title="Documentation">π</a></td>
|
|
170
|
+
<td align="center"><a href="http://telegram.me/dcdunkan"><img src="https://avatars.githubusercontent.com/u/70066170?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dcdunkan</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Adcdunkan" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=dcdunkan" title="Code">π»</a> <a href="#plugin-dcdunkan" title="Plugin/utility libraries">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Adcdunkan" title="Reviewed Pull Requests">π</a></td>
|
|
171
|
+
<td align="center"><a href="https://xuann.wang/"><img src="https://avatars.githubusercontent.com/u/44045911?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kid</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kidonng" title="Documentation">π</a> <a href="#translation-kidonng" title="Translation">π</a></td>
|
|
172
|
+
<td align="center"><a href="http://slava.fomin.io/"><img src="https://avatars.githubusercontent.com/u/1702725?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Slava Fomin II</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Aslavafomin" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=slavafomin" title="Documentation">π</a></td>
|
|
173
|
+
<td align="center"><a href="https://kikobeats.com/"><img src="https://avatars.githubusercontent.com/u/2096101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kiko Beats</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=Kikobeats" title="Documentation">π</a></td>
|
|
174
|
+
</tr>
|
|
175
|
+
<tr>
|
|
176
|
+
<td align="center"><a href="http://///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////kraftwerk28.pp.ua"><img src="https://avatars.githubusercontent.com/u/31807671?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vsevolod</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=kraftwerk28" title="Code">π»</a> <a href="#ideas-kraftwerk28" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Akraftwerk28" title="Reviewed Pull Requests">π</a></td>
|
|
177
|
+
<td align="center"><a href="https://github.com/habemuscode"><img src="https://avatars.githubusercontent.com/u/34692207?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Habemuscode</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Ahabemuscode" title="Reviewed Pull Requests">π</a></td>
|
|
178
|
+
<td align="center"><a href="https://borodutch.com/"><img src="https://avatars.githubusercontent.com/u/3192028?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nikita Kolmogorov</b></sub></a><br /><a href="#plugin-backmeupplz" title="Plugin/utility libraries">π</a></td>
|
|
168
179
|
</tr>
|
|
169
180
|
</table>
|
|
170
181
|
|
package/out/context.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
62
62
|
* Used by some middleware to store information about how a certain string
|
|
63
63
|
* or regular expression was matched.
|
|
64
64
|
*/
|
|
65
|
-
match?: string | RegExpMatchArray
|
|
65
|
+
match?: string | RegExpMatchArray;
|
|
66
66
|
constructor(
|
|
67
67
|
/**
|
|
68
68
|
* The update object that is contained in the context.
|
|
@@ -113,7 +113,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
113
113
|
get msg(): Message | undefined;
|
|
114
114
|
/**
|
|
115
115
|
* Get chat object from whereever possible. Alias for `(this.msg ??
|
|
116
|
-
* this.myChatMember ?? this.chatMember)?.chat`
|
|
116
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest)?.chat`
|
|
117
117
|
*/
|
|
118
118
|
get chat(): Chat | undefined;
|
|
119
119
|
/**
|
|
@@ -125,7 +125,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
125
125
|
* Get message author from whereever possible. Alias for
|
|
126
126
|
* `(ctx.callbackQuery?? ctx.inlineQuery ?? ctx.shippingQuery ??
|
|
127
127
|
* ctx.preCheckoutQuery ?? ctx.chosenInlineResult ?? ctx.msg ??
|
|
128
|
-
* this.myChatMember ?? this.chatMember)?.from`
|
|
128
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest)?.from`
|
|
129
129
|
*/
|
|
130
130
|
get from(): User | undefined;
|
|
131
131
|
/**
|
|
@@ -447,6 +447,24 @@ export declare class Context implements RenamedUpdate {
|
|
|
447
447
|
* **Official reference:** https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
|
448
448
|
*/
|
|
449
449
|
setChatAdministratorCustomTitle(user_id: number, custom_title: string, signal?: AbortSignal): Promise<true>;
|
|
450
|
+
/**
|
|
451
|
+
* Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
452
|
+
*
|
|
453
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
454
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
455
|
+
*
|
|
456
|
+
* **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
|
|
457
|
+
*/
|
|
458
|
+
banChatSenderChat(sender_chat_id: number, signal?: AbortSignal): Promise<true>;
|
|
459
|
+
/**
|
|
460
|
+
* Context-aware alias for `api.unbanChatSenderChat`. Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
461
|
+
*
|
|
462
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
463
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
464
|
+
*
|
|
465
|
+
* **Official reference:** https://core.telegram.org/bots/api#unbanchatsenderchat
|
|
466
|
+
*/
|
|
467
|
+
unbanChatSenderChat(sender_chat_id: number, signal?: AbortSignal): Promise<true>;
|
|
450
468
|
/**
|
|
451
469
|
* Context-aware alias for `api.setChatPermissions`. Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
|
|
452
470
|
*
|
package/out/context.js
CHANGED
|
@@ -152,12 +152,12 @@ class Context {
|
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Get chat object from whereever possible. Alias for `(this.msg ??
|
|
155
|
-
* this.myChatMember ?? this.chatMember)?.chat`
|
|
155
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest)?.chat`
|
|
156
156
|
*/
|
|
157
157
|
get chat() {
|
|
158
|
-
var _a, _b, _c;
|
|
158
|
+
var _a, _b, _c, _d;
|
|
159
159
|
// Keep in sync with types in `filter.ts`.
|
|
160
|
-
return (_c = (
|
|
160
|
+
return (_d = ((_c = (_b = (_a = this.msg) !== null && _a !== void 0 ? _a : this.myChatMember) !== null && _b !== void 0 ? _b : this.chatMember) !== null && _c !== void 0 ? _c : this.chatJoinRequest)) === null || _d === void 0 ? void 0 : _d.chat;
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* Get sender chat object from wherever possible. Alias for
|
|
@@ -171,12 +171,12 @@ class Context {
|
|
|
171
171
|
* Get message author from whereever possible. Alias for
|
|
172
172
|
* `(ctx.callbackQuery?? ctx.inlineQuery ?? ctx.shippingQuery ??
|
|
173
173
|
* ctx.preCheckoutQuery ?? ctx.chosenInlineResult ?? ctx.msg ??
|
|
174
|
-
* this.myChatMember ?? this.chatMember)?.from`
|
|
174
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest)?.from`
|
|
175
175
|
*/
|
|
176
176
|
get from() {
|
|
177
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
177
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
178
178
|
// Keep in sync with types in `filter.ts`.
|
|
179
|
-
return (_h = (
|
|
179
|
+
return (_j = ((_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineQuery) !== null && _b !== void 0 ? _b : this.shippingQuery) !== null && _c !== void 0 ? _c : this.preCheckoutQuery) !== null && _d !== void 0 ? _d : this.chosenInlineResult) !== null && _e !== void 0 ? _e : this.msg) !== null && _f !== void 0 ? _f : this.myChatMember) !== null && _g !== void 0 ? _g : this.chatMember) !== null && _h !== void 0 ? _h : this.chatJoinRequest)) === null || _j === void 0 ? void 0 : _j.from;
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Get inline message ID from whereever possible. Alias for
|
|
@@ -576,6 +576,28 @@ class Context {
|
|
|
576
576
|
setChatAdministratorCustomTitle(user_id, custom_title, signal) {
|
|
577
577
|
return this.api.setChatAdministratorCustomTitle(orThrow(this.chat, "setChatAdministratorCustomTitle").id, user_id, custom_title, signal);
|
|
578
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Context-aware alias for `api.banChatSenderChat`. Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
581
|
+
*
|
|
582
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
583
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
584
|
+
*
|
|
585
|
+
* **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
|
|
586
|
+
*/
|
|
587
|
+
banChatSenderChat(sender_chat_id, signal) {
|
|
588
|
+
return this.api.banChatSenderChat(orThrow(this.chat, "banChatSenderChat").id, sender_chat_id, signal);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Context-aware alias for `api.unbanChatSenderChat`. Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
592
|
+
*
|
|
593
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
594
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
595
|
+
*
|
|
596
|
+
* **Official reference:** https://core.telegram.org/bots/api#unbanchatsenderchat
|
|
597
|
+
*/
|
|
598
|
+
unbanChatSenderChat(sender_chat_id, signal) {
|
|
599
|
+
return this.api.unbanChatSenderChat(orThrow(this.chat, "unbanChatSenderChat").id, sender_chat_id, signal);
|
|
600
|
+
}
|
|
579
601
|
/**
|
|
580
602
|
* Context-aware alias for `api.setChatPermissions`. Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
|
|
581
603
|
*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
2
|
+
export declare const adapters: {
|
|
3
|
+
http: (req: IncomingMessage, res: ServerResponse) => {
|
|
4
|
+
update: Promise<any>;
|
|
5
|
+
end: () => void;
|
|
6
|
+
respond: (json: string) => void;
|
|
7
|
+
};
|
|
8
|
+
https: (req: IncomingMessage, res: ServerResponse) => {
|
|
9
|
+
update: Promise<any>;
|
|
10
|
+
end: () => void;
|
|
11
|
+
respond: (json: string) => void;
|
|
12
|
+
};
|
|
13
|
+
express: (req: any, res: any) => {
|
|
14
|
+
update: Promise<any>;
|
|
15
|
+
end: () => any;
|
|
16
|
+
respond: (json: string) => void;
|
|
17
|
+
};
|
|
18
|
+
koa: (ctx: any) => {
|
|
19
|
+
update: Promise<any>;
|
|
20
|
+
end: () => void;
|
|
21
|
+
respond: (json: string) => void;
|
|
22
|
+
};
|
|
23
|
+
fastify: (req: any, reply: any) => {
|
|
24
|
+
update: Promise<any>;
|
|
25
|
+
end: () => any;
|
|
26
|
+
respond: (json: string) => any;
|
|
27
|
+
};
|
|
28
|
+
worktop: (req: any, res: any) => {
|
|
29
|
+
update: Promise<any>;
|
|
30
|
+
end: () => any;
|
|
31
|
+
respond: (json: string) => any;
|
|
32
|
+
};
|
|
33
|
+
"aws-lambda": (event: any, _context: any, callback: any) => {
|
|
34
|
+
update: any;
|
|
35
|
+
end: () => any;
|
|
36
|
+
respond: (json: string) => any;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare const defaultAdapter = "express";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultAdapter = exports.adapters = void 0;
|
|
4
|
+
/** Node.js native 'http' and 'https' modules */
|
|
5
|
+
const http = (req, res) => ({
|
|
6
|
+
update: new Promise((resolve, reject) => {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
req.on("data", (chunk) => chunks.push(chunk)).once("end", () => {
|
|
9
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
10
|
+
resolve(JSON.parse(raw));
|
|
11
|
+
}).once("error", reject);
|
|
12
|
+
}),
|
|
13
|
+
end: () => res.end(),
|
|
14
|
+
respond: (json) => res.writeHead(200, { "Content-Type": "application/json" }).end(json),
|
|
15
|
+
});
|
|
16
|
+
/** express web framework */
|
|
17
|
+
const express = (req, res) => ({
|
|
18
|
+
update: Promise.resolve(req.body),
|
|
19
|
+
end: () => res.end(),
|
|
20
|
+
respond: (json) => {
|
|
21
|
+
res.set("Content-Type", "application/json");
|
|
22
|
+
res.send(json);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
/** koa web framework */
|
|
26
|
+
const koa = (ctx) => ({
|
|
27
|
+
update: Promise.resolve(ctx.request.body),
|
|
28
|
+
end: () => {
|
|
29
|
+
ctx.body = "";
|
|
30
|
+
},
|
|
31
|
+
respond: (json) => {
|
|
32
|
+
ctx.set("Content-Type", "application/json");
|
|
33
|
+
ctx.response.body = json;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
/** fastify web framework */
|
|
37
|
+
const fastify = (req, reply) => ({
|
|
38
|
+
update: Promise.resolve(req.body),
|
|
39
|
+
end: () => reply.status(200).send(),
|
|
40
|
+
respond: (json) => reply.send(json),
|
|
41
|
+
});
|
|
42
|
+
/** worktop CloudFlare workers framework */
|
|
43
|
+
const worktop = (req, res) => ({
|
|
44
|
+
update: Promise.resolve(req.body.json()),
|
|
45
|
+
end: () => res.end(),
|
|
46
|
+
respond: (json) => res.send(200, json),
|
|
47
|
+
});
|
|
48
|
+
/** AWS lambda serverless functions */
|
|
49
|
+
const awsLambda = (event, _context, callback) => ({
|
|
50
|
+
update: JSON.parse(event.body),
|
|
51
|
+
end: () => callback(null, { statusCode: 200 }),
|
|
52
|
+
respond: (json) => callback(null, { statusCode: 200, body: json }),
|
|
53
|
+
});
|
|
54
|
+
// please open a PR if you want to add another
|
|
55
|
+
exports.adapters = {
|
|
56
|
+
http,
|
|
57
|
+
https: http,
|
|
58
|
+
express,
|
|
59
|
+
koa,
|
|
60
|
+
fastify,
|
|
61
|
+
worktop,
|
|
62
|
+
"aws-lambda": awsLambda,
|
|
63
|
+
};
|
|
64
|
+
exports.defaultAdapter = "express";
|
|
@@ -138,7 +138,7 @@ export declare class InlineKeyboard {
|
|
|
138
138
|
* the button is pressed.
|
|
139
139
|
*
|
|
140
140
|
* @param text The text to display
|
|
141
|
-
* @param url HTTP or tg:// url to be opened when button is pressed
|
|
141
|
+
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
|
142
142
|
*/
|
|
143
143
|
url(text: string, url: string): this;
|
|
144
144
|
/**
|
|
@@ -211,7 +211,7 @@ export declare class InlineKeyboard {
|
|
|
211
211
|
/**
|
|
212
212
|
* Adds a new payment button, confer https://core.telegram.org/bots/api#payments
|
|
213
213
|
*
|
|
214
|
-
* This type of button must always be the first button in the first row.
|
|
214
|
+
* This type of button must always be the first button in the first row and can only be used in invoice messages.
|
|
215
215
|
*
|
|
216
216
|
* @param text The text to display
|
|
217
217
|
*/
|
|
@@ -179,7 +179,7 @@ class InlineKeyboard {
|
|
|
179
179
|
* the button is pressed.
|
|
180
180
|
*
|
|
181
181
|
* @param text The text to display
|
|
182
|
-
* @param url HTTP or tg:// url to be opened when button is pressed
|
|
182
|
+
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
|
183
183
|
*/
|
|
184
184
|
url(text, url) {
|
|
185
185
|
return this.add({ text, url });
|
|
@@ -269,7 +269,7 @@ class InlineKeyboard {
|
|
|
269
269
|
/**
|
|
270
270
|
* Adds a new payment button, confer https://core.telegram.org/bots/api#payments
|
|
271
271
|
*
|
|
272
|
-
* This type of button must always be the first button in the first row.
|
|
272
|
+
* This type of button must always be the first button in the first row and can only be used in invoice messages.
|
|
273
273
|
*
|
|
274
274
|
* @param text The text to display
|
|
275
275
|
*/
|
|
@@ -8,7 +8,7 @@ declare type MaybePromise<T> = Promise<T> | T;
|
|
|
8
8
|
* Session middleware will load the session data of a specific chat from your
|
|
9
9
|
* storage solution, and make it available to you on the context object. Check
|
|
10
10
|
* out the
|
|
11
|
-
* [documentation](https://doc.deno.land/https
|
|
11
|
+
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/session)
|
|
12
12
|
* on session middleware to know more, and read the section about sessions on
|
|
13
13
|
* the [website](https://grammy.dev/plugins/session.html).
|
|
14
14
|
*/
|
|
@@ -37,7 +37,7 @@ export interface SessionFlavor<S> {
|
|
|
37
37
|
* object. Once you access `ctx.session`, the storage will be queried and the
|
|
38
38
|
* session data becomes available. If you access `ctx.session` again for the
|
|
39
39
|
* same context object, the cached value will be used. Check out the
|
|
40
|
-
* [documentation](https://doc.deno.land/https
|
|
40
|
+
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/lazySession)
|
|
41
41
|
* on lazy session middleware to know more, and read the section about lazy
|
|
42
42
|
* sessions on the
|
|
43
43
|
* [website](https://grammy.dev/plugins/session.html#lazy-sessions).
|
|
@@ -1,10 +1,81 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Bot } from "../bot.js";
|
|
3
|
+
import { Update } from "../platform.node.js";
|
|
2
4
|
import { Context } from "../context.js";
|
|
5
|
+
declare const adapters: {
|
|
6
|
+
callback: FrameworkAdapter;
|
|
7
|
+
http: (req: import("http").IncomingMessage, res: import("http").ServerResponse) => {
|
|
8
|
+
update: Promise<any>;
|
|
9
|
+
end: () => void;
|
|
10
|
+
respond: (json: string) => void;
|
|
11
|
+
};
|
|
12
|
+
https: (req: import("http").IncomingMessage, res: import("http").ServerResponse) => {
|
|
13
|
+
update: Promise<any>;
|
|
14
|
+
end: () => void;
|
|
15
|
+
respond: (json: string) => void;
|
|
16
|
+
};
|
|
17
|
+
express: (req: any, res: any) => {
|
|
18
|
+
update: Promise<any>;
|
|
19
|
+
end: () => any;
|
|
20
|
+
respond: (json: string) => void;
|
|
21
|
+
};
|
|
22
|
+
koa: (ctx: any) => {
|
|
23
|
+
update: Promise<any>;
|
|
24
|
+
end: () => void;
|
|
25
|
+
respond: (json: string) => void;
|
|
26
|
+
};
|
|
27
|
+
fastify: (req: any, reply: any) => {
|
|
28
|
+
update: Promise<any>;
|
|
29
|
+
end: () => any;
|
|
30
|
+
respond: (json: string) => any;
|
|
31
|
+
};
|
|
32
|
+
worktop: (req: any, res: any) => {
|
|
33
|
+
update: Promise<any>;
|
|
34
|
+
end: () => any;
|
|
35
|
+
respond: (json: string) => any;
|
|
36
|
+
};
|
|
37
|
+
"aws-lambda": (event: any, _context: any, callback: any) => {
|
|
38
|
+
update: any;
|
|
39
|
+
end: () => any;
|
|
40
|
+
respond: (json: string) => any;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
3
43
|
/**
|
|
4
44
|
* HTTP Web frameworks for which grammY provides compatible callback out of the
|
|
5
45
|
* box.
|
|
6
46
|
*/
|
|
7
|
-
declare type SupportedFrameworks =
|
|
47
|
+
declare type SupportedFrameworks = keyof typeof adapters;
|
|
48
|
+
/**
|
|
49
|
+
* Abstraction over a request-response cycle, provding access to the update, as
|
|
50
|
+
* well as a mechanism for responding to the request and to end it.
|
|
51
|
+
*/
|
|
52
|
+
interface ReqResHandler {
|
|
53
|
+
/**
|
|
54
|
+
* The update object sent from Telegram, usually resolves the request's JSON
|
|
55
|
+
* body
|
|
56
|
+
*/
|
|
57
|
+
update: Promise<Update>;
|
|
58
|
+
/**
|
|
59
|
+
* Ends the request immediately without body, called after every request
|
|
60
|
+
* unless a webhook reply was performed
|
|
61
|
+
*/
|
|
62
|
+
end?: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Sends the specified JSON as a payload in the body, used for webhook
|
|
65
|
+
* replies
|
|
66
|
+
*/
|
|
67
|
+
respond: (json: string) => unknown;
|
|
68
|
+
/**
|
|
69
|
+
* Some frameworks (e.g. Deno's std/http `listenAndServe`) assume
|
|
70
|
+
* that handler returns something
|
|
71
|
+
*/
|
|
72
|
+
handlerReturn?: any;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Middleware for a web framework. Creates a request-response handler for a
|
|
76
|
+
* request. The handler will be used to integrate with the compatible framework.
|
|
77
|
+
*/
|
|
78
|
+
export declare type FrameworkAdapter = (...args: any[]) => ReqResHandler;
|
|
8
79
|
/**
|
|
9
80
|
* Creates a callback function that you can pass to a web framework (such as
|
|
10
81
|
* express) if you want to run your bot via webhooks. Use it like this:
|
|
@@ -24,5 +95,5 @@ declare type SupportedFrameworks = "express" | "http" | "https" | "koa" | "oak"
|
|
|
24
95
|
* @param onTimeout An optional strategy to handle timeouts (default: 'throw')
|
|
25
96
|
* @param timeoutMilliseconds An optional number of timeout milliseconds (default: 10_000)
|
|
26
97
|
*/
|
|
27
|
-
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>,
|
|
98
|
+
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>, adapter?: SupportedFrameworks | FrameworkAdapter, onTimeout?: "throw" | "return" | ((...args: any[]) => unknown), timeoutMilliseconds?: number): (...args: any[]) => Promise<any>;
|
|
28
99
|
export {};
|
|
@@ -2,60 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.webhookCallback = void 0;
|
|
4
4
|
const platform_node_js_1 = require("../platform.node.js");
|
|
5
|
+
const frameworks_node_js_1 = require("./frameworks.node.js");
|
|
5
6
|
const debugErr = (0, platform_node_js_1.debug)("grammy:error");
|
|
6
|
-
const
|
|
7
|
-
update: Promise.resolve(
|
|
8
|
-
|
|
9
|
-
respond: (json) => {
|
|
10
|
-
res.set("Content-Type", "application/json");
|
|
11
|
-
res.send(json);
|
|
12
|
-
},
|
|
7
|
+
const callbackAdapter = (update, callback) => ({
|
|
8
|
+
update: Promise.resolve(update),
|
|
9
|
+
respond: callback,
|
|
13
10
|
});
|
|
14
|
-
|
|
15
|
-
const frameworkAdapters = {
|
|
16
|
-
express: standard,
|
|
17
|
-
http: standard,
|
|
18
|
-
https: standard,
|
|
19
|
-
koa: (ctx) => ({
|
|
20
|
-
update: Promise.resolve(ctx.request.body),
|
|
21
|
-
end: () => (ctx.body = ""),
|
|
22
|
-
respond: (json) => {
|
|
23
|
-
ctx.set("Content-Type", "application/json");
|
|
24
|
-
ctx.response.body = json;
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
oak: (ctx) => ({
|
|
28
|
-
update: ctx.request.body({ type: "json" }).value,
|
|
29
|
-
end: () => (ctx.response.status = 200),
|
|
30
|
-
respond: (json) => {
|
|
31
|
-
ctx.response.type = "json";
|
|
32
|
-
ctx.response.body = json;
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
fastify: (req, reply) => ({
|
|
36
|
-
update: Promise.resolve(req.body),
|
|
37
|
-
end: () => reply.send({}),
|
|
38
|
-
respond: (json) => reply.send(json),
|
|
39
|
-
}),
|
|
40
|
-
worktop: (req, res) => ({
|
|
41
|
-
update: Promise.resolve(req.body.json()),
|
|
42
|
-
end: () => res.end(),
|
|
43
|
-
respond: (json) => res.send(200, json),
|
|
44
|
-
}),
|
|
45
|
-
callback: (update, callback) => ({
|
|
46
|
-
update: update,
|
|
47
|
-
respond: callback,
|
|
48
|
-
}),
|
|
49
|
-
"aws-lambda": (event, _context, callback) => ({
|
|
50
|
-
update: JSON.parse(event.body),
|
|
51
|
-
end: () => callback(null, { statusCode: 200 }),
|
|
52
|
-
respond: (json) => callback(null, {
|
|
53
|
-
statusCode: 200,
|
|
54
|
-
body: json,
|
|
55
|
-
}),
|
|
56
|
-
}),
|
|
57
|
-
// please open a PR if you want to add another
|
|
58
|
-
};
|
|
11
|
+
const adapters = { ...frameworks_node_js_1.adapters, callback: callbackAdapter };
|
|
59
12
|
/**
|
|
60
13
|
* Creates a callback function that you can pass to a web framework (such as
|
|
61
14
|
* express) if you want to run your bot via webhooks. Use it like this:
|
|
@@ -75,21 +28,14 @@ const frameworkAdapters = {
|
|
|
75
28
|
* @param onTimeout An optional strategy to handle timeouts (default: 'throw')
|
|
76
29
|
* @param timeoutMilliseconds An optional number of timeout milliseconds (default: 10_000)
|
|
77
30
|
*/
|
|
78
|
-
function webhookCallback(bot,
|
|
79
|
-
var _a;
|
|
80
|
-
const server = (_a = frameworkAdapters[framework]) !== null && _a !== void 0 ? _a : standard;
|
|
31
|
+
function webhookCallback(bot, adapter = frameworks_node_js_1.defaultAdapter, onTimeout = "throw", timeoutMilliseconds = 10000) {
|
|
81
32
|
let firstUpdate = true;
|
|
82
33
|
let initialized = false;
|
|
83
34
|
let initCall;
|
|
35
|
+
const server = typeof adapter === "string"
|
|
36
|
+
? adapters[adapter]
|
|
37
|
+
: adapter;
|
|
84
38
|
return async (...args) => {
|
|
85
|
-
const { update, respond, end } = server(...args);
|
|
86
|
-
let usedWebhookReply = false;
|
|
87
|
-
const webhookReplyEnvelope = {
|
|
88
|
-
send: async (json) => {
|
|
89
|
-
usedWebhookReply = true;
|
|
90
|
-
await respond(json);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
39
|
if (!initialized) {
|
|
94
40
|
if (firstUpdate) {
|
|
95
41
|
initCall = bot.init();
|
|
@@ -98,11 +44,20 @@ function webhookCallback(bot, framework = "express", onTimeout = "throw", timeou
|
|
|
98
44
|
await initCall;
|
|
99
45
|
initialized = true;
|
|
100
46
|
}
|
|
47
|
+
const { update, respond, end, handlerReturn } = server(...args);
|
|
48
|
+
let usedWebhookReply = false;
|
|
49
|
+
const webhookReplyEnvelope = {
|
|
50
|
+
async send(json) {
|
|
51
|
+
usedWebhookReply = true;
|
|
52
|
+
await respond(json);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
101
55
|
await timeoutIfNecessary(bot.handleUpdate(await update, webhookReplyEnvelope), typeof onTimeout === "function"
|
|
102
56
|
? () => onTimeout(...args)
|
|
103
57
|
: onTimeout, timeoutMilliseconds);
|
|
104
58
|
if (end !== undefined && !usedWebhookReply)
|
|
105
59
|
end();
|
|
60
|
+
return handlerReturn;
|
|
106
61
|
};
|
|
107
62
|
}
|
|
108
63
|
exports.webhookCallback = webhookCallback;
|