@aracna/telegram-bot 1.9.13 → 2.0.1

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.
Files changed (173) hide show
  1. package/apis/telegram-api.d.ts +9 -0
  2. package/apis/telegram-api.js +55 -0
  3. package/apis/telegram-file-api.d.ts +7 -0
  4. package/apis/telegram-file-api.js +14 -0
  5. package/classes/client.d.ts +46 -0
  6. package/classes/client.js +409 -0
  7. package/definitions/constants.d.ts +10 -0
  8. package/definitions/constants.js +53 -1
  9. package/definitions/enums.d.ts +1 -20
  10. package/definitions/enums.js +2 -22
  11. package/definitions/interfaces.d.ts +91 -75
  12. package/definitions/interfaces.js +0 -1
  13. package/definitions/telegram-api-definitions.d.ts +12 -0
  14. package/definitions/telegram-api-definitions.js +2 -0
  15. package/definitions/types.d.ts +4 -3
  16. package/index.d.ts +656 -416
  17. package/index.js +236 -20
  18. package/loggers/class-logger.d.ts +2 -0
  19. package/loggers/{module.logger.js → class-logger.js} +2 -2
  20. package/package.json +13 -4
  21. package/requests/add-requests.d.ts +3 -0
  22. package/requests/add-requests.js +14 -0
  23. package/requests/answer-requests.d.ts +7 -0
  24. package/requests/answer-requests.js +23 -0
  25. package/requests/approve-requests.d.ts +3 -0
  26. package/requests/approve-requests.js +7 -0
  27. package/requests/ban-requests.d.ts +4 -0
  28. package/requests/ban-requests.js +11 -0
  29. package/requests/close-requests.d.ts +4 -0
  30. package/requests/close-requests.js +11 -0
  31. package/requests/copy-requests.d.ts +4 -0
  32. package/requests/copy-requests.js +11 -0
  33. package/requests/create-requests.d.ts +7 -0
  34. package/requests/create-requests.js +30 -0
  35. package/requests/decline-requests.d.ts +3 -0
  36. package/requests/decline-requests.js +7 -0
  37. package/requests/delete-requests.d.ts +10 -0
  38. package/requests/delete-requests.js +35 -0
  39. package/requests/download-requests.d.ts +3 -0
  40. package/requests/download-requests.js +29 -0
  41. package/requests/edit-requests.d.ts +12 -0
  42. package/requests/edit-requests.js +46 -0
  43. package/requests/export-requests.d.ts +3 -0
  44. package/requests/export-requests.js +7 -0
  45. package/requests/forward-requests.d.ts +4 -0
  46. package/requests/forward-requests.js +11 -0
  47. package/requests/get-requests.d.ts +23 -0
  48. package/requests/get-requests.js +92 -0
  49. package/requests/hide-requests.d.ts +3 -0
  50. package/requests/hide-requests.js +7 -0
  51. package/requests/leave-requests.d.ts +3 -0
  52. package/requests/leave-requests.js +7 -0
  53. package/requests/log-requests.d.ts +2 -0
  54. package/requests/log-requests.js +7 -0
  55. package/requests/pin-requests.d.ts +3 -0
  56. package/requests/pin-requests.js +7 -0
  57. package/requests/promote-requests.d.ts +3 -0
  58. package/requests/promote-requests.js +7 -0
  59. package/requests/refund-requests.d.ts +3 -0
  60. package/requests/refund-requests.js +7 -0
  61. package/requests/reopen-requests.d.ts +4 -0
  62. package/requests/reopen-requests.js +11 -0
  63. package/requests/replace-requests.d.ts +3 -0
  64. package/requests/replace-requests.js +14 -0
  65. package/requests/restrict-requests.d.ts +3 -0
  66. package/requests/restrict-requests.js +7 -0
  67. package/requests/revoke-requests.d.ts +3 -0
  68. package/requests/revoke-requests.js +7 -0
  69. package/requests/send-requests.d.ts +24 -0
  70. package/requests/send-requests.js +102 -0
  71. package/requests/set-requests.d.ts +24 -0
  72. package/requests/set-requests.js +95 -0
  73. package/requests/stop-requests.d.ts +4 -0
  74. package/requests/stop-requests.js +11 -0
  75. package/requests/unban-requests.d.ts +4 -0
  76. package/requests/unban-requests.js +11 -0
  77. package/requests/unhide-requests.d.ts +3 -0
  78. package/requests/unhide-requests.js +7 -0
  79. package/requests/unpin-requests.d.ts +6 -0
  80. package/requests/unpin-requests.js +19 -0
  81. package/requests/upload-requests.d.ts +3 -0
  82. package/requests/upload-requests.js +7 -0
  83. package/requests/webhook-requests.d.ts +6 -0
  84. package/requests/webhook-requests.js +20 -0
  85. package/utils/callback-query-utils.d.ts +3 -0
  86. package/utils/callback-query-utils.js +25 -0
  87. package/utils/command-utils.d.ts +5 -0
  88. package/utils/command-utils.js +28 -0
  89. package/utils/context-utils.d.ts +11 -0
  90. package/utils/context-utils.js +42 -0
  91. package/utils/html-utils.d.ts +2 -0
  92. package/utils/html-utils.js +18 -0
  93. package/utils/inline-keyboard-utils.d.ts +12 -0
  94. package/utils/inline-keyboard-utils.js +43 -0
  95. package/utils/reply-to-message-utils.d.ts +6 -0
  96. package/utils/reply-to-message-utils.js +36 -0
  97. package/utils/start-message-utils.d.ts +6 -0
  98. package/utils/start-message-utils.js +40 -0
  99. package/builders/button.builder.d.ts +0 -11
  100. package/builders/button.builder.js +0 -31
  101. package/childs/add.d.ts +0 -6
  102. package/childs/add.js +0 -10
  103. package/childs/answer.d.ts +0 -9
  104. package/childs/answer.js +0 -19
  105. package/childs/ban.d.ts +0 -6
  106. package/childs/ban.js +0 -10
  107. package/childs/create.d.ts +0 -6
  108. package/childs/create.js +0 -17
  109. package/childs/delete.d.ts +0 -8
  110. package/childs/delete.js +0 -19
  111. package/childs/download.d.ts +0 -8
  112. package/childs/download.js +0 -32
  113. package/childs/edit.d.ts +0 -10
  114. package/childs/edit.js +0 -22
  115. package/childs/export.d.ts +0 -5
  116. package/childs/export.js +0 -10
  117. package/childs/forward.d.ts +0 -6
  118. package/childs/forward.js +0 -15
  119. package/childs/get.d.ts +0 -15
  120. package/childs/get.js +0 -37
  121. package/childs/leave.d.ts +0 -5
  122. package/childs/leave.js +0 -10
  123. package/childs/pin.d.ts +0 -6
  124. package/childs/pin.js +0 -10
  125. package/childs/polling.d.ts +0 -9
  126. package/childs/polling.js +0 -34
  127. package/childs/privates/send.private.d.ts +0 -7
  128. package/childs/privates/send.private.js +0 -19
  129. package/childs/promote.d.ts +0 -6
  130. package/childs/promote.js +0 -10
  131. package/childs/restrict.d.ts +0 -6
  132. package/childs/restrict.js +0 -15
  133. package/childs/send.d.ts +0 -31
  134. package/childs/send.js +0 -130
  135. package/childs/set.d.ts +0 -17
  136. package/childs/set.js +0 -44
  137. package/childs/stop.d.ts +0 -7
  138. package/childs/stop.js +0 -13
  139. package/childs/unban.d.ts +0 -5
  140. package/childs/unban.js +0 -10
  141. package/childs/unpin.d.ts +0 -5
  142. package/childs/unpin.js +0 -10
  143. package/childs/upload.d.ts +0 -7
  144. package/childs/upload.js +0 -10
  145. package/childs/webhook.d.ts +0 -8
  146. package/childs/webhook.js +0 -22
  147. package/loggers/module.logger.d.ts +0 -2
  148. package/modules/api.d.ts +0 -5
  149. package/modules/api.js +0 -24
  150. package/modules/builder.d.ts +0 -4
  151. package/modules/builder.js +0 -8
  152. package/modules/child.d.ts +0 -5
  153. package/modules/child.js +0 -10
  154. package/modules/configuration.d.ts +0 -8
  155. package/modules/configuration.js +0 -10
  156. package/modules/dummy.d.ts +0 -9
  157. package/modules/dummy.js +0 -56
  158. package/modules/telegram.d.ts +0 -87
  159. package/modules/telegram.js +0 -358
  160. package/utils/callback.query.utils.d.ts +0 -5
  161. package/utils/callback.query.utils.js +0 -26
  162. package/utils/command.utils.d.ts +0 -7
  163. package/utils/command.utils.js +0 -29
  164. package/utils/context.utils.d.ts +0 -13
  165. package/utils/context.utils.js +0 -41
  166. package/utils/html.utils.d.ts +0 -5
  167. package/utils/html.utils.js +0 -20
  168. package/utils/inline.keyboard.utils.d.ts +0 -4
  169. package/utils/inline.keyboard.utils.js +0 -26
  170. package/utils/reply.to.message.utils.d.ts +0 -6
  171. package/utils/reply.to.message.utils.js +0 -27
  172. package/utils/start.utils.d.ts +0 -7
  173. package/utils/start.utils.js +0 -32
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setChatAdministratorCustomTitle = setChatAdministratorCustomTitle;
4
+ exports.setChatDescription = setChatDescription;
5
+ exports.setChatMenuButton = setChatMenuButton;
6
+ exports.setChatPermissions = setChatPermissions;
7
+ exports.setChatPhoto = setChatPhoto;
8
+ exports.setChatStickerSet = setChatStickerSet;
9
+ exports.setChatTitle = setChatTitle;
10
+ exports.setCustomEmojiStickerSetThumbnail = setCustomEmojiStickerSetThumbnail;
11
+ exports.setGameScore = setGameScore;
12
+ exports.setMessageReaction = setMessageReaction;
13
+ exports.setMyCommands = setMyCommands;
14
+ exports.setMyDefaultAdministratorRights = setMyDefaultAdministratorRights;
15
+ exports.setMyDescription = setMyDescription;
16
+ exports.setMyName = setMyName;
17
+ exports.setMyShortDescription = setMyShortDescription;
18
+ exports.setPassportDataErrors = setPassportDataErrors;
19
+ exports.setStickerEmojiList = setStickerEmojiList;
20
+ exports.setStickerKeywords = setStickerKeywords;
21
+ exports.setStickerMaskPosition = setStickerMaskPosition;
22
+ exports.setStickerPositionInSet = setStickerPositionInSet;
23
+ exports.setStickerSetThumbnail = setStickerSetThumbnail;
24
+ exports.setStickerSetTitle = setStickerSetTitle;
25
+ const telegram_api_1 = require("../apis/telegram-api");
26
+ async function setChatAdministratorCustomTitle(token, body) {
27
+ return telegram_api_1.TelegramAPI.post('setChatAdministratorCustomTitle', body, { token });
28
+ }
29
+ async function setChatDescription(token, body) {
30
+ return telegram_api_1.TelegramAPI.post('setChatDescription', body, { token });
31
+ }
32
+ async function setChatMenuButton(token, body) {
33
+ return telegram_api_1.TelegramAPI.post('setChatMenuButton', body, { token });
34
+ }
35
+ async function setChatPermissions(token, body) {
36
+ return telegram_api_1.TelegramAPI.post('setChatPermissions', body, { token });
37
+ }
38
+ async function setChatPhoto(token, body) {
39
+ return telegram_api_1.TelegramAPI.post('setChatPhoto', {
40
+ ...body,
41
+ photo: body.photo instanceof Blob ? `attach://photo_blob` : body.photo,
42
+ ...(body.photo instanceof Blob ? { photo_blob: body.photo } : {})
43
+ }, { token });
44
+ }
45
+ async function setChatStickerSet(token, body) {
46
+ return telegram_api_1.TelegramAPI.post('setChatStickerSet', body, { token });
47
+ }
48
+ async function setChatTitle(token, body) {
49
+ return telegram_api_1.TelegramAPI.post('setChatTitle', body, { token });
50
+ }
51
+ async function setCustomEmojiStickerSetThumbnail(token, body) {
52
+ return telegram_api_1.TelegramAPI.post('setCustomEmojiStickerSetThumbnail', body, { token });
53
+ }
54
+ async function setGameScore(token, body) {
55
+ return telegram_api_1.TelegramAPI.post('setGameScore', body, { token });
56
+ }
57
+ async function setMessageReaction(token, body) {
58
+ return telegram_api_1.TelegramAPI.post('setMessageReaction', body, { token });
59
+ }
60
+ async function setMyCommands(token, body) {
61
+ return telegram_api_1.TelegramAPI.post('setMyCommands', body, { token });
62
+ }
63
+ async function setMyDefaultAdministratorRights(token, body) {
64
+ return telegram_api_1.TelegramAPI.post('setMyDefaultAdministratorRights', body, { token });
65
+ }
66
+ async function setMyDescription(token, body) {
67
+ return telegram_api_1.TelegramAPI.post('setMyDescription', body, { token });
68
+ }
69
+ async function setMyName(token, body) {
70
+ return telegram_api_1.TelegramAPI.post('setMyName', body, { token });
71
+ }
72
+ async function setMyShortDescription(token, body) {
73
+ return telegram_api_1.TelegramAPI.post('setMyShortDescription', body, { token });
74
+ }
75
+ async function setPassportDataErrors(token, body) {
76
+ return telegram_api_1.TelegramAPI.post('setPassportDataErrors', body, { token });
77
+ }
78
+ async function setStickerEmojiList(token, body) {
79
+ return telegram_api_1.TelegramAPI.post('setStickerEmojiList', body, { token });
80
+ }
81
+ async function setStickerKeywords(token, body) {
82
+ return telegram_api_1.TelegramAPI.post('setStickerKeywords', body, { token });
83
+ }
84
+ async function setStickerMaskPosition(token, body) {
85
+ return telegram_api_1.TelegramAPI.post('setStickerMaskPosition', body, { token });
86
+ }
87
+ async function setStickerPositionInSet(token, body) {
88
+ return telegram_api_1.TelegramAPI.post('setStickerPositionInSet', body, { token });
89
+ }
90
+ async function setStickerSetThumbnail(token, body) {
91
+ return telegram_api_1.TelegramAPI.post('setStickerSetThumbnail', body, { token });
92
+ }
93
+ async function setStickerSetTitle(token, body) {
94
+ return telegram_api_1.TelegramAPI.post('setStickerSetTitle', body, { token });
95
+ }
@@ -0,0 +1,4 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { Message, Poll, StopMessageLiveLocation, StopPoll } from '@aracna/telegram-bot-types';
3
+ export declare function stopMessageLiveLocation(token: string, body: StopMessageLiveLocation): Promise<Message | boolean | FetchError>;
4
+ export declare function stopPoll(token: string, body: StopPoll): Promise<Poll | FetchError>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stopMessageLiveLocation = stopMessageLiveLocation;
4
+ exports.stopPoll = stopPoll;
5
+ const telegram_api_1 = require("../apis/telegram-api");
6
+ async function stopMessageLiveLocation(token, body) {
7
+ return telegram_api_1.TelegramAPI.post('stopMessageLiveLocation', body, { token });
8
+ }
9
+ async function stopPoll(token, body) {
10
+ return telegram_api_1.TelegramAPI.post('stopPoll', body, { token });
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { UnbanChatMember, UnbanChatSenderChat } from '@aracna/telegram-bot-types';
3
+ export declare function unbanChatMember(token: string, body: UnbanChatMember): Promise<boolean | FetchError>;
4
+ export declare function unbanChatSenderChat(token: string, body: UnbanChatSenderChat): Promise<boolean | FetchError>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unbanChatMember = unbanChatMember;
4
+ exports.unbanChatSenderChat = unbanChatSenderChat;
5
+ const telegram_api_1 = require("../apis/telegram-api");
6
+ async function unbanChatMember(token, body) {
7
+ return telegram_api_1.TelegramAPI.post('unbanChatMember', body, { token });
8
+ }
9
+ async function unbanChatSenderChat(token, body) {
10
+ return telegram_api_1.TelegramAPI.post('unbanChatSenderChat', body, { token });
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { HideGeneralForumTopic } from '@aracna/telegram-bot-types';
3
+ export declare function unhideGeneralForumTopic(token: string, body: HideGeneralForumTopic): Promise<boolean | FetchError>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unhideGeneralForumTopic = unhideGeneralForumTopic;
4
+ const telegram_api_1 = require("../apis/telegram-api");
5
+ async function unhideGeneralForumTopic(token, body) {
6
+ return telegram_api_1.TelegramAPI.post('unhideGeneralForumTopic', body, { token });
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { UnpinAllChatMessages, UnpinAllForumTopicMessages, UnpinAllGeneralForumTopicMessages, UnpinChatMessage } from '@aracna/telegram-bot-types';
3
+ export declare function unpinAllChatMessages(token: string, body: UnpinAllChatMessages): Promise<boolean | FetchError>;
4
+ export declare function unpinAllForumTopicMessages(token: string, body: UnpinAllForumTopicMessages): Promise<boolean | FetchError>;
5
+ export declare function unpinAllGeneralForumTopicMessages(token: string, body: UnpinAllGeneralForumTopicMessages): Promise<boolean | FetchError>;
6
+ export declare function unpinChatMessage(token: string, body: UnpinChatMessage): Promise<boolean | FetchError>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unpinAllChatMessages = unpinAllChatMessages;
4
+ exports.unpinAllForumTopicMessages = unpinAllForumTopicMessages;
5
+ exports.unpinAllGeneralForumTopicMessages = unpinAllGeneralForumTopicMessages;
6
+ exports.unpinChatMessage = unpinChatMessage;
7
+ const telegram_api_1 = require("../apis/telegram-api");
8
+ async function unpinAllChatMessages(token, body) {
9
+ return telegram_api_1.TelegramAPI.post('unpinAllChatMessages', body, { token });
10
+ }
11
+ async function unpinAllForumTopicMessages(token, body) {
12
+ return telegram_api_1.TelegramAPI.post('unpinAllForumTopicMessages', body, { token });
13
+ }
14
+ async function unpinAllGeneralForumTopicMessages(token, body) {
15
+ return telegram_api_1.TelegramAPI.post('unpinAllGeneralForumTopicMessages', body, { token });
16
+ }
17
+ async function unpinChatMessage(token, body) {
18
+ return telegram_api_1.TelegramAPI.post('unpinChatMessage', body, { token });
19
+ }
@@ -0,0 +1,3 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { File, UploadStickerFile } from '@aracna/telegram-bot-types';
3
+ export declare function uploadStickerFile(token: string, body: UploadStickerFile): Promise<File | FetchError>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadStickerFile = uploadStickerFile;
4
+ const telegram_api_1 = require("../apis/telegram-api");
5
+ async function uploadStickerFile(token, body) {
6
+ return telegram_api_1.TelegramAPI.post('uploadStickerFile', body, { token });
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { FetchError } from '@aracna/core';
2
+ import type { DeleteWebhook, SetWebhook, WebhookInfo } from '@aracna/telegram-bot-types';
3
+ export declare function closeWebhook(token: string): Promise<boolean | FetchError>;
4
+ export declare function deleteWebhook(token: string, body?: DeleteWebhook): Promise<boolean | FetchError>;
5
+ export declare function getWebhookInfo(token: string): Promise<WebhookInfo | FetchError>;
6
+ export declare function setWebhook(token: string, body: SetWebhook): Promise<boolean | FetchError>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closeWebhook = closeWebhook;
4
+ exports.deleteWebhook = deleteWebhook;
5
+ exports.getWebhookInfo = getWebhookInfo;
6
+ exports.setWebhook = setWebhook;
7
+ const telegram_api_1 = require("../apis/telegram-api");
8
+ const constants_1 = require("../definitions/constants");
9
+ async function closeWebhook(token) {
10
+ return telegram_api_1.TelegramAPI.post('close', undefined, { token });
11
+ }
12
+ async function deleteWebhook(token, body) {
13
+ return telegram_api_1.TelegramAPI.post('deleteWebhook', body, { token });
14
+ }
15
+ async function getWebhookInfo(token) {
16
+ return telegram_api_1.TelegramAPI.post('getWebhookInfo', undefined, { token });
17
+ }
18
+ async function setWebhook(token, body) {
19
+ return telegram_api_1.TelegramAPI.post('setWebhook', { allowed_updates: constants_1.DEFAULT_ALLOWED_UPDATES, ...body }, { token });
20
+ }
@@ -0,0 +1,3 @@
1
+ import type { CallbackQueryBody, EncodeCallbackQueryBodyOptions } from '../definitions/interfaces';
2
+ export declare function decodeCallbackQueryBody<T>(data?: string): CallbackQueryBody<T>;
3
+ export declare function encodeCallbackQueryBody<T>(data: T, options?: EncodeCallbackQueryBodyOptions): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeCallbackQueryBody = decodeCallbackQueryBody;
4
+ exports.encodeCallbackQueryBody = encodeCallbackQueryBody;
5
+ const core_1 = require("@aracna/core");
6
+ const constants_1 = require("../definitions/constants");
7
+ function decodeCallbackQueryBody(data) {
8
+ let body;
9
+ if (!data) {
10
+ return (0, constants_1.DEFAULT_CALLBACK_QUERY_BODY)();
11
+ }
12
+ body = (0, core_1.tc)(() => (0, core_1.decodeJSON)((0, core_1.decodeText)((0, core_1.decodeBase64)(data)), (0, constants_1.DEFAULT_DECODE_JSON_OPTIONS)()));
13
+ if (body instanceof Error)
14
+ return (0, constants_1.DEFAULT_CALLBACK_QUERY_BODY)();
15
+ return body;
16
+ }
17
+ function encodeCallbackQueryBody(data, options) {
18
+ let body;
19
+ body = {
20
+ c: options?.chatID,
21
+ d: data,
22
+ m: options?.command
23
+ };
24
+ return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
25
+ }
@@ -0,0 +1,5 @@
1
+ import type { Context } from 'vm';
2
+ import type { UpdateType } from '../definitions/types';
3
+ export declare function getCommandByContext<T extends UpdateType>(context: Context[T]): string | undefined;
4
+ export declare function getCommand(string: string | undefined): string | undefined;
5
+ export declare function omitCommand(string: string | undefined): string;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommandByContext = getCommandByContext;
4
+ exports.getCommand = getCommand;
5
+ exports.omitCommand = omitCommand;
6
+ const core_1 = require("@aracna/core");
7
+ const constants_1 = require("../definitions/constants");
8
+ function getCommandByContext(context) {
9
+ let string;
10
+ switch (true) {
11
+ case (0, core_1.hasObjectProperty)(context, 'caption'):
12
+ string = (0, core_1.getObjectProperty)(context, 'caption', '');
13
+ break;
14
+ case (0, core_1.hasObjectProperty)(context, 'text'):
15
+ string = (0, core_1.getObjectProperty)(context, 'text', '');
16
+ break;
17
+ }
18
+ return getCommand(string);
19
+ }
20
+ function getCommand(string) {
21
+ if (typeof string !== 'string') {
22
+ return;
23
+ }
24
+ return constants_1.REGEXP_COMMAND.exec(string.slice(0, 512))?.[0].slice(1);
25
+ }
26
+ function omitCommand(string) {
27
+ return string?.replace(constants_1.REGEXP_COMMAND_WITH_USERNAME, '').trim() ?? '';
28
+ }
@@ -0,0 +1,11 @@
1
+ import type { Chat, User } from '@aracna/telegram-bot-types';
2
+ import type { Context } from '../definitions/interfaces';
3
+ import type { UpdateType } from '../definitions/types';
4
+ export declare function getContextChat<T extends UpdateType>(context: Context[T]): Chat | undefined;
5
+ export declare function getContextChatID<T extends UpdateType>(context: Context[T]): bigint | number | undefined;
6
+ export declare function getContextChatType<T extends UpdateType>(context: Context[T]): string | undefined;
7
+ export declare function getContextUser<T extends UpdateType>(context: Context[T]): User | undefined;
8
+ export declare function getContextUserFirstName<T extends UpdateType>(context: Context[T]): string | undefined;
9
+ export declare function getContextUserID<T extends UpdateType>(context: Context[T]): bigint | number | undefined;
10
+ export declare function getContextUserLastName<T extends UpdateType>(context: Context[T]): string | undefined;
11
+ export declare function getContextUserUsername<T extends UpdateType>(context: Context[T]): string | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContextChat = getContextChat;
4
+ exports.getContextChatID = getContextChatID;
5
+ exports.getContextChatType = getContextChatType;
6
+ exports.getContextUser = getContextUser;
7
+ exports.getContextUserFirstName = getContextUserFirstName;
8
+ exports.getContextUserID = getContextUserID;
9
+ exports.getContextUserLastName = getContextUserLastName;
10
+ exports.getContextUserUsername = getContextUserUsername;
11
+ const core_1 = require("@aracna/core");
12
+ function getContextChat(context) {
13
+ if ((0, core_1.hasObjectProperty)(context, 'chat')) {
14
+ return (0, core_1.getObjectProperty)(context, 'chat');
15
+ }
16
+ if ((0, core_1.hasObjectProperty)(context, 'message.chat')) {
17
+ return (0, core_1.getObjectProperty)(context, 'message.chat');
18
+ }
19
+ }
20
+ function getContextChatID(context) {
21
+ return getContextChat(context)?.id;
22
+ }
23
+ function getContextChatType(context) {
24
+ return getContextChat(context)?.type;
25
+ }
26
+ function getContextUser(context) {
27
+ if ((0, core_1.hasObjectProperty)(context, 'from')) {
28
+ return (0, core_1.getObjectProperty)(context, 'from');
29
+ }
30
+ }
31
+ function getContextUserFirstName(context) {
32
+ return getContextUser(context)?.first_name;
33
+ }
34
+ function getContextUserID(context) {
35
+ return getContextUser(context)?.id;
36
+ }
37
+ function getContextUserLastName(context) {
38
+ return getContextUser(context)?.last_name;
39
+ }
40
+ function getContextUserUsername(context) {
41
+ return getContextUser(context)?.username;
42
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getProgressHTML(value: number, min?: number, max?: number, size?: number): string;
2
+ export declare function sanitizeHTML(text: string): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProgressHTML = getProgressHTML;
4
+ exports.sanitizeHTML = sanitizeHTML;
5
+ const core_1 = require("@aracna/core");
6
+ const tags = ['b', 'strong', 'i', 'em', 'u', 'ins', 's', 'strike', 'del', 'span', 'tg-spoiler', 'a', 'code', 'pre', '/', '"'];
7
+ function getProgressHTML(value, min = 0, max = 100, size = 20) {
8
+ let percentage, steps;
9
+ percentage = (0, core_1.getNumberPercentage)(value, { min, max });
10
+ steps = new Array(size).fill(0).map((_, index) => ((index * max) / size < percentage ? '=' : ' '));
11
+ return `<code>[${steps.join('')}]</code>`;
12
+ }
13
+ function sanitizeHTML(text) {
14
+ return text
15
+ .replace(/&/gm, '&amp;')
16
+ .replace(new RegExp(`<(?!(${tags.join('|')}))`, 'gm'), '&lt;')
17
+ .replace(new RegExp(`(?<!(${tags.join('|')}))>`, 'gm'), '&gt;');
18
+ }
@@ -0,0 +1,12 @@
1
+ import type { InlineKeyboardButton, LoginUrl, SwitchInlineQueryChosenChat, WebAppInfo } from '@aracna/telegram-bot-types';
2
+ import { EncodeCallbackQueryBodyOptions } from '../definitions/interfaces';
3
+ export declare function getInlineKeyboardCallbackButton<T>(text: string, data: T, options?: EncodeCallbackQueryBodyOptions): InlineKeyboardButton;
4
+ export declare function getInlineKeyboardGameButton(text: string, game: string): InlineKeyboardButton;
5
+ export declare function getInlineKeyboardLoginButton(text: string, url: string, fields?: Partial<LoginUrl>): InlineKeyboardButton;
6
+ export declare function getInlineKeyboardPayButton(text: string): InlineKeyboardButton;
7
+ export declare function getInlineKeyboardQueryButton(text: string, query: string): InlineKeyboardButton;
8
+ export declare function getInlineKeyboardQueryChosenChatButton(text: string, query: SwitchInlineQueryChosenChat): InlineKeyboardButton;
9
+ export declare function getInlineKeyboardQueryCurrentChatButton(text: string, query: string): InlineKeyboardButton;
10
+ export declare function getInlineKeyboardTextButton(text: string): InlineKeyboardButton;
11
+ export declare function getInlineKeyboardUrlButton(text: string, url: string): InlineKeyboardButton;
12
+ export declare function getInlineKeyboardWebAppButton(text: string, app: WebAppInfo): InlineKeyboardButton;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInlineKeyboardCallbackButton = getInlineKeyboardCallbackButton;
4
+ exports.getInlineKeyboardGameButton = getInlineKeyboardGameButton;
5
+ exports.getInlineKeyboardLoginButton = getInlineKeyboardLoginButton;
6
+ exports.getInlineKeyboardPayButton = getInlineKeyboardPayButton;
7
+ exports.getInlineKeyboardQueryButton = getInlineKeyboardQueryButton;
8
+ exports.getInlineKeyboardQueryChosenChatButton = getInlineKeyboardQueryChosenChatButton;
9
+ exports.getInlineKeyboardQueryCurrentChatButton = getInlineKeyboardQueryCurrentChatButton;
10
+ exports.getInlineKeyboardTextButton = getInlineKeyboardTextButton;
11
+ exports.getInlineKeyboardUrlButton = getInlineKeyboardUrlButton;
12
+ exports.getInlineKeyboardWebAppButton = getInlineKeyboardWebAppButton;
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) };
16
+ }
17
+ function getInlineKeyboardGameButton(text, game) {
18
+ return { text: text, callback_game: game };
19
+ }
20
+ function getInlineKeyboardLoginButton(text, url, fields) {
21
+ return { text: text, login_url: { url: url, ...fields } };
22
+ }
23
+ function getInlineKeyboardPayButton(text) {
24
+ return { text: text, pay: true };
25
+ }
26
+ function getInlineKeyboardQueryButton(text, query) {
27
+ return { text: text, switch_inline_query: query };
28
+ }
29
+ function getInlineKeyboardQueryChosenChatButton(text, query) {
30
+ return { text: text, switch_inline_query_chosen_chat: query };
31
+ }
32
+ function getInlineKeyboardQueryCurrentChatButton(text, query) {
33
+ return { text: text, switch_inline_query_current_chat: query };
34
+ }
35
+ function getInlineKeyboardTextButton(text) {
36
+ return { text: text };
37
+ }
38
+ function getInlineKeyboardUrlButton(text, url) {
39
+ return { text: text, url: url };
40
+ }
41
+ function getInlineKeyboardWebAppButton(text, app) {
42
+ return { text: text, web_app: app };
43
+ }
@@ -0,0 +1,6 @@
1
+ import type { MessageEntity } from '@aracna/telegram-bot-types';
2
+ import type { EncodeReplyToMessageBodyOptions, ReplyToMessageBody } from '../definitions/interfaces';
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;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeReplyToMessageBody = decodeReplyToMessageBody;
4
+ exports.encodeReplyToMessageBody = encodeReplyToMessageBody;
5
+ exports.encodeReplyToMessageBodyToAnchorTag = encodeReplyToMessageBodyToAnchorTag;
6
+ exports.encodeReplyToMessageBodyToURL = encodeReplyToMessageBodyToURL;
7
+ const core_1 = require("@aracna/core");
8
+ const constants_1 = require("../definitions/constants");
9
+ function decodeReplyToMessageBody(entities) {
10
+ let entity, encoded, body;
11
+ entity = entities[entities.length - 1];
12
+ if (!entity?.url)
13
+ return (0, constants_1.DEFAULT_REPLY_TO_MESSAGE_BODY)();
14
+ encoded = new URL(entity.url).searchParams.get('a');
15
+ if (!encoded)
16
+ return (0, constants_1.DEFAULT_REPLY_TO_MESSAGE_BODY)();
17
+ body = (0, core_1.tc)(() => (0, core_1.decodeJSON)((0, core_1.decodeText)((0, core_1.decodeBase64)(encoded)), (0, constants_1.DEFAULT_DECODE_JSON_OPTIONS)()));
18
+ if (body instanceof Error)
19
+ return (0, constants_1.DEFAULT_REPLY_TO_MESSAGE_BODY)();
20
+ return body;
21
+ }
22
+ function encodeReplyToMessageBody(data, options) {
23
+ let body;
24
+ body = {
25
+ c: options?.chatID,
26
+ d: data,
27
+ m: options?.command
28
+ };
29
+ return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
30
+ }
31
+ function encodeReplyToMessageBodyToAnchorTag(data, options) {
32
+ return `\n<a href="${encodeReplyToMessageBodyToURL(data, options)}">ㅤ</a>`;
33
+ }
34
+ function encodeReplyToMessageBodyToURL(data, options) {
35
+ return (0, core_1.appendSearchParamsToURL)('https://t.me', { a: encodeReplyToMessageBody(data, options) });
36
+ }
@@ -0,0 +1,6 @@
1
+ import type { EncodeStartBodyOptions, StartBody } from '../definitions/interfaces';
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;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeStartBody = decodeStartBody;
4
+ exports.encodeStartBody = encodeStartBody;
5
+ exports.encodeStartBodyToAnchorTag = encodeStartBodyToAnchorTag;
6
+ exports.encodeStartBodyToText = encodeStartBodyToText;
7
+ exports.encodeStartBodyToURL = encodeStartBodyToURL;
8
+ const core_1 = require("@aracna/core");
9
+ const constants_1 = require("../definitions/constants");
10
+ function decodeStartBody(text) {
11
+ let encoded, body;
12
+ if (!text) {
13
+ return (0, constants_1.DEFAULT_START_MESSAGE_BODY)();
14
+ }
15
+ encoded = text.replace('/start', '').trim();
16
+ if (encoded.length <= 0)
17
+ return (0, constants_1.DEFAULT_START_MESSAGE_BODY)();
18
+ body = (0, core_1.tc)(() => (0, core_1.decodeJSON)((0, core_1.decodeText)((0, core_1.decodeBase64)(encoded)), (0, constants_1.DEFAULT_DECODE_JSON_OPTIONS)()));
19
+ if (body instanceof Error)
20
+ return (0, constants_1.DEFAULT_START_MESSAGE_BODY)();
21
+ return body;
22
+ }
23
+ function encodeStartBody(data, options) {
24
+ let body;
25
+ body = {
26
+ c: options?.chatID,
27
+ d: data,
28
+ m: options?.command
29
+ };
30
+ return (0, core_1.encodeBase64)((0, core_1.encodeText)((0, core_1.encodeJSON)(body, (0, constants_1.DEFAULT_ENCODE_JSON_OPTIONS)(), '{}')));
31
+ }
32
+ function encodeStartBodyToAnchorTag(username, children, data, options) {
33
+ return `<a href="${encodeStartBodyToURL(username, data, options)}">${children}</a>`;
34
+ }
35
+ function encodeStartBodyToText(data, options) {
36
+ return `/start ${encodeStartBody(data, options)}`;
37
+ }
38
+ function encodeStartBodyToURL(username, data, options) {
39
+ return (0, core_1.appendSearchParamsToURL)(`https://t.me/${username}`, { start: encodeStartBody(data, options) });
40
+ }
@@ -1,11 +0,0 @@
1
- import { InlineKeyboardButton, LoginUrl } from '@aracna/telegram-bot-types';
2
- export declare class ButtonBuilder {
3
- callback<T>(text: string, data: T, type: string, chatID?: number): InlineKeyboardButton;
4
- game(text: string, game: string): InlineKeyboardButton;
5
- login(text: string, url: string, fields?: Partial<LoginUrl>): InlineKeyboardButton;
6
- pay(text: string): InlineKeyboardButton;
7
- query(text: string, query: string): InlineKeyboardButton;
8
- queryCurrentChat(text: string, query: string): InlineKeyboardButton;
9
- text(text: string): InlineKeyboardButton;
10
- url(text: string, url: string): InlineKeyboardButton;
11
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ButtonBuilder = void 0;
4
- const callback_query_utils_1 = require("../utils/callback.query.utils");
5
- class ButtonBuilder {
6
- callback(text, data, type, chatID) {
7
- return { text: text, callback_data: callback_query_utils_1.CallbackQueryUtils.encodeBody(data, type, chatID) };
8
- }
9
- game(text, game) {
10
- return { text: text, callback_game: game };
11
- }
12
- login(text, url, fields) {
13
- return { text: text, login_url: { url: url, ...fields } };
14
- }
15
- pay(text) {
16
- return { text: text, pay: true };
17
- }
18
- query(text, query) {
19
- return { text: text, switch_inline_query: query };
20
- }
21
- queryCurrentChat(text, query) {
22
- return { text: text, switch_inline_query_current_chat: query };
23
- }
24
- text(text) {
25
- return { text: text };
26
- }
27
- url(text, url) {
28
- return { text: text, url: url };
29
- }
30
- }
31
- exports.ButtonBuilder = ButtonBuilder;
package/childs/add.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { FetchError } from '@aracna/core';
2
- import { AddStickerToSet, InputSticker, Message } from '@aracna/telegram-bot-types';
3
- import { Child } from '../modules/child';
4
- export declare class Add extends Child {
5
- stickerToSet(userID: number, name: string, sticker: InputSticker, parameters: Partial<AddStickerToSet>): Promise<Message | FetchError>;
6
- }
package/childs/add.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Add = void 0;
4
- const child_1 = require("../modules/child");
5
- class Add extends child_1.Child {
6
- async stickerToSet(userID, name, sticker, parameters) {
7
- return this.telegram.api.post('addStickerToSet', { sticker: sticker, ...parameters, name: name, user_id: userID });
8
- }
9
- }
10
- exports.Add = Add;
@@ -1,9 +0,0 @@
1
- import { FetchError } from '@aracna/core';
2
- import { AnswerCallbackQuery, AnswerInlineQuery, AnswerPreCheckoutQuery, AnswerShippingQuery, InlineQueryResult } from '@aracna/telegram-bot-types';
3
- import { Child } from '../modules/child';
4
- export declare class Answer extends Child {
5
- callbackQuery(id: string, parameters?: Partial<AnswerCallbackQuery>): Promise<boolean | FetchError>;
6
- inlineQuery(id: string, results: InlineQueryResult[], parameters?: Partial<AnswerInlineQuery>): Promise<boolean | FetchError>;
7
- preCheckoutQuery(id: string, ok: boolean, parameters?: Partial<AnswerPreCheckoutQuery>): Promise<boolean | FetchError>;
8
- shippingQuery(id: string, ok: boolean, parameters?: Partial<AnswerShippingQuery>): Promise<boolean | FetchError>;
9
- }
package/childs/answer.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Answer = void 0;
4
- const child_1 = require("../modules/child");
5
- class Answer extends child_1.Child {
6
- async callbackQuery(id, parameters) {
7
- return this.telegram.api.post('answerCallbackQuery', { callback_query_id: id, ...parameters });
8
- }
9
- async inlineQuery(id, results, parameters) {
10
- return this.telegram.api.post('answerInlineQuery', { inline_query_id: id, results: results, ...parameters });
11
- }
12
- async preCheckoutQuery(id, ok, parameters) {
13
- return this.telegram.api.post('answerPreCheckoutQuery', { ok: ok, pre_checkout_query_id: id, ...parameters });
14
- }
15
- async shippingQuery(id, ok, parameters) {
16
- return this.telegram.api.post('answerShippingQuery', { ok: ok, shipping_query_id: id, ...parameters });
17
- }
18
- }
19
- exports.Answer = Answer;
package/childs/ban.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { FetchError } from '@aracna/core';
2
- import { BanChatMember } from '@aracna/telegram-bot-types';
3
- import { Child } from '../modules/child';
4
- export declare class Ban extends Child {
5
- chatMember(chatID: number, userID: number, parameters?: Partial<BanChatMember>): Promise<boolean | FetchError>;
6
- }
package/childs/ban.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ban = void 0;
4
- const child_1 = require("../modules/child");
5
- class Ban extends child_1.Child {
6
- async chatMember(chatID, userID, parameters) {
7
- return this.telegram.api.post('banChatMember', { chat_id: chatID, user_id: userID, ...parameters });
8
- }
9
- }
10
- exports.Ban = Ban;