@aracna/telegram-bot 2.0.8 → 2.0.10

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 (104) hide show
  1. package/apis/telegram-api.d.ts +1 -1
  2. package/apis/telegram-api.js +1 -64
  3. package/apis/telegram-file-api.d.ts +1 -1
  4. package/apis/telegram-file-api.js +1 -24
  5. package/classes/client.d.ts +2 -2
  6. package/classes/client.js +1 -420
  7. package/definitions/constants.d.ts +1 -1
  8. package/definitions/constants.js +1 -57
  9. package/definitions/enums.js +1 -7
  10. package/definitions/interfaces.d.ts +1 -1
  11. package/definitions/interfaces.js +0 -2
  12. package/definitions/types.d.ts +1 -1
  13. package/definitions/types.js +0 -2
  14. package/index.cjs +1 -0
  15. package/index.js +1 -273
  16. package/loggers/class-logger.js +1 -6
  17. package/package.json +6 -31
  18. package/requests/add-requests.d.ts +1 -1
  19. package/requests/add-requests.js +1 -14
  20. package/requests/answer-requests.d.ts +1 -1
  21. package/requests/answer-requests.js +1 -23
  22. package/requests/approve-requests.d.ts +1 -1
  23. package/requests/approve-requests.js +1 -7
  24. package/requests/ban-requests.d.ts +1 -1
  25. package/requests/ban-requests.js +1 -11
  26. package/requests/business-requests.d.ts +1 -1
  27. package/requests/business-requests.js +1 -63
  28. package/requests/close-requests.d.ts +1 -1
  29. package/requests/close-requests.js +1 -11
  30. package/requests/copy-requests.d.ts +1 -1
  31. package/requests/copy-requests.js +1 -11
  32. package/requests/create-requests.d.ts +1 -1
  33. package/requests/create-requests.js +1 -30
  34. package/requests/decline-requests.d.ts +1 -1
  35. package/requests/decline-requests.js +1 -7
  36. package/requests/delete-requests.d.ts +1 -1
  37. package/requests/delete-requests.js +1 -35
  38. package/requests/download-requests.d.ts +1 -1
  39. package/requests/download-requests.js +1 -29
  40. package/requests/edit-requests.d.ts +2 -2
  41. package/requests/edit-requests.js +1 -50
  42. package/requests/export-requests.d.ts +1 -1
  43. package/requests/export-requests.js +1 -7
  44. package/requests/forward-requests.d.ts +1 -1
  45. package/requests/forward-requests.js +1 -11
  46. package/requests/get-requests.d.ts +1 -1
  47. package/requests/get-requests.js +1 -88
  48. package/requests/gift-requests.d.ts +1 -1
  49. package/requests/gift-requests.js +1 -27
  50. package/requests/hide-requests.d.ts +1 -1
  51. package/requests/hide-requests.js +1 -7
  52. package/requests/leave-requests.d.ts +1 -1
  53. package/requests/leave-requests.js +1 -7
  54. package/requests/log-requests.d.ts +1 -1
  55. package/requests/log-requests.js +1 -7
  56. package/requests/pin-requests.d.ts +1 -1
  57. package/requests/pin-requests.js +1 -7
  58. package/requests/promote-requests.d.ts +1 -1
  59. package/requests/promote-requests.js +1 -7
  60. package/requests/refund-requests.d.ts +1 -1
  61. package/requests/refund-requests.js +1 -7
  62. package/requests/reopen-requests.d.ts +1 -1
  63. package/requests/reopen-requests.js +1 -11
  64. package/requests/replace-requests.d.ts +1 -1
  65. package/requests/replace-requests.js +1 -14
  66. package/requests/restrict-requests.d.ts +1 -1
  67. package/requests/restrict-requests.js +1 -7
  68. package/requests/revoke-requests.d.ts +1 -1
  69. package/requests/revoke-requests.js +1 -7
  70. package/requests/save-requests.d.ts +1 -1
  71. package/requests/save-requests.js +1 -7
  72. package/requests/send-requests.d.ts +1 -1
  73. package/requests/send-requests.js +1 -106
  74. package/requests/set-requests.d.ts +1 -1
  75. package/requests/set-requests.js +1 -99
  76. package/requests/stop-requests.d.ts +1 -1
  77. package/requests/stop-requests.js +1 -11
  78. package/requests/story-requests.d.ts +1 -1
  79. package/requests/story-requests.js +1 -15
  80. package/requests/unban-requests.d.ts +1 -1
  81. package/requests/unban-requests.js +1 -11
  82. package/requests/unhide-requests.d.ts +1 -1
  83. package/requests/unhide-requests.js +1 -7
  84. package/requests/unpin-requests.d.ts +1 -1
  85. package/requests/unpin-requests.js +1 -19
  86. package/requests/upload-requests.d.ts +1 -1
  87. package/requests/upload-requests.js +1 -7
  88. package/requests/verification-requests.d.ts +1 -1
  89. package/requests/verification-requests.js +1 -19
  90. package/requests/webhook-requests.d.ts +1 -1
  91. package/requests/webhook-requests.js +1 -20
  92. package/utils/callback-query-utils.d.ts +1 -1
  93. package/utils/callback-query-utils.js +1 -25
  94. package/utils/command-utils.d.ts +1 -1
  95. package/utils/command-utils.js +1 -28
  96. package/utils/context-utils.d.ts +2 -2
  97. package/utils/context-utils.js +1 -42
  98. package/utils/html-utils.js +1 -18
  99. package/utils/inline-keyboard-utils.d.ts +1 -1
  100. package/utils/inline-keyboard-utils.js +1 -43
  101. package/utils/reply-to-message-utils.d.ts +1 -1
  102. package/utils/reply-to-message-utils.js +1 -36
  103. package/utils/start-message-utils.d.ts +1 -1
  104. package/utils/start-message-utils.js +1 -40
@@ -1,42 +1 @@
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
- }
1
+ import{getObjectProperty as n,hasObjectProperty as r}from"@aracna/core";function o(e){if(r(e,"chat"))return n(e,"chat");if(r(e,"message.chat"))return n(e,"message.chat")}function p(e){return o(e)?.id}function d(e){return o(e)?.type}function t(e){if(r(e,"from"))return n(e,"from")}function s(e){return t(e)?.first_name}function a(e){return t(e)?.id}function f(e){return t(e)?.last_name}function x(e){return t(e)?.username}export{o as getContextChat,p as getContextChatID,d as getContextChatType,t as getContextUser,s as getContextUserFirstName,a as getContextUserID,f as getContextUserLastName,x as getContextUserUsername};
@@ -1,18 +1 @@
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
- }
1
+ import{getNumberPercentage as p}from"@aracna/core";const i=["b","strong","i","em","u","ins","s","strike","del","span","tg-spoiler","a","code","pre","/",'"'];function a(e,s=0,r=100,n=20){let t,g;return t=p(e,{min:s,max:r}),g=new Array(n).fill(0).map((m,o)=>o*r/n<t?"=":" "),`<code>[${g.join("")}]</code>`}function c(e){return e.replace(/&/gm,"&amp;").replace(new RegExp(`<(?!(${i.join("|")}))`,"gm"),"&lt;").replace(new RegExp(`(?<!(${i.join("|")}))>`,"gm"),"&gt;")}export{a as getProgressHTML,c as sanitizeHTML};
@@ -1,5 +1,5 @@
1
1
  import type { InlineKeyboardButton, LoginUrl, SwitchInlineQueryChosenChat, WebAppInfo } from '@aracna/telegram-bot-types';
2
- import { EncodeCallbackQueryBodyOptions } from '../definitions/interfaces';
2
+ import { EncodeCallbackQueryBodyOptions } from '../definitions/interfaces.js';
3
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;
@@ -1,43 +1 @@
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, options) {
15
- return { text: text, callback_data: (0, callback_query_utils_1.encodeCallbackQueryBody)(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
- }
1
+ import{encodeCallbackQueryBody as r}from"./callback-query-utils.js";function a(t,n){return{text:t,callback_data:r(n)}}function l(t,n){return{text:t,callback_game:n}}function y(t,n,e){return{text:t,login_url:{url:n,...e}}}function b(t){return{text:t,pay:!0}}function c(t,n){return{text:t,switch_inline_query:n}}function g(t,n){return{text:t,switch_inline_query_chosen_chat:n}}function d(t,n){return{text:t,switch_inline_query_current_chat:n}}function p(t){return{text:t}}function s(t,n){return{text:t,url:n}}function I(t,n){return{text:t,web_app:n}}export{a as getInlineKeyboardCallbackButton,l as getInlineKeyboardGameButton,y as getInlineKeyboardLoginButton,b as getInlineKeyboardPayButton,c as getInlineKeyboardQueryButton,g as getInlineKeyboardQueryChosenChatButton,d as getInlineKeyboardQueryCurrentChatButton,p as getInlineKeyboardTextButton,s as getInlineKeyboardUrlButton,I as getInlineKeyboardWebAppButton};
@@ -1,5 +1,5 @@
1
1
  import type { MessageEntity } from '@aracna/telegram-bot-types';
2
- import type { EncodeReplyToMessageBodyOptions, ReplyToMessageBody } from '../definitions/interfaces';
2
+ import type { EncodeReplyToMessageBodyOptions, ReplyToMessageBody } from '../definitions/interfaces.js';
3
3
  export declare function decodeReplyToMessageBody<T>(entities: MessageEntity[]): ReplyToMessageBody<T>;
4
4
  export declare function encodeReplyToMessageBody<T>(options?: EncodeReplyToMessageBodyOptions<T>): string;
5
5
  export declare function encodeReplyToMessageBodyToAnchorTag<T>(options?: EncodeReplyToMessageBodyOptions<T>): string;
@@ -1,36 +1 @@
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(options) {
23
- let body;
24
- body = {
25
- c: options?.chatID,
26
- d: options?.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(options) {
32
- return `<a href="${encodeReplyToMessageBodyToURL(options)}"> </a>`;
33
- }
34
- function encodeReplyToMessageBodyToURL(options) {
35
- return (0, core_1.appendSearchParamsToURL)('https://t.me', { a: encodeReplyToMessageBody(options) });
36
- }
1
+ import{appendSearchParamsToURL as s,decodeBase64 as d,decodeJSON as a,decodeText as y,encodeBase64 as T,encodeJSON as c,encodeText as p,tc as i}from"@aracna/core";import{DEFAULT_DECODE_JSON_OPTIONS as g,DEFAULT_ENCODE_JSON_OPTIONS as l,DEFAULT_REPLY_TO_MESSAGE_BODY as r}from"../definitions/constants.js";function R(e){let o,t,n;return o=e[e.length-1],o?.url?(t=new URL(o.url).searchParams.get("a"),t?(n=i(()=>a(y(d(t)),g())),n instanceof Error?r():n):r()):r()}function E(e){let o;return o={c:e?.chatID,d:e?.data,m:e?.command},T(p(c(o,l(),"{}")))}function m(e){return`<a href="${f(e)}">\u200A</a>`}function f(e){return s("https://t.me",{a:E(e)})}export{R as decodeReplyToMessageBody,E as encodeReplyToMessageBody,m as encodeReplyToMessageBodyToAnchorTag,f as encodeReplyToMessageBodyToURL};
@@ -1,4 +1,4 @@
1
- import type { EncodeStartBodyOptions, StartBody } from '../definitions/interfaces';
1
+ import type { EncodeStartBodyOptions, StartBody } from '../definitions/interfaces.js';
2
2
  export declare function decodeStartBody<T>(text: string | undefined): StartBody<T>;
3
3
  export declare function encodeStartBody<T>(options?: EncodeStartBodyOptions): string;
4
4
  export declare function encodeStartBodyToAnchorTag<T>(username: string, children: string, options?: EncodeStartBodyOptions<T>): string;
@@ -1,40 +1 @@
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(options) {
24
- let body;
25
- body = {
26
- c: options?.chatID,
27
- d: options?.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, options) {
33
- return `<a href="${encodeStartBodyToURL(username, options)}">${children}</a>`;
34
- }
35
- function encodeStartBodyToText(options) {
36
- return `/start ${encodeStartBody(options)}`;
37
- }
38
- function encodeStartBodyToURL(username, options) {
39
- return (0, core_1.appendSearchParamsToURL)(`https://t.me/${username}`, { start: encodeStartBody(options) });
40
- }
1
+ import{appendSearchParamsToURL as d,decodeBase64 as a,decodeJSON as c,decodeText as i,encodeBase64 as T,encodeJSON as S,encodeText as s,tc as y}from"@aracna/core";import{DEFAULT_DECODE_JSON_OPTIONS as B,DEFAULT_ENCODE_JSON_OPTIONS as f,DEFAULT_START_MESSAGE_BODY as o}from"../definitions/constants.js";function u(t){let r,e;return t?(r=t.replace("/start","").trim(),r.length<=0?o():(e=y(()=>c(i(a(r)),B())),e instanceof Error?o():e)):o()}function n(t){let r;return r={c:t?.chatID,d:t?.data,m:t?.command},T(s(S(r,f(),"{}")))}function m(t,r,e){return`<a href="${p(t,e)}">${r}</a>`}function g(t){return`/start ${n(t)}`}function p(t,r){return d(`https://t.me/${t}`,{start:n(r)})}export{u as decodeStartBody,n as encodeStartBody,m as encodeStartBodyToAnchorTag,g as encodeStartBodyToText,p as encodeStartBodyToURL};