@codebam/cf-workers-telegram-bot 7.18.0 → 7.19.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.
@@ -7,7 +7,7 @@ export default class TelegramApi {
7
7
  getApiUrl(botApi: string, slug: string, data: Record<string, SerializableData>): Request<unknown, CfProperties<unknown>>;
8
8
  getFile(botApi: string, data: {
9
9
  file_id: string;
10
- }, token: string): Promise<ArrayBuffer>;
10
+ }, token: string): Promise<Response>;
11
11
  sendMessage(botApi: string, data: {
12
12
  reply_to_message_id: number | string;
13
13
  chat_id: number | string;
@@ -12,8 +12,7 @@ export default class TelegramApi {
12
12
  const response = await fetch(url);
13
13
  const json = await response.json();
14
14
  const file_path = json.result.file_path;
15
- const file_response = await fetch(`https://api.telegram.org/file/bot${token}/${file_path}`);
16
- return await file_response.arrayBuffer();
15
+ return await fetch(`https://api.telegram.org/file/bot${token}/${file_path}`);
17
16
  }
18
17
  async sendMessage(botApi, data) {
19
18
  const url = this.getApiUrl(botApi, 'sendMessage', data);
@@ -43,6 +43,10 @@ export default class TelegramBot {
43
43
  command = ':photo';
44
44
  break;
45
45
  }
46
+ case 'document': {
47
+ command = ':document';
48
+ break;
49
+ }
46
50
  default:
47
51
  break;
48
52
  }
@@ -15,7 +15,7 @@ export default class TelegramExecutionContext {
15
15
  setData(key: string, value: SerializableData): this;
16
16
  getData(key: string): SerializableData;
17
17
  replyVideo(video: string, options?: Record<string, SerializableData>): Promise<Response | undefined>;
18
- getFile(file_id: string): Promise<ArrayBuffer>;
18
+ getFile(file_id: string): Promise<Response>;
19
19
  replyPhoto(photo: string, caption?: string, options?: Record<string, SerializableData>): Promise<Response | undefined>;
20
20
  reply(message: string, parse_mode?: string, options?: Record<string, SerializableData>): Promise<Response | undefined>;
21
21
  }
@@ -20,6 +20,9 @@ export default class TelegramExecutionContext {
20
20
  else if (this.update.inline_query?.query) {
21
21
  this.update_type = 'inline';
22
22
  }
23
+ else if (this.update.message?.document) {
24
+ this.update_type = 'document';
25
+ }
23
26
  }
24
27
  getText() {
25
28
  return this.update.message?.text ?? this.update.inline_query?.query ?? '';
@@ -106,6 +109,14 @@ export default class TelegramExecutionContext {
106
109
  inline_query_id: this.update.inline_query?.id.toString() ?? '',
107
110
  results: [new TelegramInlineQueryResultArticle(message)],
108
111
  });
112
+ case 'document':
113
+ return await this.api.sendMessage(this.bot.api.toString(), {
114
+ ...options,
115
+ chat_id: this.update.message?.chat.id.toString() ?? '',
116
+ reply_to_message_id: this.update.message?.message_id.toString() ?? '',
117
+ text: message,
118
+ parse_mode,
119
+ });
109
120
  default:
110
121
  break;
111
122
  }
@@ -0,0 +1,9 @@
1
+ import TelegramPhotoSize from './TelegramPhotoSize.js';
2
+ export interface TelegramDocument {
3
+ file_name: string;
4
+ mime_type: string;
5
+ thumbnail: TelegramPhotoSize;
6
+ file_id: string;
7
+ file_unique_id: string;
8
+ file_size: number;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import TelegramChat from './TelegramChat.js';
2
+ import { TelegramDocument } from './TelegramDocument.js';
2
3
  import TelegramFrom from './TelegramFrom.js';
3
4
  import TelegramMessageEntity from './TelegramMessageEntity.js';
4
5
  import TelegramPhotoSize from './TelegramPhotoSize.js';
@@ -24,6 +25,7 @@ interface TelegramMessage {
24
25
  author_signature?: string;
25
26
  text?: string;
26
27
  entities?: TelegramMessageEntity[];
28
+ document?: TelegramDocument;
27
29
  photo?: TelegramPhotoSize[];
28
30
  caption?: string;
29
31
  caption_entities?: TelegramMessageEntity[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "7.18.0",
3
+ "version": "7.19.0",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",
@@ -44,5 +44,5 @@
44
44
  "typescript-eslint": "^7.10.0",
45
45
  "vitest": "^1.6.0"
46
46
  },
47
- "gitHead": "9403f38804403328eac9f7249bdeaccee8a4ee25"
47
+ "gitHead": "6a464429f3ce661593659db8145d5b73ac75e5e3"
48
48
  }