@aracna/telegram-bot 1.9.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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/builders/button.builder.js +31 -0
  4. package/childs/add.js +10 -0
  5. package/childs/answer.js +19 -0
  6. package/childs/ban.js +10 -0
  7. package/childs/create.js +17 -0
  8. package/childs/delete.js +19 -0
  9. package/childs/download.js +32 -0
  10. package/childs/edit.js +22 -0
  11. package/childs/export.js +10 -0
  12. package/childs/forward.js +15 -0
  13. package/childs/get.js +37 -0
  14. package/childs/leave.js +10 -0
  15. package/childs/pin.js +10 -0
  16. package/childs/polling.js +34 -0
  17. package/childs/privates/send.private.js +19 -0
  18. package/childs/promote.js +10 -0
  19. package/childs/restrict.js +15 -0
  20. package/childs/send.js +130 -0
  21. package/childs/set.js +44 -0
  22. package/childs/stop.js +13 -0
  23. package/childs/unban.js +10 -0
  24. package/childs/unpin.js +10 -0
  25. package/childs/upload.js +10 -0
  26. package/childs/webhook.js +22 -0
  27. package/declarations/builders/button.builder.d.ts +11 -0
  28. package/declarations/childs/add.d.ts +6 -0
  29. package/declarations/childs/answer.d.ts +9 -0
  30. package/declarations/childs/ban.d.ts +6 -0
  31. package/declarations/childs/create.d.ts +6 -0
  32. package/declarations/childs/delete.d.ts +8 -0
  33. package/declarations/childs/download.d.ts +9 -0
  34. package/declarations/childs/edit.d.ts +10 -0
  35. package/declarations/childs/export.d.ts +5 -0
  36. package/declarations/childs/forward.d.ts +6 -0
  37. package/declarations/childs/get.d.ts +15 -0
  38. package/declarations/childs/leave.d.ts +5 -0
  39. package/declarations/childs/pin.d.ts +6 -0
  40. package/declarations/childs/polling.d.ts +9 -0
  41. package/declarations/childs/privates/send.private.d.ts +7 -0
  42. package/declarations/childs/promote.d.ts +6 -0
  43. package/declarations/childs/restrict.d.ts +6 -0
  44. package/declarations/childs/send.d.ts +31 -0
  45. package/declarations/childs/set.d.ts +17 -0
  46. package/declarations/childs/stop.d.ts +7 -0
  47. package/declarations/childs/unban.d.ts +5 -0
  48. package/declarations/childs/unpin.d.ts +5 -0
  49. package/declarations/childs/upload.d.ts +7 -0
  50. package/declarations/childs/webhook.d.ts +8 -0
  51. package/declarations/definitions/constants.d.ts +2 -0
  52. package/declarations/definitions/enums.d.ts +22 -0
  53. package/declarations/definitions/interfaces.d.ts +97 -0
  54. package/declarations/definitions/types.d.ts +4 -0
  55. package/declarations/index.d.ts +12 -0
  56. package/declarations/loggers/module.logger.d.ts +2 -0
  57. package/declarations/modules/api.d.ts +5 -0
  58. package/declarations/modules/builder.d.ts +4 -0
  59. package/declarations/modules/child.d.ts +5 -0
  60. package/declarations/modules/configuration.d.ts +8 -0
  61. package/declarations/modules/dummy.d.ts +9 -0
  62. package/declarations/modules/telegram.d.ts +87 -0
  63. package/declarations/utils/callback.query.utils.d.ts +5 -0
  64. package/declarations/utils/command.utils.d.ts +8 -0
  65. package/declarations/utils/context.utils.d.ts +13 -0
  66. package/declarations/utils/html.utils.d.ts +5 -0
  67. package/declarations/utils/inline.keyboard.utils.d.ts +4 -0
  68. package/declarations/utils/reply.to.message.utils.d.ts +6 -0
  69. package/declarations/utils/start.utils.d.ts +7 -0
  70. package/definitions/constants.js +11 -0
  71. package/definitions/enums.js +27 -0
  72. package/definitions/interfaces.js +3 -0
  73. package/definitions/types.js +2 -0
  74. package/index.d.ts +498 -0
  75. package/index.js +24 -0
  76. package/loggers/module.logger.js +6 -0
  77. package/modules/api.js +26 -0
  78. package/modules/builder.js +8 -0
  79. package/modules/child.js +10 -0
  80. package/modules/configuration.js +10 -0
  81. package/modules/dummy.js +56 -0
  82. package/modules/telegram.js +353 -0
  83. package/package.json +28 -0
  84. package/utils/callback.query.utils.js +26 -0
  85. package/utils/command.utils.js +29 -0
  86. package/utils/context.utils.js +43 -0
  87. package/utils/html.utils.js +20 -0
  88. package/utils/inline.keyboard.utils.js +26 -0
  89. package/utils/reply.to.message.utils.js +27 -0
  90. package/utils/start.utils.js +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dario Sechi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ ![NPM](https://img.shields.io/npm/l/@aracna/telegram-bot)
2
+ ![npm (scoped)](https://img.shields.io/npm/v/@aracna/telegram-bot)
3
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=coverage)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
4
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
5
+ [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
6
+ [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
7
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
8
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
9
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
10
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aracna_telegram-bot&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
11
+
12
+ # Aracna Telegram Bot
13
+
14
+ This library makes building Telegram Bot back-ends a breeze by abstracting all the tedious parts and exposing a simple API to work with.
15
+
16
+ ### Documentation
17
+
18
+ You can find the telegram bot documentation on the [Aracna Website](https://aracna.dariosechi.it).
@@ -0,0 +1,31 @@
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.js ADDED
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,19 @@
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.js ADDED
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Create = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Create extends child_1.Child {
6
+ async stickerSet(userID, format, name, title, stickers, parameters) {
7
+ return this.telegram.api.post('createNewStickerSet', {
8
+ name: name,
9
+ sticker_format: format,
10
+ stickers: stickers,
11
+ title: title,
12
+ user_id: userID,
13
+ ...parameters
14
+ });
15
+ }
16
+ }
17
+ exports.Create = Create;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Delete = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Delete extends child_1.Child {
6
+ async chatPhoto(chatID) {
7
+ return this.telegram.api.post('deleteChatPhoto', { chat_id: chatID });
8
+ }
9
+ async chatStickerSet(chatID) {
10
+ return this.telegram.api.post('deleteChatStickerSet', { chat_id: chatID });
11
+ }
12
+ async message(chatID, message) {
13
+ return this.telegram.api.post('deleteMessage', { chat_id: chatID, message_id: message });
14
+ }
15
+ async stickerFromSet(sticker) {
16
+ return this.telegram.api.post('deleteStickerFromSet', { sticker: sticker });
17
+ }
18
+ }
19
+ exports.Delete = Delete;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Download = void 0;
4
+ const api_1 = require("../modules/api");
5
+ const child_1 = require("../modules/child");
6
+ class Download extends child_1.Child {
7
+ api = new api_1.API('https://api.telegram.org/file/bot' + this.telegram.token + '/');
8
+ async file(id) {
9
+ let file, buffer;
10
+ file = await this.telegram.get.file(id);
11
+ if (file instanceof Error)
12
+ return file;
13
+ buffer = await this.api.get(file.file_path || '');
14
+ if (buffer instanceof Error)
15
+ return buffer;
16
+ return buffer.data;
17
+ }
18
+ async userFirstProfilePhoto(id) {
19
+ let photos, sizes, buffer;
20
+ photos = await this.telegram.get.userProfilePhotos(id, { limit: 1 });
21
+ if (photos instanceof Error)
22
+ return photos;
23
+ sizes = photos.photos;
24
+ if (sizes.length <= 0)
25
+ return new Error(JSON.stringify(photos));
26
+ buffer = await this.file(sizes[0].reduce((r, v) => (v.height + v.width > r.height + r.width ? v : r), sizes[0][0]).file_id);
27
+ if (buffer instanceof Error)
28
+ return buffer;
29
+ return buffer;
30
+ }
31
+ }
32
+ exports.Download = Download;
package/childs/edit.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Edit = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Edit extends child_1.Child {
6
+ async messageCaption(parameters) {
7
+ return this.telegram.api.post('editMessageCaption', parameters);
8
+ }
9
+ async messageLiveLocation(latitude, longitude, parameters) {
10
+ return this.telegram.api.post('editMessageLiveLocation', { latitude: latitude, longitude: longitude, ...parameters });
11
+ }
12
+ async messageMedia(media, parameters) {
13
+ return this.telegram.api.post('editMessageText', { media: media, ...parameters });
14
+ }
15
+ async messageReplyMarkup(parameters) {
16
+ return this.telegram.api.post('editMessageReplyMarkup', parameters);
17
+ }
18
+ async messageText(text, parameters) {
19
+ return this.telegram.api.post('editMessageText', { text: text, ...parameters });
20
+ }
21
+ }
22
+ exports.Edit = Edit;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Export = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Export extends child_1.Child {
6
+ async chatInviteLink(chatID) {
7
+ return this.telegram.api.post('exportChatInviteLink', { chat_id: chatID });
8
+ }
9
+ }
10
+ exports.Export = Export;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Forward = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Forward extends child_1.Child {
6
+ async message(chatID, fromChatID, messageID, parameters) {
7
+ return this.telegram.api.post('forwardMessage', {
8
+ chat_id: chatID,
9
+ from_chat_id: fromChatID,
10
+ message_id: messageID,
11
+ ...parameters
12
+ });
13
+ }
14
+ }
15
+ exports.Forward = Forward;
package/childs/get.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Get = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Get extends child_1.Child {
6
+ async chat(id) {
7
+ return this.telegram.api.post('getChat', { chat_id: id });
8
+ }
9
+ async chatAdministrators(id) {
10
+ return this.telegram.api.post('getChatAdministrators', { chat_id: id });
11
+ }
12
+ async chatMember(chatID, userID) {
13
+ return this.telegram.api.post('getChatMember', { chat_id: chatID, user_id: userID });
14
+ }
15
+ async chatMemberCount(id) {
16
+ return this.telegram.api.post('getChatMemberCount', { chat_id: id });
17
+ }
18
+ async commands() {
19
+ return this.telegram.api.post('getMyCommands');
20
+ }
21
+ async file(id) {
22
+ return this.telegram.api.post('getFile', { file_id: id });
23
+ }
24
+ async gameHighScores(userID, parameters) {
25
+ return this.telegram.api.post('getGameHighScores', { user_id: userID, ...parameters });
26
+ }
27
+ async me() {
28
+ return this.telegram.api.post('getMe');
29
+ }
30
+ async stickerSet(name) {
31
+ return this.telegram.api.post('getStickerSet', { name: name });
32
+ }
33
+ async userProfilePhotos(id, parameters) {
34
+ return this.telegram.api.post('getUserProfilePhotos', { user_id: id, ...parameters });
35
+ }
36
+ }
37
+ exports.Get = Get;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Leave = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Leave extends child_1.Child {
6
+ async chat(id) {
7
+ return this.telegram.api.post('leaveChat', { chat_id: id });
8
+ }
9
+ }
10
+ exports.Leave = Leave;
package/childs/pin.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pin = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Pin extends child_1.Child {
6
+ async chatMessage(chatID, message, parameters) {
7
+ return this.telegram.api.post('pinChatMessage', { chat_id: chatID, message_id: message, ...parameters });
8
+ }
9
+ }
10
+ exports.Pin = Pin;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Polling = void 0;
4
+ const enums_1 = require("../definitions/enums");
5
+ const child_1 = require("../modules/child");
6
+ class Polling extends child_1.Child {
7
+ active = false;
8
+ offset = 0;
9
+ start(ms = 1000, parameters) {
10
+ this.active = true;
11
+ this.get(ms, parameters);
12
+ }
13
+ stop() {
14
+ this.active = false;
15
+ }
16
+ async get(ms, parameters) {
17
+ let body, updates;
18
+ body = {
19
+ allowed_updates: Object.values(enums_1.UpdateType).map((v) => v.toLowerCase()),
20
+ offset: this.offset,
21
+ ...parameters
22
+ };
23
+ updates = await this.telegram.api.post('getUpdates', body);
24
+ if (updates instanceof Error)
25
+ return updates;
26
+ updates.forEach((v) => this.telegram.handle(v));
27
+ this.offset = updates.length > 0 ? updates[updates.length - 1].update_id + 1 : this.offset;
28
+ if (this.active) {
29
+ setTimeout(() => this.get(ms, parameters), ms);
30
+ }
31
+ return updates;
32
+ }
33
+ }
34
+ exports.Polling = Polling;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SendPrivate = void 0;
4
+ const child_1 = require("../../modules/child");
5
+ const callback_query_utils_1 = require("../../utils/callback.query.utils");
6
+ class SendPrivate extends child_1.Child {
7
+ async buttons(chatIDs, text, buttons, parameters) {
8
+ return this.telegram.send.buttons(chatIDs[1], text, buttons.map((v) => {
9
+ let decoded;
10
+ decoded = callback_query_utils_1.CallbackQueryUtils.decodeBody(v.callback_data);
11
+ decoded.c = chatIDs[0];
12
+ return this.telegram.builder.button.callback(v.text, decoded.d, decoded.t, decoded.c);
13
+ }), parameters);
14
+ }
15
+ async repliable(chatIDs, text, data, type, parameters) {
16
+ return this.telegram.send.repliable(chatIDs[1], text, data, type, parameters, chatIDs[0]);
17
+ }
18
+ }
19
+ exports.SendPrivate = SendPrivate;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Promote = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Promote extends child_1.Child {
6
+ async chatMember(chatID, userID, parameters) {
7
+ return this.telegram.api.post('promoteChatMember', { chat_id: chatID, user_id: userID, ...parameters });
8
+ }
9
+ }
10
+ exports.Promote = Promote;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Restrict = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Restrict extends child_1.Child {
6
+ async chatMember(chatID, userID, permissions, parameters) {
7
+ return this.telegram.api.post('restrictChatMember', {
8
+ chat_id: chatID,
9
+ permissions: permissions,
10
+ user_id: userID,
11
+ ...parameters
12
+ });
13
+ }
14
+ }
15
+ exports.Restrict = Restrict;
package/childs/send.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Send = void 0;
4
+ const core_1 = require("@aracna/core");
5
+ const child_1 = require("../modules/child");
6
+ const configuration_1 = require("../modules/configuration");
7
+ const html_utils_1 = require("../utils/html.utils");
8
+ const inline_keyboard_utils_1 = require("../utils/inline.keyboard.utils");
9
+ const reply_to_message_utils_1 = require("../utils/reply.to.message.utils");
10
+ const send_private_1 = require("./privates/send.private");
11
+ class Send extends child_1.Child {
12
+ private = new send_private_1.SendPrivate(this.telegram);
13
+ async animation(chatID, file, parameters) {
14
+ return this.file(chatID, file, 'animation', parameters);
15
+ }
16
+ async audio(chatID, file, parameters) {
17
+ return this.file(chatID, file, 'audio', parameters);
18
+ }
19
+ async document(chatID, file, parameters) {
20
+ return this.file(chatID, file, 'document', parameters);
21
+ }
22
+ async buttons(chatID, text, buttons, parameters) {
23
+ return buttons.length <= 0
24
+ ? configuration_1.Configuration.handler.send.buttons.empty(chatID)
25
+ : this.message(chatID, text, {
26
+ reply_markup: {
27
+ inline_keyboard: buttons
28
+ .concat(await (0, core_1.getObjectProperty)(configuration_1.Configuration.default.buttons, inline_keyboard_utils_1.InlineKeyboardUtils.getButtonsType(buttons), async (chatID) => [])(chatID))
29
+ .map((v) => [v])
30
+ },
31
+ ...parameters
32
+ });
33
+ }
34
+ async chatAction(chatID, action) {
35
+ return this.telegram.api.post('sendChatAction', { chat_id: chatID, action: action });
36
+ }
37
+ async contact(chatID, phoneNumber, firstName, parameters) {
38
+ return this.telegram.api.post('sendContact', { chat_id: chatID, first_name: firstName, phone_number: phoneNumber, ...parameters });
39
+ }
40
+ async dice(chatID, parameters) {
41
+ return this.telegram.api.post('sendDice', { chat_id: chatID, ...parameters });
42
+ }
43
+ async game(chatID, gameShortName, parameters) {
44
+ return this.telegram.api.post('sendGame', { chat_id: chatID, game_short_name: gameShortName, ...parameters });
45
+ }
46
+ async html(chatID, text, parameters) {
47
+ return this.message(chatID, html_utils_1.HTMLUtils.sanitize(text), {
48
+ parse_mode: 'HTML',
49
+ ...parameters
50
+ });
51
+ }
52
+ async invoice(chatID, title, description, payload, providerToken, startParameter, currency, prices, parameters) {
53
+ return this.telegram.api.post('sendInvoice', {
54
+ chat_id: chatID,
55
+ currency: currency,
56
+ description: description,
57
+ payload: payload,
58
+ prices: prices,
59
+ provider_token: providerToken,
60
+ start_parameter: startParameter,
61
+ title: title,
62
+ ...parameters
63
+ });
64
+ }
65
+ async location(chatID, latitude, longitude, parameters) {
66
+ return this.telegram.api.post('sendLocation', { chat_id: chatID, latitude: latitude, longitude: longitude, ...parameters });
67
+ }
68
+ async mediaGroup(chatID, media, parameters) {
69
+ return this.telegram.api.post('sendMediaGroup', media.every((v) => v.media instanceof Buffer)
70
+ ? {
71
+ chat_id: chatID,
72
+ media: media.map((v, k) => ({ ...v, media: `attach://media_${k}` })),
73
+ ...media.reduce((r, v, k) => ({ ...r, [`media_${k}`]: v.media }), {}),
74
+ ...parameters
75
+ }
76
+ : { chat_id: chatID, media: media, ...parameters });
77
+ }
78
+ async message(chatID, text, parameters) {
79
+ return this.telegram.api.post('sendMessage', {
80
+ chat_id: chatID,
81
+ text: text,
82
+ ...parameters
83
+ });
84
+ }
85
+ async photo(chatID, file, parameters) {
86
+ return this.file(chatID, file, 'photo', parameters);
87
+ }
88
+ async poll(chatID, question, options, parameters) {
89
+ return this.telegram.api.post('sendPoll', { chat_id: chatID, options: options, question: question, ...parameters });
90
+ }
91
+ async repliable(chatID, text, data, type, parameters, fromChatID) {
92
+ return this.html(chatID, text + reply_to_message_utils_1.ReplyToMessageUtils.encodeBody(data, type, fromChatID), {
93
+ reply_markup: {
94
+ force_reply: true,
95
+ selective: true
96
+ },
97
+ ...parameters
98
+ });
99
+ }
100
+ async sticker(chatID, file, parameters) {
101
+ return this.file(chatID, file, 'sticker', parameters);
102
+ }
103
+ async venue(chatID, latitude, longitude, title, address, parameters) {
104
+ return this.telegram.api.post('sendVanue', {
105
+ address: address,
106
+ chat_id: chatID,
107
+ latitude: latitude,
108
+ longitude: longitude,
109
+ title: title,
110
+ ...parameters
111
+ });
112
+ }
113
+ async video(chatID, file, parameters) {
114
+ return this.file(chatID, file, 'video', parameters);
115
+ }
116
+ async videoNote(chatID, file, parameters) {
117
+ return this.file(chatID, file, 'video_note', parameters);
118
+ }
119
+ async voice(chatID, file, parameters) {
120
+ return this.file(chatID, file, 'voice', parameters);
121
+ }
122
+ file(chatID, data, type, parameters) {
123
+ return this.telegram.api.post('send' + (0, core_1.getPascalCaseString)(type), {
124
+ chat_id: chatID,
125
+ [type]: data,
126
+ ...parameters
127
+ });
128
+ }
129
+ }
130
+ exports.Send = Send;
package/childs/set.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Set = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Set extends child_1.Child {
6
+ async chatAdministratorCustomTitle(chatID, userID, customTitle) {
7
+ return this.telegram.api.post('setChatAdministratorCustomTitle', {
8
+ custom_title: customTitle,
9
+ chat_id: chatID,
10
+ user_id: userID
11
+ });
12
+ }
13
+ async chatDescription(chatID, description) {
14
+ return this.telegram.api.post('setChatDescription', { chat_id: chatID, description: description });
15
+ }
16
+ async chatPermissions(chatID, permissions) {
17
+ return this.telegram.api.post('setChatTitle', { chat_id: chatID, permissions: permissions });
18
+ }
19
+ async chatPhoto(chatID, photo) {
20
+ return this.telegram.api.post('setChatPhoto', { chat_id: chatID, photo: photo });
21
+ }
22
+ async chatStickerSet(chatID, stickerSetName) {
23
+ return this.telegram.api.post('setChatStickerSet', { chat_id: chatID, sticker_set_name: stickerSetName });
24
+ }
25
+ async chatTitle(chatID, title) {
26
+ return this.telegram.api.post('setChatTitle', { chat_id: chatID, title: title });
27
+ }
28
+ async commands(commands, parameters) {
29
+ return this.telegram.api.post('setMyCommands', { commands: commands, ...parameters });
30
+ }
31
+ async gameScore(userID, score, parameters) {
32
+ return this.telegram.api.post('setGameScore', { score: score, user_id: userID, ...parameters });
33
+ }
34
+ async passportDataErrors(userID, errors) {
35
+ return this.telegram.api.post('setPassportDataErrors', { errors: errors, user_id: userID });
36
+ }
37
+ async stickerPositionInSet(sticker, position) {
38
+ return this.telegram.api.post('setStickerPositionInSet', { position: position, sticker: sticker });
39
+ }
40
+ async stickerSetThumb(name, userID, parameters) {
41
+ return this.telegram.api.post('setStickerSetThumb', { name: name, user_id: userID, ...parameters });
42
+ }
43
+ }
44
+ exports.Set = Set;
package/childs/stop.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stop = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Stop extends child_1.Child {
6
+ async messageLiveLocation(parameters) {
7
+ return this.telegram.api.post('stopMessageLiveLocation', parameters);
8
+ }
9
+ async poll(chatID, message, parameters) {
10
+ return this.telegram.api.post('stopPoll', { chat_id: chatID, message_id: message, ...parameters });
11
+ }
12
+ }
13
+ exports.Stop = Stop;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Unban = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Unban extends child_1.Child {
6
+ async chatMember(chatID, userID) {
7
+ return this.telegram.api.post('unbanChatMember', { chat_id: chatID, user_id: userID });
8
+ }
9
+ }
10
+ exports.Unban = Unban;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Unpin = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Unpin extends child_1.Child {
6
+ async chatMessage(chatID) {
7
+ return this.telegram.api.post('unpinChatMessage', { chat_id: chatID });
8
+ }
9
+ }
10
+ exports.Unpin = Unpin;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Upload = void 0;
4
+ const child_1 = require("../modules/child");
5
+ class Upload extends child_1.Child {
6
+ async stickerFile(userID, format, sticker) {
7
+ return this.telegram.api.post('uploadStickerFile', { sticker: sticker, sticker_format: format, user_id: userID });
8
+ }
9
+ }
10
+ exports.Upload = Upload;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webhook = void 0;
4
+ const enums_1 = require("../definitions/enums");
5
+ const child_1 = require("../modules/child");
6
+ class Webhook extends child_1.Child {
7
+ async delete() {
8
+ return this.telegram.api.post('deleteWebhook');
9
+ }
10
+ async set(route = '', parameters) {
11
+ return this.telegram.api.post('setWebhook', {
12
+ allowed_updates: Object.values(enums_1.UpdateType).map((v) => v.toLowerCase()),
13
+ max_connections: 100,
14
+ url: this.url(route),
15
+ ...parameters
16
+ });
17
+ }
18
+ url(route) {
19
+ return 'https://' + this.telegram.hostname + ':' + this.telegram.port + '/' + route + 'bot' + this.telegram.token;
20
+ }
21
+ }
22
+ exports.Webhook = Webhook;
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,6 @@
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
+ }