@aracna/telegram-bot 2.0.1 → 2.0.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.
@@ -1,11 +1,11 @@
1
1
  import type { BusinessConnection, BusinessMessagesDeleted, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, ChatMemberUpdated, ChosenInlineResult, DeleteWebhook, EditMessageMedia, GetUpdates, InlineQuery, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo, Message, MessageReactionCountUpdated, MessageReactionUpdated, CallbackQuery as NativeCallbackQuery, Poll, PollAnswer, PreCheckoutQuery, SendMediaGroup, SendMessage, SendPaidMedia, SetWebhook, ShippingQuery } from '@aracna/telegram-bot-types';
2
2
  import type { ClientListenerMiddleware, InputFile, UpdateType } from './types';
3
- export interface CallbackQuery<T = unknown> extends NativeCallbackQuery {
3
+ export interface CallbackQuery<T = any> extends NativeCallbackQuery {
4
4
  body: CallbackQueryBody<T>;
5
5
  }
6
- export interface CallbackQueryBody<T = unknown> {
6
+ export interface CallbackQueryBody<T = any> {
7
7
  c?: bigint | number;
8
- d: T;
8
+ d?: T;
9
9
  m?: string;
10
10
  }
11
11
  export interface ClientConnectionOptions {
@@ -66,17 +66,20 @@ export interface Context {
66
66
  export interface EditMessageMediaAlternative extends Omit<EditMessageMedia, 'media'> {
67
67
  media: InputMediaAlternative;
68
68
  }
69
- export interface EncodeCallbackQueryBodyOptions {
69
+ export interface EncodeCallbackQueryBodyOptions<T = any> {
70
70
  chatID?: bigint | number;
71
71
  command?: string;
72
+ data?: T;
72
73
  }
73
- export interface EncodeReplyToMessageBodyOptions {
74
+ export interface EncodeReplyToMessageBodyOptions<T = any> {
74
75
  chatID?: bigint | number;
75
76
  command?: string;
77
+ data?: T;
76
78
  }
77
- export interface EncodeStartBodyOptions {
79
+ export interface EncodeStartBodyOptions<T = any> {
78
80
  chatID?: bigint | number;
79
81
  command?: string;
82
+ data?: T;
80
83
  }
81
84
  export interface InputMediaAlternative extends Omit<InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo, 'media'> {
82
85
  media: InputFile;
@@ -84,12 +87,12 @@ export interface InputMediaAlternative extends Omit<InputMediaAudio | InputMedia
84
87
  export interface InputPaidMediaAlternative extends Omit<InputMediaPhoto | InputMediaVideo, 'media'> {
85
88
  media: InputFile;
86
89
  }
87
- export interface ReplyToMessage<T = unknown> extends Message {
90
+ export interface ReplyToMessage<T = any> extends Message {
88
91
  body: ReplyToMessageBody<T>;
89
92
  }
90
- export interface ReplyToMessageBody<T = unknown> {
93
+ export interface ReplyToMessageBody<T = any> {
91
94
  c?: bigint | number;
92
- d: T;
95
+ d?: T;
93
96
  m?: string;
94
97
  }
95
98
  export interface SendMediaGroupAlternative extends Omit<SendMediaGroup, 'media'> {
@@ -98,16 +101,16 @@ export interface SendMediaGroupAlternative extends Omit<SendMediaGroup, 'media'>
98
101
  export interface SendPaidMediaAlternative extends Omit<SendPaidMedia, 'media'> {
99
102
  media: InputPaidMediaAlternative[];
100
103
  }
101
- export interface SendRepliableMessage<T = unknown> extends SendMessage {
104
+ export interface SendRepliableMessage<T = any> extends SendMessage {
102
105
  command?: string;
103
106
  data: T;
104
107
  from_chat_id?: bigint;
105
108
  }
106
- export interface Start<T = unknown> extends Message {
109
+ export interface Start<T = any> extends Message {
107
110
  body: StartBody<T>;
108
111
  }
109
- export interface StartBody<T = unknown> {
112
+ export interface StartBody<T = any> {
110
113
  c?: bigint | number;
111
- d: T;
114
+ d?: T;
112
115
  m?: string;
113
116
  }
package/index.d.ts CHANGED
@@ -202,13 +202,13 @@ export declare function banTelegramChatMember(token: string, body: BanChatMember
202
202
 
203
203
  export declare function banTelegramChatSenderChat(token: string, body: BanChatSenderChat): Promise<boolean | FetchError>;
204
204
 
205
- export declare interface CallbackQuery<T = unknown> extends CallbackQuery_2 {
205
+ export declare interface CallbackQuery<T = any> extends CallbackQuery_2 {
206
206
  body: CallbackQueryBody<T>;
207
207
  }
208
208
 
209
- export declare interface CallbackQueryBody<T = unknown> {
209
+ export declare interface CallbackQueryBody<T = any> {
210
210
  c?: bigint | number;
211
- d: T;
211
+ d?: T;
212
212
  m?: string;
213
213
  }
214
214
 
@@ -324,36 +324,39 @@ export declare function editTelegramMessageReplyMarkup(token: string, body: Edit
324
324
 
325
325
  export declare function editTelegramMessageText(token: string, body: EditMessageText): Promise<Message | FetchError>;
326
326
 
327
- export declare function encodeTelegramCallbackQueryBody<T>(data: T, options?: EncodeTelegramCallbackQueryBodyOptions): string;
327
+ export declare function encodeTelegramCallbackQueryBody<T>(options?: EncodeTelegramCallbackQueryBodyOptions<T>): string;
328
328
 
329
- export declare interface EncodeTelegramCallbackQueryBodyOptions {
329
+ export declare interface EncodeTelegramCallbackQueryBodyOptions<T = any> {
330
330
  chatID?: bigint | number;
331
331
  command?: string;
332
+ data?: T;
332
333
  }
333
334
 
334
- export declare function encodeTelegramReplyToMessageBody<T>(data: T, options?: EncodeTelegramReplyToMessageBodyOptions): string;
335
+ export declare function encodeTelegramReplyToMessageBody<T>(options?: EncodeTelegramReplyToMessageBodyOptions): string;
335
336
 
336
- export declare interface EncodeTelegramReplyToMessageBodyOptions {
337
+ export declare interface EncodeTelegramReplyToMessageBodyOptions<T = any> {
337
338
  chatID?: bigint | number;
338
339
  command?: string;
340
+ data?: T;
339
341
  }
340
342
 
341
- export declare function encodeTelegramReplyToMessageBodyToAnchorTag<T>(data: T, options?: EncodeTelegramReplyToMessageBodyOptions): string;
343
+ export declare function encodeTelegramReplyToMessageBodyToAnchorTag<T>(options?: EncodeTelegramReplyToMessageBodyOptions): string;
342
344
 
343
- export declare function encodeTelegramReplyToMessageBodyToURL<T>(data: T, options?: EncodeTelegramReplyToMessageBodyOptions): string;
345
+ export declare function encodeTelegramReplyToMessageBodyToURL<T>(options?: EncodeTelegramReplyToMessageBodyOptions): string;
344
346
 
345
- export declare function encodeTelegramStartBody<T>(data: T, options?: EncodeTelegramStartBodyOptions): string;
347
+ export declare function encodeTelegramStartBody<T>(options?: EncodeTelegramStartBodyOptions): string;
346
348
 
347
- export declare interface EncodeTelegramStartBodyOptions {
349
+ export declare interface EncodeTelegramStartBodyOptions<T = any> {
348
350
  chatID?: bigint | number;
349
351
  command?: string;
352
+ data?: T;
350
353
  }
351
354
 
352
- export declare function encodeTelegramStartBodyToAnchorTag<T>(username: string, children: string, data: T, options?: EncodeTelegramStartBodyOptions): string;
355
+ export declare function encodeTelegramStartBodyToAnchorTag<T>(username: string, children: string, options?: EncodeTelegramStartBodyOptions): string;
353
356
 
354
- export declare function encodeTelegramStartBodyToText<T>(data: T, options?: EncodeTelegramStartBodyOptions): string;
357
+ export declare function encodeTelegramStartBodyToText<T>(options?: EncodeTelegramStartBodyOptions): string;
355
358
 
356
- export declare function encodeTelegramStartBodyToURL<T>(username: string, data: T, options?: EncodeTelegramStartBodyOptions): string;
359
+ export declare function encodeTelegramStartBodyToURL<T>(username: string, options?: EncodeTelegramStartBodyOptions): string;
357
360
 
358
361
  export declare function exportTelegramChatInviteLink(token: string, body: ExportChatInviteLink): Promise<string | FetchError>;
359
362
 
@@ -411,7 +414,7 @@ export declare function getTelegramForumTopicIconStickers(token: string): Promis
411
414
 
412
415
  export declare function getTelegramGameHighScores(token: string, body: GetGameHighScores): Promise<GameHighScore[] | FetchError>;
413
416
 
414
- export declare function getTelegramInlineKeyboardCallbackButton<T>(text: string, data: T, options?: EncodeTelegramCallbackQueryBodyOptions): InlineKeyboardButton;
417
+ export declare function getTelegramInlineKeyboardCallbackButton<T>(text: string, options?: EncodeTelegramCallbackQueryBodyOptions): InlineKeyboardButton;
415
418
 
416
419
  export declare function getTelegramInlineKeyboardGameButton(text: string, game: string): InlineKeyboardButton;
417
420
 
@@ -481,13 +484,13 @@ export declare function reopenTelegramGeneralForumTopic(token: string, body: Reo
481
484
 
482
485
  export declare function replaceTelegramStickerInSet(token: string, body: ReplaceStickerInSet): Promise<boolean | FetchError>;
483
486
 
484
- export declare interface ReplyToMessage<T = unknown> extends Message {
487
+ export declare interface ReplyToMessage<T = any> extends Message {
485
488
  body: ReplyToMessageBody<T>;
486
489
  }
487
490
 
488
- export declare interface ReplyToMessageBody<T = unknown> {
491
+ export declare interface ReplyToMessageBody<T = any> {
489
492
  c?: bigint | number;
490
- d: T;
493
+ d?: T;
491
494
  m?: string;
492
495
  }
493
496
 
@@ -505,7 +508,7 @@ declare interface SendPaidMediaAlternative extends Omit<SendPaidMedia, 'media'>
505
508
  media: InputPaidMediaAlternative[];
506
509
  }
507
510
 
508
- export declare interface SendRepliableMessage<T = unknown> extends SendMessage {
511
+ export declare interface SendRepliableMessage<T = any> extends SendMessage {
509
512
  command?: string;
510
513
  data: T;
511
514
  from_chat_id?: bigint;
@@ -599,13 +602,13 @@ export declare function setTelegramStickerSetTitle(token: string, body: SetStick
599
602
 
600
603
  export declare function setTelegramWebhook(token: string, body: SetWebhook): Promise<boolean | FetchError>;
601
604
 
602
- export declare interface Start<T = unknown> extends Message {
605
+ export declare interface Start<T = any> extends Message {
603
606
  body: StartBody<T>;
604
607
  }
605
608
 
606
- export declare interface StartBody<T = unknown> {
609
+ export declare interface StartBody<T = any> {
607
610
  c?: bigint | number;
608
- d: T;
611
+ d?: T;
609
612
  m?: string;
610
613
  }
611
614
 
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "repository": "https://github.com/aracna/telegram-bot",
38
38
  "types": "index.d.ts",
39
- "version": "2.0.1",
39
+ "version": "2.0.3",
40
40
  "scripts": {
41
41
  "build": "rm -rf dist && pnpm tsc && pnpm api-extractor run --local",
42
42
  "prepublish": "pnpm test && pnpm build && cp LICENSE package.json README.md dist",
@@ -82,7 +82,7 @@ async function sendRepliableMessage(token, body) {
82
82
  parse_mode: 'HTML',
83
83
  reply_markup: { force_reply: true, selective: true },
84
84
  ...body,
85
- text: body.text + (0, reply_to_message_utils_1.encodeReplyToMessageBody)(body.data, { chatID: body.from_chat_id, command: body.command })
85
+ text: body.text + (0, reply_to_message_utils_1.encodeReplyToMessageBody)({ chatID: body.from_chat_id, command: body.command, data: body.data })
86
86
  });
87
87
  }
88
88
  async function sendSticker(token, body) {
@@ -1,3 +1,3 @@
1
1
  import type { CallbackQueryBody, EncodeCallbackQueryBodyOptions } from '../definitions/interfaces';
2
2
  export declare function decodeCallbackQueryBody<T>(data?: string): CallbackQueryBody<T>;
3
- export declare function encodeCallbackQueryBody<T>(data: T, options?: EncodeCallbackQueryBodyOptions): string;
3
+ export declare function encodeCallbackQueryBody<T>(options?: EncodeCallbackQueryBodyOptions<T>): string;
@@ -14,11 +14,11 @@ function decodeCallbackQueryBody(data) {
14
14
  return (0, constants_1.DEFAULT_CALLBACK_QUERY_BODY)();
15
15
  return body;
16
16
  }
17
- function encodeCallbackQueryBody(data, options) {
17
+ function encodeCallbackQueryBody(options) {
18
18
  let body;
19
19
  body = {
20
20
  c: options?.chatID,
21
- d: data,
21
+ d: options?.data,
22
22
  m: options?.command
23
23
  };
24
24
  return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
@@ -1,6 +1,6 @@
1
1
  import type { InlineKeyboardButton, LoginUrl, SwitchInlineQueryChosenChat, WebAppInfo } from '@aracna/telegram-bot-types';
2
2
  import { EncodeCallbackQueryBodyOptions } from '../definitions/interfaces';
3
- export declare function getInlineKeyboardCallbackButton<T>(text: string, data: T, options?: EncodeCallbackQueryBodyOptions): InlineKeyboardButton;
3
+ export declare function getInlineKeyboardCallbackButton<T>(text: string, options?: EncodeCallbackQueryBodyOptions): InlineKeyboardButton;
4
4
  export declare function getInlineKeyboardGameButton(text: string, game: string): InlineKeyboardButton;
5
5
  export declare function getInlineKeyboardLoginButton(text: string, url: string, fields?: Partial<LoginUrl>): InlineKeyboardButton;
6
6
  export declare function getInlineKeyboardPayButton(text: string): InlineKeyboardButton;
@@ -11,8 +11,8 @@ exports.getInlineKeyboardTextButton = getInlineKeyboardTextButton;
11
11
  exports.getInlineKeyboardUrlButton = getInlineKeyboardUrlButton;
12
12
  exports.getInlineKeyboardWebAppButton = getInlineKeyboardWebAppButton;
13
13
  const callback_query_utils_1 = require("./callback-query-utils");
14
- function getInlineKeyboardCallbackButton(text, data, options) {
15
- return { text: text, callback_data: (0, callback_query_utils_1.encodeCallbackQueryBody)(data, options) };
14
+ function getInlineKeyboardCallbackButton(text, options) {
15
+ return { text: text, callback_data: (0, callback_query_utils_1.encodeCallbackQueryBody)(options) };
16
16
  }
17
17
  function getInlineKeyboardGameButton(text, game) {
18
18
  return { text: text, callback_game: game };
@@ -1,6 +1,6 @@
1
1
  import type { MessageEntity } from '@aracna/telegram-bot-types';
2
2
  import type { EncodeReplyToMessageBodyOptions, ReplyToMessageBody } from '../definitions/interfaces';
3
3
  export declare function decodeReplyToMessageBody<T>(entities: MessageEntity[]): ReplyToMessageBody<T>;
4
- export declare function encodeReplyToMessageBody<T>(data: T, options?: EncodeReplyToMessageBodyOptions): string;
5
- export declare function encodeReplyToMessageBodyToAnchorTag<T>(data: T, options?: EncodeReplyToMessageBodyOptions): string;
6
- export declare function encodeReplyToMessageBodyToURL<T>(data: T, options?: EncodeReplyToMessageBodyOptions): string;
4
+ export declare function encodeReplyToMessageBody<T>(options?: EncodeReplyToMessageBodyOptions): string;
5
+ export declare function encodeReplyToMessageBodyToAnchorTag<T>(options?: EncodeReplyToMessageBodyOptions): string;
6
+ export declare function encodeReplyToMessageBodyToURL<T>(options?: EncodeReplyToMessageBodyOptions): string;
@@ -19,18 +19,18 @@ function decodeReplyToMessageBody(entities) {
19
19
  return (0, constants_1.DEFAULT_REPLY_TO_MESSAGE_BODY)();
20
20
  return body;
21
21
  }
22
- function encodeReplyToMessageBody(data, options) {
22
+ function encodeReplyToMessageBody(options) {
23
23
  let body;
24
24
  body = {
25
25
  c: options?.chatID,
26
- d: data,
26
+ d: options?.data,
27
27
  m: options?.command
28
28
  };
29
29
  return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
30
30
  }
31
- function encodeReplyToMessageBodyToAnchorTag(data, options) {
32
- return `\n<a href="${encodeReplyToMessageBodyToURL(data, options)}">ㅤ</a>`;
31
+ function encodeReplyToMessageBodyToAnchorTag(options) {
32
+ return `\n<a href="${encodeReplyToMessageBodyToURL(options)}">ㅤ</a>`;
33
33
  }
34
- function encodeReplyToMessageBodyToURL(data, options) {
35
- return (0, core_1.appendSearchParamsToURL)('https://t.me', { a: encodeReplyToMessageBody(data, options) });
34
+ function encodeReplyToMessageBodyToURL(options) {
35
+ return (0, core_1.appendSearchParamsToURL)('https://t.me', { a: encodeReplyToMessageBody(options) });
36
36
  }
@@ -1,6 +1,6 @@
1
1
  import type { EncodeStartBodyOptions, StartBody } from '../definitions/interfaces';
2
2
  export declare function decodeStartBody<T>(text: string | undefined): StartBody<T>;
3
- export declare function encodeStartBody<T>(data: T, options?: EncodeStartBodyOptions): string;
4
- export declare function encodeStartBodyToAnchorTag<T>(username: string, children: string, data: T, options?: EncodeStartBodyOptions): string;
5
- export declare function encodeStartBodyToText<T>(data: T, options?: EncodeStartBodyOptions): string;
6
- export declare function encodeStartBodyToURL<T>(username: string, data: T, options?: EncodeStartBodyOptions): string;
3
+ export declare function encodeStartBody<T>(options?: EncodeStartBodyOptions): string;
4
+ export declare function encodeStartBodyToAnchorTag<T>(username: string, children: string, options?: EncodeStartBodyOptions): string;
5
+ export declare function encodeStartBodyToText<T>(options?: EncodeStartBodyOptions): string;
6
+ export declare function encodeStartBodyToURL<T>(username: string, options?: EncodeStartBodyOptions): string;
@@ -20,21 +20,21 @@ function decodeStartBody(text) {
20
20
  return (0, constants_1.DEFAULT_START_MESSAGE_BODY)();
21
21
  return body;
22
22
  }
23
- function encodeStartBody(data, options) {
23
+ function encodeStartBody(options) {
24
24
  let body;
25
25
  body = {
26
26
  c: options?.chatID,
27
- d: data,
27
+ d: options?.data,
28
28
  m: options?.command
29
29
  };
30
30
  return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
31
31
  }
32
- function encodeStartBodyToAnchorTag(username, children, data, options) {
33
- return `<a href="${encodeStartBodyToURL(username, data, options)}">${children}</a>`;
32
+ function encodeStartBodyToAnchorTag(username, children, options) {
33
+ return `<a href="${encodeStartBodyToURL(username, options)}">${children}</a>`;
34
34
  }
35
- function encodeStartBodyToText(data, options) {
36
- return `/start ${encodeStartBody(data, options)}`;
35
+ function encodeStartBodyToText(options) {
36
+ return `/start ${encodeStartBody(options)}`;
37
37
  }
38
- function encodeStartBodyToURL(username, data, options) {
39
- return (0, core_1.appendSearchParamsToURL)(`https://t.me/${username}`, { start: encodeStartBody(data, options) });
38
+ function encodeStartBodyToURL(username, options) {
39
+ return (0, core_1.appendSearchParamsToURL)(`https://t.me/${username}`, { start: encodeStartBody(options) });
40
40
  }