@codebam/cf-workers-telegram-bot 9.4.0 → 9.4.3

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 CHANGED
@@ -6,8 +6,7 @@ CF Workers Telegram Bot
6
6
  </h3>
7
7
 
8
8
  <h6 align="center">
9
- <a href="https://codebam.github.io/cf-workers-telegram-bot/">Docs</a>
10
- <a href="https://github.com/codebam/cf-workers-telegram-bot/wiki">Wiki</a>
9
+ <a href="https://cf-workers-telegram-bot.codebam.ca">Docs</a>
11
10
  </h6>
12
11
 
13
12
  <p align="center">
package/dist/main.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import TelegramBot from './telegram_bot.js';
2
2
  import TelegramExecutionContext from './telegram_execution_context.js';
3
3
  import Webhook from './webhook.js';
4
- import TelegramApi from './telegram_api.js';
4
+ import TelegramApi, { TelegramApiBaseParams, SendMessageParams, SendMessageDraftParams, SendPhotoParams, SendVideoParams, SendChatActionParams, AnswerCallbackParams, AnswerInlineParams, AnswerGuestParams, SendInvoiceParams, AnswerPreCheckoutParams, TelegramApiParams } from './telegram_api.js';
5
5
  import TelegramCommand from './types/TelegramCommand.js';
6
6
  import TelegramFrom from './types/TelegramFrom.js';
7
7
  import TelegramChat from './types/TelegramChat.js';
@@ -18,6 +18,12 @@ import TelegramInlineQueryType from './types/TelegramInlineQueryType.js';
18
18
  import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
19
19
  import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
20
20
  import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
21
+ import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
21
22
  import ChatPermissions from './types/ChatPermissions.js';
23
+ import TelegramBusinessMessage from './types/TelegramBusinessMessage.js';
24
+ import TelegramCallbackQuery from './types/TelegramCallbackQuery.js';
25
+ import TelegramPreCheckoutQuery from './types/TelegramPreCheckoutQuery.js';
26
+ import TelegramDocument from './types/TelegramDocument.js';
27
+ import TelegramSuccessfulPayment from './types/TelegramSuccessfulPayment.js';
22
28
  export default TelegramBot;
23
- export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramCommand, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramGuestMessage, TelegramInputMessageContent, TelegramInlineQuery, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, ChatPermissions, };
29
+ export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramApiBaseParams, SendMessageParams, SendMessageDraftParams, SendPhotoParams, SendVideoParams, SendChatActionParams, AnswerCallbackParams, AnswerInlineParams, AnswerGuestParams, SendInvoiceParams, AnswerPreCheckoutParams, TelegramApiParams, TelegramCommand, TelegramFrom, TelegramChat, TelegramUser, TelegramMessageEntity, TelegramPhotoSize, TelegramMessage, TelegramGuestMessage, TelegramInputMessageContent, TelegramInlineQuery, TelegramUpdate, PartialTelegramUpdate, TelegramInlineQueryType, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, ChatPermissions, TelegramBusinessMessage, TelegramCallbackQuery, TelegramPreCheckoutQuery, TelegramDocument, TelegramSuccessfulPayment, };
package/dist/main.js CHANGED
@@ -6,5 +6,6 @@ import TelegramUpdate from './types/TelegramUpdate.js';
6
6
  import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js';
7
7
  import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
8
8
  import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js';
9
+ import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
9
10
  export default TelegramBot;
10
- export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramUpdate, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, };
11
+ export { TelegramBot, TelegramExecutionContext, Webhook, TelegramApi, TelegramUpdate, TelegramInlineQueryResult, TelegramInlineQueryResultPhoto, TelegramInlineQueryResultArticle, TelegramInlineQueryResultVideo, };
@@ -2,12 +2,13 @@ import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultA
2
2
  import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js';
3
3
  import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js';
4
4
  /** Interface for common Telegram API parameters */
5
- interface TelegramApiBaseParams {
5
+ export interface TelegramApiBaseParams {
6
6
  chat_id: number | string;
7
+ message_thread_id?: number;
7
8
  business_connection_id?: string | number;
8
9
  }
9
10
  /** Interface for message parameters */
10
- interface SendMessageParams extends TelegramApiBaseParams {
11
+ export interface SendMessageParams extends TelegramApiBaseParams {
11
12
  text: string;
12
13
  parse_mode: string;
13
14
  reply_to_message_id?: number | string;
@@ -17,11 +18,11 @@ interface SendMessageParams extends TelegramApiBaseParams {
17
18
  reply_markup?: object;
18
19
  }
19
20
  /** Interface for message draft parameters */
20
- interface SendMessageDraftParams extends SendMessageParams {
21
+ export interface SendMessageDraftParams extends SendMessageParams {
21
22
  draft_id: number;
22
23
  }
23
24
  /** Interface for photo parameters */
24
- interface SendPhotoParams extends TelegramApiBaseParams {
25
+ export interface SendPhotoParams extends TelegramApiBaseParams {
25
26
  photo: string;
26
27
  caption?: string;
27
28
  parse_mode?: string;
@@ -31,7 +32,7 @@ interface SendPhotoParams extends TelegramApiBaseParams {
31
32
  reply_markup?: object;
32
33
  }
33
34
  /** Interface for video parameters */
34
- interface SendVideoParams extends TelegramApiBaseParams {
35
+ export interface SendVideoParams extends TelegramApiBaseParams {
35
36
  video: string;
36
37
  caption?: string;
37
38
  parse_mode?: string;
@@ -41,11 +42,11 @@ interface SendVideoParams extends TelegramApiBaseParams {
41
42
  reply_markup?: object;
42
43
  }
43
44
  /** Interface for chat action parameters */
44
- interface SendChatActionParams extends TelegramApiBaseParams {
45
+ export interface SendChatActionParams extends TelegramApiBaseParams {
45
46
  action: string;
46
47
  }
47
48
  /** Interface for callback query parameters */
48
- interface AnswerCallbackParams {
49
+ export interface AnswerCallbackParams {
49
50
  callback_query_id: number | string;
50
51
  text?: string;
51
52
  show_alert?: boolean;
@@ -53,7 +54,7 @@ interface AnswerCallbackParams {
53
54
  cache_time?: number;
54
55
  }
55
56
  /** Interface for inline query parameters */
56
- interface AnswerInlineParams {
57
+ export interface AnswerInlineParams {
57
58
  inline_query_id: number | string;
58
59
  results: TelegramInlineQueryResultArticle[] | TelegramInlineQueryResultPhoto[] | TelegramInlineQueryResultVideo[];
59
60
  cache_time?: number;
@@ -61,12 +62,12 @@ interface AnswerInlineParams {
61
62
  next_offset?: string;
62
63
  }
63
64
  /** Interface for guest query parameters */
64
- interface AnswerGuestParams {
65
+ export interface AnswerGuestParams {
65
66
  guest_query_id: string;
66
67
  result: TelegramInlineQueryResultArticle | TelegramInlineQueryResultPhoto | TelegramInlineQueryResultVideo;
67
68
  }
68
69
  /** Interface for invoice parameters */
69
- interface SendInvoiceParams extends TelegramApiBaseParams {
70
+ export interface SendInvoiceParams extends TelegramApiBaseParams {
70
71
  title: string;
71
72
  description: string;
72
73
  payload: string;
@@ -78,13 +79,13 @@ interface SendInvoiceParams extends TelegramApiBaseParams {
78
79
  }[];
79
80
  }
80
81
  /** Interface for pre-checkout query parameters */
81
- interface AnswerPreCheckoutParams {
82
+ export interface AnswerPreCheckoutParams {
82
83
  pre_checkout_query_id: string;
83
84
  ok: boolean;
84
85
  error_message?: string;
85
86
  }
86
87
  /** Type for all possible API parameters */
87
- type TelegramApiParams = SendMessageParams | SendPhotoParams | SendVideoParams | SendChatActionParams | AnswerCallbackParams | AnswerInlineParams | AnswerGuestParams | SendInvoiceParams | AnswerPreCheckoutParams | Record<string, unknown>;
88
+ export type TelegramApiParams = SendMessageParams | SendPhotoParams | SendVideoParams | SendChatActionParams | AnswerCallbackParams | AnswerInlineParams | AnswerGuestParams | SendInvoiceParams | AnswerPreCheckoutParams | Record<string, unknown>;
88
89
  /** Class representing the Telegram API and all its methods */
89
90
  export default class TelegramApi {
90
91
  /**
@@ -203,4 +204,3 @@ export default class TelegramApi {
203
204
  */
204
205
  answerPreCheckoutQuery(botApi: string, data: AnswerPreCheckoutParams): Promise<Response>;
205
206
  }
206
- export {};
@@ -32,6 +32,11 @@ export default class TelegramExecutionContext {
32
32
  * @returns The message ID as a string or empty string if not available
33
33
  */
34
34
  private getMessageId;
35
+ /**
36
+ * Get the message thread ID from the current update
37
+ * @returns The message thread ID as a number or undefined
38
+ */
39
+ private getThreadId;
35
40
  /**
36
41
  * Reply to the last message with a video
37
42
  * @param video - string to a video on the internet or a file_id on telegram
@@ -85,6 +85,13 @@ export default class TelegramExecutionContext {
85
85
  }
86
86
  return '';
87
87
  }
88
+ /**
89
+ * Get the message thread ID from the current update
90
+ * @returns The message thread ID as a number or undefined
91
+ */
92
+ getThreadId() {
93
+ return this.update.message?.message_thread_id;
94
+ }
88
95
  /**
89
96
  * Reply to the last message with a video
90
97
  * @param video - string to a video on the internet or a file_id on telegram
@@ -98,6 +105,7 @@ export default class TelegramExecutionContext {
98
105
  return await this.api.sendVideo(this.bot.api.toString(), {
99
106
  ...options,
100
107
  chat_id: this.getChatId(),
108
+ message_thread_id: this.getThreadId(),
101
109
  reply_to_message_id: this.getMessageId(),
102
110
  video,
103
111
  });
@@ -134,6 +142,7 @@ export default class TelegramExecutionContext {
134
142
  return await this.api.sendPhoto(this.bot.api.toString(), {
135
143
  ...options,
136
144
  chat_id: this.getChatId(),
145
+ message_thread_id: this.getThreadId(),
137
146
  reply_to_message_id: this.getMessageId(),
138
147
  photo,
139
148
  caption,
@@ -156,15 +165,16 @@ export default class TelegramExecutionContext {
156
165
  case 'message':
157
166
  case 'photo':
158
167
  case 'document':
159
- case 'guest_message':
160
168
  return await this.api.sendChatAction(this.bot.api.toString(), {
161
169
  chat_id: this.getChatId(),
170
+ message_thread_id: this.getThreadId(),
162
171
  action: 'typing',
163
172
  });
164
173
  case 'business_message':
165
174
  return await this.api.sendChatAction(this.bot.api.toString(), {
166
175
  business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
167
176
  chat_id: this.getChatId(),
177
+ message_thread_id: this.getThreadId(),
168
178
  action: 'typing',
169
179
  });
170
180
  default:
@@ -210,6 +220,7 @@ export default class TelegramExecutionContext {
210
220
  return await this.api.sendMessageDraft(this.bot.api.toString(), {
211
221
  ...options,
212
222
  chat_id: this.getChatId(),
223
+ message_thread_id: this.getThreadId(),
213
224
  text: message,
214
225
  parse_mode,
215
226
  draft_id,
@@ -235,6 +246,7 @@ export default class TelegramExecutionContext {
235
246
  return await this.api.sendMessage(this.bot.api.toString(), {
236
247
  ...options,
237
248
  chat_id: this.getChatId(),
249
+ message_thread_id: this.getThreadId(),
238
250
  reply_to_message_id: this.getMessageId(),
239
251
  text: message,
240
252
  parse_mode,
@@ -243,12 +255,14 @@ export default class TelegramExecutionContext {
243
255
  return await this.api.sendMessage(this.bot.api.toString(), {
244
256
  ...options,
245
257
  chat_id: this.getChatId(),
258
+ message_thread_id: this.getThreadId(),
246
259
  text: message,
247
260
  parse_mode,
248
261
  });
249
262
  case 'business_message':
250
263
  return await this.api.sendMessage(this.bot.api.toString(), {
251
264
  chat_id: this.getChatId(),
265
+ message_thread_id: this.getThreadId(),
252
266
  text: message,
253
267
  business_connection_id: this.update.business_message?.business_connection_id.toString() ?? '',
254
268
  parse_mode,
@@ -258,6 +272,7 @@ export default class TelegramExecutionContext {
258
272
  return await this.api.sendMessage(this.bot.api.toString(), {
259
273
  ...options,
260
274
  chat_id: this.update.callback_query.message.chat.id.toString(),
275
+ message_thread_id: this.getThreadId(),
261
276
  text: message,
262
277
  parse_mode,
263
278
  });
@@ -280,6 +295,7 @@ export default class TelegramExecutionContext {
280
295
  async sendStarsInvoice(title, description, payload, amount) {
281
296
  return await this.api.sendInvoice(this.bot.api.toString(), {
282
297
  chat_id: this.getChatId(),
298
+ message_thread_id: this.getThreadId(),
283
299
  title,
284
300
  description,
285
301
  payload,
@@ -7,3 +7,4 @@ export interface TelegramDocument {
7
7
  file_unique_id: string;
8
8
  file_size: number;
9
9
  }
10
+ export default TelegramDocument;
@@ -7,6 +7,7 @@ import TelegramUser from './TelegramUser.js';
7
7
  import TelegramSuccessfulPayment from './TelegramSuccessfulPayment.js';
8
8
  interface TelegramMessage {
9
9
  message_id: number;
10
+ message_thread_id?: number;
10
11
  from: TelegramFrom;
11
12
  sender_chat?: TelegramChat;
12
13
  date: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "9.4.0",
3
+ "version": "9.4.3",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",
@@ -48,5 +48,10 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "typedoc": "0.28.19"
51
+ },
52
+ "typedocOptions": {
53
+ "entryPoints": [
54
+ "./src/main.ts"
55
+ ]
51
56
  }
52
57
  }