Skip to content

Commit d6c2b5a

Browse files
committed
v11.15.0
1 parent 27d2546 commit d6c2b5a

34 files changed

Lines changed: 1369 additions & 674 deletions

package-lock.json

Lines changed: 1288 additions & 138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
"webhook"
1818
],
1919
"type": "module",
20-
"private": false,
20+
"private": true,
21+
"workspaces": [
22+
"consumer",
23+
"webapp",
24+
"ai-workflow"
25+
],
2126
"publishConfig": {
2227
"access": "public"
2328
},
@@ -54,11 +59,12 @@
5459
},
5560
"dependencies": {
5661
"@eslint/eslintrc": "^3.3.5",
62+
"@grammyjs/types": "^3.27.2",
5763
"marked": "^18.0.3"
5864
},
5965
"typedocOptions": {
6066
"entryPoints": [
6167
"./src/main.ts"
6268
]
6369
}
64-
}
70+
}

src/main.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Chat as TelegramChat, User as TelegramUser, User as TelegramFrom, MessageEntity as TelegramMessageEntity, PhotoSize as TelegramPhotoSize, Message as TelegramMessage, Voice as TelegramVoice, InputMessageContent as TelegramInputMessageContent, InlineQuery as TelegramInlineQuery, Update as TelegramUpdate, InlineQueryResult as TelegramInlineQueryResult, InlineQueryResultPhoto as TelegramInlineQueryResultPhoto, InlineQueryResultArticle as TelegramInlineQueryResultArticle, InlineQueryResultVideo as TelegramInlineQueryResultVideo, InlineQueryResultVoice as TelegramInlineQueryResultVoice, ChatPermissions as ChatPermissions, Message as TelegramBusinessMessage, CallbackQuery as TelegramCallbackQuery, PreCheckoutQuery as TelegramPreCheckoutQuery, Document as TelegramDocument, SuccessfulPayment as TelegramSuccessfulPayment } from '@grammyjs/types';
12
import TelegramBot from './telegram_bot.js';
23
import TelegramExecutionContext from './telegram_execution_context.js';
34
import Webhook from './webhook.js';
@@ -17,30 +18,30 @@ import TelegramApi, {
1718
TelegramApiParams,
1819
} from './telegram_api.js';
1920
import TelegramCommand from './types/TelegramCommand.js';
20-
import TelegramFrom from './types/TelegramFrom.js';
21-
import TelegramChat from './types/TelegramChat.js';
22-
import TelegramUser from './types/TelegramUser.js';
23-
import TelegramMessageEntity from './types/TelegramMessageEntity.js';
24-
import TelegramPhotoSize from './types/TelegramPhotoSize.js';
25-
import TelegramMessage from './types/TelegramMessage.js';
26-
import { TelegramVoice } from './types/TelegramVoice.js';
21+
22+
23+
24+
25+
26+
27+
2728
import TelegramGuestMessage from './types/TelegramGuestMessage.js';
28-
import TelegramInputMessageContent from './types/TelegramInputMessageContent.js';
29-
import TelegramInlineQuery from './types/TelegramInlineQuery.js';
30-
import TelegramUpdate from './types/TelegramUpdate.js';
29+
30+
31+
3132
import PartialTelegramUpdate from './types/PartialTelegramUpdate.js';
3233
import TelegramInlineQueryType from './types/TelegramInlineQueryType.js';
33-
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
34-
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
35-
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
36-
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
37-
import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js';
38-
import ChatPermissions from './types/ChatPermissions.js';
39-
import TelegramBusinessMessage from './types/TelegramBusinessMessage.js';
40-
import TelegramCallbackQuery from './types/TelegramCallbackQuery.js';
41-
import TelegramPreCheckoutQuery from './types/TelegramPreCheckoutQuery.js';
42-
import TelegramDocument from './types/TelegramDocument.js';
43-
import TelegramSuccessfulPayment from './types/TelegramSuccessfulPayment.js';
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
4445
import { markdownToHtml, fetchTool } from './utils.js';
4546

4647
export default TelegramBot;

src/telegram_api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
1+
import { InlineQueryResult as TelegramInlineQueryResult } from '@grammyjs/types';
2+
23

34
/** Interface for common Telegram API parameters */
45
export interface TelegramApiBaseParams {

src/telegram_bot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import TelegramUpdate from './types/TelegramUpdate.js';
1+
import { Update as TelegramUpdate } from '@grammyjs/types';
2+
23
import TelegramExecutionContext from './telegram_execution_context.js';
34
import Webhook from './webhook.js';
45

@@ -11,8 +12,7 @@ export default class TelegramBot {
1112
/** The telegram webhook object */
1213
webhook: Webhook = new Webhook('', new Request('http://127.0.0.1'));
1314
/** The telegram update object */
14-
update: TelegramUpdate = new TelegramUpdate({});
15-
/** The telegram commands record map */
15+
update: TelegramUpdate = { update_id: 0 } as TelegramUpdate; /** The telegram commands record map */
1616
commands: Record<string, (ctx: TelegramExecutionContext) => Promise<Response | void>> = {};
1717
/** Middleware functions to run before handlers */
1818
middleware: ((ctx: TelegramExecutionContext) => Promise<Response | void>)[] = [];

src/telegram_execution_context.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { Update as TelegramUpdate, InlineQueryResult as TelegramInlineQueryResult, ParseMode } from '@grammyjs/types';
12
import TelegramApi from './telegram_api.js';
23
import TelegramBot from './telegram_bot.js';
3-
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
4-
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
5-
import TelegramUpdate from './types/TelegramUpdate.js';
6-
import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
7-
import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js';
8-
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
4+
5+
6+
7+
8+
9+
910

1011
/** Class representing the context of execution */
1112
export default class TelegramExecutionContext {
@@ -54,7 +55,7 @@ export default class TelegramExecutionContext {
5455
* @returns The user ID or undefined if not available
5556
*/
5657
get userId(): number | undefined {
57-
return this.update.message?.from.id ?? this.update.business_message?.from.id ?? this.update.guest_message?.from.id;
58+
return this.update.message?.from?.id ?? this.update.business_message?.from?.id ?? this.update.guest_message?.from?.id;
5859
}
5960

6061
/**
@@ -163,7 +164,7 @@ export default class TelegramExecutionContext {
163164
...options,
164165
chat_id: this.getChatId(),
165166
message_thread_id: this.getThreadId(),
166-
business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
167+
business_connection_id: this.update.business_message?.business_connection_id?.toString() ?? '',
167168
video,
168169
});
169170
case 'guest_message':
@@ -172,7 +173,7 @@ export default class TelegramExecutionContext {
172173
return await this.api.answerInline(this.bot.api.toString(), {
173174
...options,
174175
inline_query_id: this.update.inline_query?.id.toString() ?? '',
175-
results: [new TelegramInlineQueryResultVideo({ video })],
176+
results: [{ type: 'video', id: crypto.randomUUID(), video_url: video, mime_type: 'video/mp4', thumbnail_url: video, title: 'Video' }],
176177
});
177178

178179
default:
@@ -214,7 +215,7 @@ export default class TelegramExecutionContext {
214215
...options,
215216
chat_id: this.getChatId(),
216217
message_thread_id: this.getThreadId(),
217-
business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
218+
business_connection_id: this.update.business_message?.business_connection_id?.toString() ?? '',
218219
photo,
219220
caption,
220221
});
@@ -223,7 +224,7 @@ export default class TelegramExecutionContext {
223224
case 'inline':
224225
return await this.api.answerInline(this.bot.api.toString(), {
225226
inline_query_id: this.update.inline_query?.id.toString() ?? '',
226-
results: [new TelegramInlineQueryResultPhoto({ photo })],
227+
results: [{ type: 'photo', id: crypto.randomUUID(), photo_url: photo, thumbnail_url: photo }],
227228
});
228229

229230
default:
@@ -255,7 +256,7 @@ export default class TelegramExecutionContext {
255256
...options,
256257
chat_id: this.getChatId(),
257258
message_thread_id: this.getThreadId(),
258-
business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
259+
business_connection_id: this.update.business_message?.business_connection_id?.toString() ?? '',
259260
voice,
260261
caption,
261262
});
@@ -283,7 +284,7 @@ export default class TelegramExecutionContext {
283284
});
284285
case 'business_message':
285286
return await this.api.sendChatAction(this.bot.api.toString(), {
286-
business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
287+
business_connection_id: this.update.business_message?.business_connection_id?.toString() ?? '',
287288
chat_id: this.getChatId(),
288289
message_thread_id: this.getThreadId(),
289290
action: 'typing',
@@ -304,7 +305,7 @@ export default class TelegramExecutionContext {
304305
if (this.update_type === 'inline') {
305306
return await this.api.answerInline(this.bot.api.toString(), {
306307
inline_query_id: this.update.inline_query?.id.toString() ?? '',
307-
results: [new TelegramInlineQueryResultArticle({ content: message, title, parse_mode })],
308+
results: [{ type: 'article', id: crypto.randomUUID(), title: title ?? '', input_message_content: { message_text: message, parse_mode: parse_mode as ParseMode } }],
308309
});
309310
}
310311
return null;
@@ -329,7 +330,7 @@ export default class TelegramExecutionContext {
329330
* @returns Promise with the API response
330331
*/
331332
async answerGuestQueryText(message: string, parse_mode = '') {
332-
return await this.answerGuestQuery(new TelegramInlineQueryResultArticle({ content: message, title: 'Response', parse_mode }));
333+
return await this.answerGuestQuery({ type: 'article', id: crypto.randomUUID(), title: 'Response', input_message_content: { message_text: message, parse_mode: parse_mode as ParseMode } });
333334
}
334335

335336
/**
@@ -340,7 +341,7 @@ export default class TelegramExecutionContext {
340341
* @returns Promise with the API response
341342
*/
342343
async answerGuestQueryPhoto(photo: string, caption = '', parse_mode = '') {
343-
return await this.answerGuestQuery(new TelegramInlineQueryResultPhoto({ photo, caption, parse_mode }));
344+
return await this.answerGuestQuery({ type: 'photo', id: crypto.randomUUID(), photo_url: photo, thumbnail_url: photo, caption, parse_mode: parse_mode as ParseMode });
344345
}
345346

346347
/**
@@ -351,7 +352,7 @@ export default class TelegramExecutionContext {
351352
* @returns Promise with the API response
352353
*/
353354
async answerGuestQueryVideo(video: string, caption = '', parse_mode = '') {
354-
return await this.answerGuestQuery(new TelegramInlineQueryResultVideo({ video, caption, parse_mode }));
355+
return await this.answerGuestQuery({ type: 'video', id: crypto.randomUUID(), video_url: video, mime_type: 'video/mp4', thumbnail_url: video, title: 'Video', caption, parse_mode: parse_mode as ParseMode });
355356
}
356357

357358
/**
@@ -362,7 +363,7 @@ export default class TelegramExecutionContext {
362363
* @returns Promise with the API response
363364
*/
364365
async answerGuestQueryVoice(voice: string, caption = '', parse_mode = '') {
365-
return await this.answerGuestQuery(new TelegramInlineQueryResultVoice({ voice, caption, parse_mode }));
366+
return await this.answerGuestQuery({ type: 'voice', id: crypto.randomUUID(), voice_url: voice, title: 'Voice', caption, parse_mode: parse_mode as ParseMode });
366367
}
367368

368369

@@ -384,7 +385,7 @@ export default class TelegramExecutionContext {
384385
options: Record<string, number | string | boolean | object> = {},
385386
) {
386387
const message_id = this.drafts.get(draft_id);
387-
const business_connection_id = this.update.business_message?.business_connection_id.toString();
388+
const business_connection_id = this.update.business_message?.business_connection_id?.toString();
388389

389390
if (message_id) {
390391
return await this.api.editMessageText(this.bot.api.toString(), {
@@ -466,11 +467,11 @@ export default class TelegramExecutionContext {
466467
chat_id: this.getChatId(),
467468
message_thread_id: this.getThreadId(),
468469
text: message,
469-
business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
470+
business_connection_id: this.update.business_message?.business_connection_id?.toString() ?? '',
470471
parse_mode,
471472
});
472473
case 'callback':
473-
if (this.update.callback_query?.message.chat.id) {
474+
if (this.update.callback_query?.message?.chat.id) {
474475
return await this.api.sendMessage(this.bot.api.toString(), {
475476
...options,
476477
chat_id: this.update.callback_query.message.chat.id.toString(),
@@ -499,7 +500,7 @@ export default class TelegramExecutionContext {
499500
return await this.api.sendInvoice(this.bot.api.toString(), {
500501
chat_id: this.getChatId(),
501502
message_thread_id: this.getThreadId(),
502-
business_connection_id: this.update.business_message?.business_connection_id.toString(),
503+
business_connection_id: this.update.business_message?.business_connection_id?.toString(),
503504
title,
504505
description,
505506
payload,

src/types.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
import { Chat as TelegramChat, User as TelegramUser, User as TelegramFrom, MessageEntity as TelegramMessageEntity, PhotoSize as TelegramPhotoSize, Message as TelegramMessage, InputMessageContent as TelegramInputMessageContent, InlineQuery as TelegramInlineQuery, Update as TelegramUpdate, InlineQueryResult as TelegramInlineQueryResult, InlineQueryResultPhoto as TelegramInlineQueryResultPhoto, InlineQueryResultArticle as TelegramInlineQueryResultArticle, ChatPermissions as ChatPermissions } from '@grammyjs/types';
12
import TelegramBot from './telegram_bot.js';
23
import TelegramExecutionContext from './telegram_execution_context.js';
34
import Webhook from './webhook.js';
45
import TelegramApi from './telegram_api.js';
56
import TelegramCommand from './types/TelegramCommand.js';
6-
import TelegramFrom from './types/TelegramFrom.js';
7-
import TelegramChat from './types/TelegramChat.js';
8-
import TelegramUser from './types/TelegramUser.js';
9-
import TelegramMessageEntity from './types/TelegramMessageEntity.js';
10-
import TelegramPhotoSize from './types/TelegramPhotoSize.js';
11-
import TelegramMessage from './types/TelegramMessage.js';
12-
import TelegramInputMessageContent from './types/TelegramInputMessageContent.js';
13-
import TelegramInlineQuery from './types/TelegramInlineQuery.js';
14-
import TelegramUpdate from './types/TelegramUpdate.js';
7+
8+
9+
10+
11+
12+
13+
14+
15+
1516
import PartialTelegramUpdate from './types/PartialTelegramUpdate.js';
1617
import TelegramInlineQueryType from './types/TelegramInlineQueryType.js';
17-
import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
18-
import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
19-
import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
20-
import ChatPermissions from './types/ChatPermissions.js';
18+
19+
20+
21+
2122

2223
export default TelegramBot;
2324
export {

src/types/ChatPermissions.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/types/PartialTelegramUpdate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import TelegramBusinessMessage from './TelegramBusinessMessage.js';
2-
import TelegramInlineQuery from './TelegramInlineQuery.js';
3-
import TelegramMessage from './TelegramMessage.js';
1+
import { Message as TelegramBusinessMessage } from '@grammyjs/types';
2+
import { InlineQuery as TelegramInlineQuery } from '@grammyjs/types';
3+
import { Message as TelegramMessage } from '@grammyjs/types';
44
import TelegramGuestMessage from './TelegramGuestMessage.js';
5-
import TelegramPreCheckoutQuery from './TelegramPreCheckoutQuery.js';
6-
import TelegramCallbackQuery from './TelegramCallbackQuery.js';
7-
import TelegramBusinessConnection from './TelegramBusinessConnection.js';
5+
import { PreCheckoutQuery as TelegramPreCheckoutQuery } from '@grammyjs/types';
6+
import { CallbackQuery as TelegramCallbackQuery } from '@grammyjs/types';
7+
import { BusinessConnection as TelegramBusinessConnection } from '@grammyjs/types';
88

99
interface PartialTelegramUpdate {
1010
update_id?: number;

src/types/TelegramBusinessConnection.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)