@codebam/cf-workers-telegram-bot 11.6.1 → 11.9.0
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 +28 -18
- package/dist/main.d.ts +2 -1
- package/dist/main.js +2 -1
- package/dist/telegram_api.d.ts +3 -5
- package/dist/telegram_execution_context.d.ts +37 -3
- package/dist/telegram_execution_context.js +89 -17
- package/dist/types/TelegramInlineQueryResultPhoto.d.ts +7 -1
- package/dist/types/TelegramInlineQueryResultPhoto.js +7 -3
- package/dist/types/TelegramInlineQueryResultVideo.d.ts +12 -6
- package/dist/types/TelegramInlineQueryResultVideo.js +12 -8
- package/dist/types/TelegramInlineQueryResultVoice.d.ts +13 -0
- package/dist/types/TelegramInlineQueryResultVoice.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,24 +33,24 @@ npm install @codebam/cf-workers-telegram-bot
|
|
|
33
33
|
import TelegramBot, { TelegramExecutionContext } from '@codebam/cf-workers-telegram-bot';
|
|
34
34
|
|
|
35
35
|
export interface Env {
|
|
36
|
-
|
|
36
|
+
SECRET_TELEGRAM_API_TOKEN: string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export default {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
41
|
+
const bot = new TelegramBot(env.SECRET_TELEGRAM_API_TOKEN);
|
|
42
|
+
|
|
43
|
+
await bot
|
|
44
|
+
.command('start', async (ctx) => {
|
|
45
|
+
await ctx.reply('Hello! I am running on Cloudflare Workers.');
|
|
46
|
+
})
|
|
47
|
+
.onMessage(async (ctx) => {
|
|
48
|
+
await ctx.reply(`You said: ${ctx.text}`);
|
|
49
|
+
})
|
|
50
|
+
.handle(request);
|
|
51
|
+
|
|
52
|
+
return new Response('ok');
|
|
53
|
+
},
|
|
54
54
|
};
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -66,15 +66,19 @@ export default {
|
|
|
66
66
|
The `consumer` directory in this repository serves as a template for new projects. It is included as a git submodule.
|
|
67
67
|
|
|
68
68
|
1. **Clone the repository with submodules**:
|
|
69
|
+
|
|
69
70
|
```sh
|
|
70
71
|
git clone --recursive https://github.com/codebam/cf-workers-telegram-bot.git
|
|
71
72
|
```
|
|
72
|
-
|
|
73
|
+
|
|
74
|
+
_Or, if you've already cloned it:_
|
|
75
|
+
|
|
73
76
|
```sh
|
|
74
77
|
git submodule update --init --recursive
|
|
75
78
|
```
|
|
76
79
|
|
|
77
80
|
2. **Copy the consumer directory**:
|
|
81
|
+
|
|
78
82
|
```sh
|
|
79
83
|
cp -r consumer my-new-bot
|
|
80
84
|
cd my-new-bot
|
|
@@ -86,33 +90,39 @@ The `consumer` directory in this repository serves as a template for new project
|
|
|
86
90
|
|
|
87
91
|
4. **Set your Telegram Token**:
|
|
88
92
|
Get a token from [@BotFather](https://t.me/BotFather) and add it to your worker:
|
|
93
|
+
|
|
89
94
|
```sh
|
|
90
95
|
npx wrangler secret put SECRET_TELEGRAM_API_TOKEN
|
|
91
96
|
```
|
|
92
97
|
|
|
93
98
|
5. **Deploy**:
|
|
99
|
+
|
|
94
100
|
```sh
|
|
95
101
|
npm run deploy
|
|
96
102
|
```
|
|
97
103
|
|
|
98
|
-
|
|
104
|
+
6. **Set Webhook**:
|
|
99
105
|
Visit the following URL in your browser to register your worker with Telegram:
|
|
100
106
|
`https://<your-worker>.<your-subdomain>.workers.dev/<SECRET_TELEGRAM_API_TOKEN>/setWebhook`
|
|
101
107
|
|
|
102
108
|
## Deployment
|
|
103
109
|
|
|
104
110
|
### Manual Deployment
|
|
111
|
+
|
|
105
112
|
Use [Wrangler](https://developers.cloudflare.com/workers/wrangler/) to deploy:
|
|
113
|
+
|
|
106
114
|
```sh
|
|
107
115
|
npx wrangler deploy
|
|
108
116
|
```
|
|
109
117
|
|
|
110
118
|
### GitHub Actions
|
|
111
|
-
To automate deployments, use the [Wrangler Action](https://github.com/cloudflare/wrangler-action) or Cloudflare's built-in [GitHub integration](https://developers.cloudflare.com/workers/ci-cd/github-actions/).
|
|
112
119
|
|
|
120
|
+
To automate deployments, use the [Wrangler Action](https://github.com/cloudflare/wrangler-action) or Cloudflare's built-in [GitHub integration](https://developers.cloudflare.com/workers/ci-cd/github-actions/).
|
|
113
121
|
|
|
114
122
|
## API Documentation
|
|
123
|
+
|
|
115
124
|
Detailed API documentation is available at [cf-workers-telegram-bot.codebam.ca](https://cf-workers-telegram-bot.codebam.ca).
|
|
116
125
|
|
|
117
126
|
## License
|
|
127
|
+
|
|
118
128
|
Apache-2.0
|
package/dist/main.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
|
|
|
20
20
|
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
|
|
21
21
|
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
|
|
22
22
|
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
|
|
23
|
+
import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js';
|
|
23
24
|
import ChatPermissions from './types/ChatPermissions.js';
|
|
24
25
|
import TelegramBusinessMessage from './types/TelegramBusinessMessage.js';
|
|
25
26
|
import TelegramCallbackQuery from './types/TelegramCallbackQuery.js';
|
|
@@ -27,4 +28,4 @@ import TelegramPreCheckoutQuery from './types/TelegramPreCheckoutQuery.js';
|
|
|
27
28
|
import TelegramDocument from './types/TelegramDocument.js';
|
|
28
29
|
import TelegramSuccessfulPayment from './types/TelegramSuccessfulPayment.js';
|
|
29
30
|
export default TelegramBot;
|
|
30
|
-
export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramApiBaseParams, SendMessageParams, SendMessageDraftParams, SendPhotoParams, SendVideoParams, SendVoiceParams, SendChatActionParams, AnswerCallbackParams, AnswerInlineParams, AnswerGuestParams, SendInvoiceParams, AnswerPreCheckoutParams, TelegramApiParams, TelegramCommand, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramVoice, TelegramGuestMessage, TelegramInputMessageContent, TelegramInlineQuery, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, ChatPermissions, TelegramBusinessMessage, TelegramCallbackQuery, TelegramPreCheckoutQuery, TelegramDocument, TelegramSuccessfulPayment, };
|
|
31
|
+
export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramApiBaseParams, SendMessageParams, SendMessageDraftParams, SendPhotoParams, SendVideoParams, SendVoiceParams, SendChatActionParams, AnswerCallbackParams, AnswerInlineParams, AnswerGuestParams, SendInvoiceParams, AnswerPreCheckoutParams, TelegramApiParams, TelegramCommand, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramVoice, TelegramGuestMessage, TelegramInputMessageContent, TelegramInlineQuery, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, TelegramInlineQueryResultVoice, ChatPermissions, TelegramBusinessMessage, TelegramCallbackQuery, TelegramPreCheckoutQuery, TelegramDocument, TelegramSuccessfulPayment, };
|
package/dist/main.js
CHANGED
|
@@ -7,5 +7,6 @@ import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
|
|
|
7
7
|
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
|
|
8
8
|
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
|
|
9
9
|
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
|
|
10
|
+
import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js';
|
|
10
11
|
export default TelegramBot;
|
|
11
|
-
export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramUpdate, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, };
|
|
12
|
+
export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramUpdate, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, TelegramInlineQueryResultVoice, };
|
package/dist/telegram_api.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
|
|
3
|
-
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
|
|
1
|
+
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
|
|
4
2
|
/** Interface for common Telegram API parameters */
|
|
5
3
|
export interface TelegramApiBaseParams {
|
|
6
4
|
chat_id: number | string;
|
|
@@ -56,7 +54,7 @@ export interface AnswerCallbackParams {
|
|
|
56
54
|
/** Interface for inline query parameters */
|
|
57
55
|
export interface AnswerInlineParams {
|
|
58
56
|
inline_query_id: number | string;
|
|
59
|
-
results:
|
|
57
|
+
results: TelegramInlineQueryResult[];
|
|
60
58
|
cache_time?: number;
|
|
61
59
|
is_personal?: boolean;
|
|
62
60
|
next_offset?: string;
|
|
@@ -64,7 +62,7 @@ export interface AnswerInlineParams {
|
|
|
64
62
|
/** Interface for guest query parameters */
|
|
65
63
|
export interface AnswerGuestParams {
|
|
66
64
|
guest_query_id: string;
|
|
67
|
-
result:
|
|
65
|
+
result: TelegramInlineQueryResult;
|
|
68
66
|
}
|
|
69
67
|
/** Interface for invoice parameters */
|
|
70
68
|
export interface SendInvoiceParams extends TelegramApiBaseParams {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import TelegramApi from './telegram_api.js';
|
|
2
2
|
import TelegramBot from './telegram_bot.js';
|
|
3
3
|
import TelegramUpdate from './types/TelegramUpdate.js';
|
|
4
|
+
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
|
|
4
5
|
/** Class representing the context of execution */
|
|
5
6
|
export default class TelegramExecutionContext {
|
|
6
7
|
/** an instance of the telegram bot */
|
|
@@ -103,19 +104,52 @@ export default class TelegramExecutionContext {
|
|
|
103
104
|
replyInline(title: string, message: string, parse_mode?: string): Promise<Response | null>;
|
|
104
105
|
/**
|
|
105
106
|
* Answer a guest query
|
|
107
|
+
* @param result - the result to reply with
|
|
108
|
+
* @returns Promise with the API response
|
|
109
|
+
*/
|
|
110
|
+
answerGuestQuery(result: TelegramInlineQueryResult): Promise<Response>;
|
|
111
|
+
/**
|
|
112
|
+
* Answer a guest query with text
|
|
106
113
|
* @param message - text to reply with
|
|
107
114
|
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
108
115
|
* @returns Promise with the API response
|
|
109
116
|
*/
|
|
110
|
-
|
|
117
|
+
answerGuestQueryText(message: string, parse_mode?: string): Promise<Response>;
|
|
118
|
+
/**
|
|
119
|
+
* Answer a guest query with a photo
|
|
120
|
+
* @param photo - url or file_id to photo
|
|
121
|
+
* @param caption - photo caption
|
|
122
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
123
|
+
* @returns Promise with the API response
|
|
124
|
+
*/
|
|
125
|
+
answerGuestQueryPhoto(photo: string, caption?: string, parse_mode?: string): Promise<Response>;
|
|
126
|
+
/**
|
|
127
|
+
* Answer a guest query with a video
|
|
128
|
+
* @param video - url or file_id to video
|
|
129
|
+
* @param caption - video caption
|
|
130
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
131
|
+
* @returns Promise with the API response
|
|
132
|
+
*/
|
|
133
|
+
answerGuestQueryVideo(video: string, caption?: string, parse_mode?: string): Promise<Response>;
|
|
134
|
+
/**
|
|
135
|
+
* Answer a guest query with a voice message
|
|
136
|
+
* @param voice - url or file_id to voice
|
|
137
|
+
* @param caption - voice caption
|
|
138
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
139
|
+
* @returns Promise with the API response
|
|
140
|
+
*/
|
|
141
|
+
answerGuestQueryVoice(voice: string, caption?: string, parse_mode?: string): Promise<Response>;
|
|
142
|
+
/** Map of draft IDs to message IDs for streaming */
|
|
143
|
+
private drafts;
|
|
111
144
|
/**
|
|
112
145
|
* Reply to the last message with a stream of text
|
|
113
146
|
* @param message - text to reply with
|
|
147
|
+
* @param draft_id - unique ID for this stream
|
|
114
148
|
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
115
|
-
* @param options - any additional options to pass to sendMessage
|
|
149
|
+
* @param options - any additional options to pass to sendMessage/editMessageText
|
|
116
150
|
* @returns Promise with the API response
|
|
117
151
|
*/
|
|
118
|
-
streamReply(message: string, draft_id: number, parse_mode?: string, options?: Record<string, number | string | boolean>): Promise<Response>;
|
|
152
|
+
streamReply(message: string, draft_id: number, parse_mode?: string, options?: Record<string, number | string | boolean | object>): Promise<Response>;
|
|
119
153
|
/**
|
|
120
154
|
* Reply to the last message with text
|
|
121
155
|
* @param message - text to reply with
|
|
@@ -2,6 +2,7 @@ import TelegramApi from './telegram_api.js';
|
|
|
2
2
|
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
|
|
3
3
|
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
|
|
4
4
|
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
|
|
5
|
+
import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js';
|
|
5
6
|
/** Class representing the context of execution */
|
|
6
7
|
export default class TelegramExecutionContext {
|
|
7
8
|
/** an instance of the telegram bot */
|
|
@@ -55,7 +56,7 @@ export default class TelegramExecutionContext {
|
|
|
55
56
|
case 'message':
|
|
56
57
|
case 'business_message':
|
|
57
58
|
case 'guest_message':
|
|
58
|
-
return (this.update.message?.text ?? this.update.guest_message?.text)?.split(' ') ?? [];
|
|
59
|
+
return (this.update.message?.text ?? this.update.business_message?.text ?? this.update.guest_message?.text)?.toString().split(' ') ?? [];
|
|
59
60
|
case 'inline':
|
|
60
61
|
return this.update.inline_query?.query.split(' ') ?? [];
|
|
61
62
|
default:
|
|
@@ -148,7 +149,6 @@ export default class TelegramExecutionContext {
|
|
|
148
149
|
switch (this.update_type) {
|
|
149
150
|
case 'voice':
|
|
150
151
|
case 'message':
|
|
151
|
-
case 'guest_message':
|
|
152
152
|
return await this.api.sendVideo(this.bot.api.toString(), {
|
|
153
153
|
...options,
|
|
154
154
|
chat_id: this.getChatId(),
|
|
@@ -156,11 +156,13 @@ export default class TelegramExecutionContext {
|
|
|
156
156
|
reply_to_message_id: this.getMessageId(),
|
|
157
157
|
video,
|
|
158
158
|
});
|
|
159
|
+
case 'guest_message':
|
|
160
|
+
return await this.answerGuestQueryVideo(video);
|
|
159
161
|
case 'inline':
|
|
160
162
|
return await this.api.answerInline(this.bot.api.toString(), {
|
|
161
163
|
...options,
|
|
162
164
|
inline_query_id: this.update.inline_query?.id.toString() ?? '',
|
|
163
|
-
results: [new TelegramInlineQueryResultVideo(video)],
|
|
165
|
+
results: [new TelegramInlineQueryResultVideo({ video })],
|
|
164
166
|
});
|
|
165
167
|
default:
|
|
166
168
|
return null;
|
|
@@ -186,7 +188,6 @@ export default class TelegramExecutionContext {
|
|
|
186
188
|
case 'voice':
|
|
187
189
|
case 'photo':
|
|
188
190
|
case 'message':
|
|
189
|
-
case 'guest_message':
|
|
190
191
|
return await this.api.sendPhoto(this.bot.api.toString(), {
|
|
191
192
|
...options,
|
|
192
193
|
chat_id: this.getChatId(),
|
|
@@ -195,10 +196,12 @@ export default class TelegramExecutionContext {
|
|
|
195
196
|
photo,
|
|
196
197
|
caption,
|
|
197
198
|
});
|
|
199
|
+
case 'guest_message':
|
|
200
|
+
return await this.answerGuestQueryPhoto(photo, caption);
|
|
198
201
|
case 'inline':
|
|
199
202
|
return await this.api.answerInline(this.bot.api.toString(), {
|
|
200
203
|
inline_query_id: this.update.inline_query?.id.toString() ?? '',
|
|
201
|
-
results: [new TelegramInlineQueryResultPhoto(photo)],
|
|
204
|
+
results: [new TelegramInlineQueryResultPhoto({ photo })],
|
|
202
205
|
});
|
|
203
206
|
default:
|
|
204
207
|
return null;
|
|
@@ -215,7 +218,6 @@ export default class TelegramExecutionContext {
|
|
|
215
218
|
switch (this.update_type) {
|
|
216
219
|
case 'voice':
|
|
217
220
|
case 'message':
|
|
218
|
-
case 'guest_message':
|
|
219
221
|
return await this.api.sendVoice(this.bot.api.toString(), {
|
|
220
222
|
...options,
|
|
221
223
|
chat_id: this.getChatId(),
|
|
@@ -224,6 +226,8 @@ export default class TelegramExecutionContext {
|
|
|
224
226
|
voice,
|
|
225
227
|
caption,
|
|
226
228
|
});
|
|
229
|
+
case 'guest_message':
|
|
230
|
+
return await this.answerGuestQueryVoice(voice, caption);
|
|
227
231
|
default:
|
|
228
232
|
return null;
|
|
229
233
|
}
|
|
@@ -272,32 +276,102 @@ export default class TelegramExecutionContext {
|
|
|
272
276
|
}
|
|
273
277
|
/**
|
|
274
278
|
* Answer a guest query
|
|
275
|
-
* @param
|
|
276
|
-
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
279
|
+
* @param result - the result to reply with
|
|
277
280
|
* @returns Promise with the API response
|
|
278
281
|
*/
|
|
279
|
-
async answerGuestQuery(
|
|
282
|
+
async answerGuestQuery(result) {
|
|
280
283
|
return await this.api.answerGuestQuery(this.bot.api.toString(), {
|
|
281
284
|
guest_query_id: this.update.guest_message?.guest_query_id ?? '',
|
|
282
|
-
result
|
|
285
|
+
result,
|
|
283
286
|
});
|
|
284
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Answer a guest query with text
|
|
290
|
+
* @param message - text to reply with
|
|
291
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
292
|
+
* @returns Promise with the API response
|
|
293
|
+
*/
|
|
294
|
+
async answerGuestQueryText(message, parse_mode = '') {
|
|
295
|
+
return await this.answerGuestQuery(new TelegramInlineQueryResultArticle({ content: message, title: 'Response', parse_mode }));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Answer a guest query with a photo
|
|
299
|
+
* @param photo - url or file_id to photo
|
|
300
|
+
* @param caption - photo caption
|
|
301
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
302
|
+
* @returns Promise with the API response
|
|
303
|
+
*/
|
|
304
|
+
async answerGuestQueryPhoto(photo, caption = '', parse_mode = '') {
|
|
305
|
+
return await this.answerGuestQuery(new TelegramInlineQueryResultPhoto({ photo, caption, parse_mode }));
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Answer a guest query with a video
|
|
309
|
+
* @param video - url or file_id to video
|
|
310
|
+
* @param caption - video caption
|
|
311
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
312
|
+
* @returns Promise with the API response
|
|
313
|
+
*/
|
|
314
|
+
async answerGuestQueryVideo(video, caption = '', parse_mode = '') {
|
|
315
|
+
return await this.answerGuestQuery(new TelegramInlineQueryResultVideo({ video, caption, parse_mode }));
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Answer a guest query with a voice message
|
|
319
|
+
* @param voice - url or file_id to voice
|
|
320
|
+
* @param caption - voice caption
|
|
321
|
+
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
322
|
+
* @returns Promise with the API response
|
|
323
|
+
*/
|
|
324
|
+
async answerGuestQueryVoice(voice, caption = '', parse_mode = '') {
|
|
325
|
+
return await this.answerGuestQuery(new TelegramInlineQueryResultVoice({ voice, caption, parse_mode }));
|
|
326
|
+
}
|
|
327
|
+
/** Map of draft IDs to message IDs for streaming */
|
|
328
|
+
drafts = new Map();
|
|
285
329
|
/**
|
|
286
330
|
* Reply to the last message with a stream of text
|
|
287
331
|
* @param message - text to reply with
|
|
332
|
+
* @param draft_id - unique ID for this stream
|
|
288
333
|
* @param parse_mode - one of HTML, MarkdownV2, Markdown, or an empty string for ascii
|
|
289
|
-
* @param options - any additional options to pass to sendMessage
|
|
334
|
+
* @param options - any additional options to pass to sendMessage/editMessageText
|
|
290
335
|
* @returns Promise with the API response
|
|
291
336
|
*/
|
|
292
337
|
async streamReply(message, draft_id, parse_mode = '', options = {}) {
|
|
293
|
-
|
|
338
|
+
const message_id = this.drafts.get(draft_id);
|
|
339
|
+
if (message_id) {
|
|
340
|
+
return await this.api.editMessageText(this.bot.api.toString(), {
|
|
341
|
+
chat_id: this.getChatId(),
|
|
342
|
+
message_id,
|
|
343
|
+
text: message,
|
|
344
|
+
parse_mode,
|
|
345
|
+
...options,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
if (this.update_type === 'guest_message') {
|
|
349
|
+
if (this.drafts.has(draft_id)) {
|
|
350
|
+
return new Response('Query already answered', { status: 200 });
|
|
351
|
+
}
|
|
352
|
+
this.drafts.set(draft_id, -1);
|
|
353
|
+
return await this.answerGuestQueryText(message, parse_mode);
|
|
354
|
+
}
|
|
355
|
+
const response = await this.api.sendMessage(this.bot.api.toString(), {
|
|
294
356
|
...options,
|
|
295
357
|
chat_id: this.getChatId(),
|
|
296
358
|
message_thread_id: this.getThreadId(),
|
|
297
359
|
text: message,
|
|
298
360
|
parse_mode,
|
|
299
|
-
draft_id,
|
|
300
361
|
});
|
|
362
|
+
if (response.status === 200) {
|
|
363
|
+
const cloned = response.clone();
|
|
364
|
+
try {
|
|
365
|
+
const json = (await cloned.json());
|
|
366
|
+
if (json.ok && json.result?.message_id) {
|
|
367
|
+
this.drafts.set(draft_id, json.result.message_id);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
// ignore
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return response;
|
|
301
375
|
}
|
|
302
376
|
/**
|
|
303
377
|
* Reply to the last message with text
|
|
@@ -312,10 +386,6 @@ export default class TelegramExecutionContext {
|
|
|
312
386
|
case 'message':
|
|
313
387
|
case 'photo':
|
|
314
388
|
case 'document':
|
|
315
|
-
case 'guest_message':
|
|
316
|
-
if (this.update_type === 'guest_message') {
|
|
317
|
-
return await this.answerGuestQuery(message, parse_mode);
|
|
318
|
-
}
|
|
319
389
|
if (reply) {
|
|
320
390
|
return await this.api.sendMessage(this.bot.api.toString(), {
|
|
321
391
|
...options,
|
|
@@ -333,6 +403,8 @@ export default class TelegramExecutionContext {
|
|
|
333
403
|
text: message,
|
|
334
404
|
parse_mode,
|
|
335
405
|
});
|
|
406
|
+
case 'guest_message':
|
|
407
|
+
return await this.answerGuestQueryText(message, parse_mode);
|
|
336
408
|
case 'business_message':
|
|
337
409
|
return await this.api.sendMessage(this.bot.api.toString(), {
|
|
338
410
|
chat_id: this.getChatId(),
|
|
@@ -11,5 +11,11 @@ export default class TelegramInlineQueryResultPhoto extends TelegramInlineQueryR
|
|
|
11
11
|
parse_mode?: string;
|
|
12
12
|
caption_entities?: string;
|
|
13
13
|
input_message_content?: TelegramInputMessageContent;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(data: {
|
|
15
|
+
photo: string;
|
|
16
|
+
caption?: string;
|
|
17
|
+
parse_mode?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
});
|
|
15
21
|
}
|
|
@@ -11,9 +11,13 @@ export default class TelegramInlineQueryResultPhoto extends TelegramInlineQueryR
|
|
|
11
11
|
caption_entities;
|
|
12
12
|
// reply_markup?: TelegramInlineKeyboardMarkup;
|
|
13
13
|
input_message_content;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(data) {
|
|
15
15
|
super('photo');
|
|
16
|
-
this.photo_url = photo;
|
|
17
|
-
this.thumb_url = photo;
|
|
16
|
+
this.photo_url = data.photo;
|
|
17
|
+
this.thumb_url = data.photo;
|
|
18
|
+
this.caption = data.caption;
|
|
19
|
+
this.parse_mode = data.parse_mode;
|
|
20
|
+
this.title = data.title;
|
|
21
|
+
this.description = data.description;
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -2,14 +2,20 @@ import TelegramInlineQueryResult from './TelegramInlineQueryResult.js';
|
|
|
2
2
|
import TelegramInputMessageContent from './TelegramInputMessageContent.js';
|
|
3
3
|
export default class TelegramInlineQueryResultVideo extends TelegramInlineQueryResult {
|
|
4
4
|
video_url: string;
|
|
5
|
+
mime_type: string;
|
|
5
6
|
thumb_url: string;
|
|
6
|
-
|
|
7
|
-
photo_height?: number;
|
|
8
|
-
title?: string;
|
|
9
|
-
description?: string;
|
|
7
|
+
title: string;
|
|
10
8
|
caption?: string;
|
|
11
9
|
parse_mode?: string;
|
|
12
|
-
|
|
10
|
+
video_width?: number;
|
|
11
|
+
video_height?: number;
|
|
12
|
+
video_duration?: number;
|
|
13
|
+
description?: string;
|
|
13
14
|
input_message_content?: TelegramInputMessageContent;
|
|
14
|
-
constructor(
|
|
15
|
+
constructor(data: {
|
|
16
|
+
video: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
caption?: string;
|
|
19
|
+
parse_mode?: string;
|
|
20
|
+
});
|
|
15
21
|
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import TelegramInlineQueryResult from './TelegramInlineQueryResult.js';
|
|
2
2
|
export default class TelegramInlineQueryResultVideo extends TelegramInlineQueryResult {
|
|
3
3
|
video_url;
|
|
4
|
+
mime_type;
|
|
4
5
|
thumb_url;
|
|
5
|
-
photo_width;
|
|
6
|
-
photo_height;
|
|
7
6
|
title;
|
|
8
|
-
description;
|
|
9
7
|
caption;
|
|
10
8
|
parse_mode;
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
video_width;
|
|
10
|
+
video_height;
|
|
11
|
+
video_duration;
|
|
12
|
+
description;
|
|
13
13
|
input_message_content;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(data) {
|
|
15
15
|
super('video');
|
|
16
|
-
this.video_url = video;
|
|
17
|
-
this.
|
|
16
|
+
this.video_url = data.video;
|
|
17
|
+
this.mime_type = 'video/mp4';
|
|
18
|
+
this.thumb_url = data.video;
|
|
19
|
+
this.title = data.title ?? 'Video';
|
|
20
|
+
this.caption = data.caption;
|
|
21
|
+
this.parse_mode = data.parse_mode;
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import TelegramInlineQueryResult from './TelegramInlineQueryResult.js';
|
|
2
|
+
export default class TelegramInlineQueryResultVoice extends TelegramInlineQueryResult {
|
|
3
|
+
voice_url: string;
|
|
4
|
+
title: string;
|
|
5
|
+
caption?: string;
|
|
6
|
+
parse_mode?: string;
|
|
7
|
+
constructor(data: {
|
|
8
|
+
voice: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
caption?: string;
|
|
11
|
+
parse_mode?: string;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import TelegramInlineQueryResult from './TelegramInlineQueryResult.js';
|
|
2
|
+
export default class TelegramInlineQueryResultVoice extends TelegramInlineQueryResult {
|
|
3
|
+
voice_url;
|
|
4
|
+
title;
|
|
5
|
+
caption;
|
|
6
|
+
parse_mode;
|
|
7
|
+
constructor(data) {
|
|
8
|
+
super('voice');
|
|
9
|
+
this.voice_url = data.voice;
|
|
10
|
+
this.title = data.title ?? 'Voice';
|
|
11
|
+
this.caption = data.caption;
|
|
12
|
+
this.parse_mode = data.parse_mode;
|
|
13
|
+
}
|
|
14
|
+
}
|