@aracna/telegram-bot 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +18 -18
- package/apis/telegram-api.d.ts +7 -5
- package/apis/telegram-api.js +13 -4
- package/apis/telegram-file-api.d.ts +6 -4
- package/apis/telegram-file-api.js +12 -2
- package/classes/client.js +7 -7
- package/definitions/interfaces.d.ts +12 -0
- package/index.d.ts +150 -152
- package/package.json +17 -17
- package/requests/add-requests.d.ts +2 -1
- package/requests/add-requests.js +2 -2
- package/requests/answer-requests.d.ts +6 -5
- package/requests/answer-requests.js +10 -10
- package/requests/approve-requests.d.ts +2 -1
- package/requests/approve-requests.js +2 -2
- package/requests/ban-requests.d.ts +3 -2
- package/requests/ban-requests.js +4 -4
- package/requests/close-requests.d.ts +3 -2
- package/requests/close-requests.js +4 -4
- package/requests/copy-requests.d.ts +3 -2
- package/requests/copy-requests.js +4 -4
- package/requests/create-requests.d.ts +6 -5
- package/requests/create-requests.js +10 -10
- package/requests/decline-requests.d.ts +2 -1
- package/requests/decline-requests.js +2 -2
- package/requests/delete-requests.d.ts +9 -8
- package/requests/delete-requests.js +16 -16
- package/requests/download-requests.d.ts +3 -2
- package/requests/download-requests.js +6 -6
- package/requests/edit-requests.d.ts +10 -9
- package/requests/edit-requests.js +18 -18
- package/requests/export-requests.d.ts +2 -1
- package/requests/export-requests.js +2 -2
- package/requests/forward-requests.d.ts +3 -2
- package/requests/forward-requests.js +4 -4
- package/requests/get-requests.d.ts +22 -21
- package/requests/get-requests.js +42 -42
- package/requests/hide-requests.d.ts +2 -1
- package/requests/hide-requests.js +2 -2
- package/requests/leave-requests.d.ts +2 -1
- package/requests/leave-requests.js +2 -2
- package/requests/log-requests.d.ts +2 -1
- package/requests/log-requests.js +2 -2
- package/requests/pin-requests.d.ts +2 -1
- package/requests/pin-requests.js +2 -2
- package/requests/promote-requests.d.ts +2 -1
- package/requests/promote-requests.js +2 -2
- package/requests/refund-requests.d.ts +2 -1
- package/requests/refund-requests.js +2 -2
- package/requests/reopen-requests.d.ts +3 -2
- package/requests/reopen-requests.js +4 -4
- package/requests/replace-requests.d.ts +2 -1
- package/requests/replace-requests.js +2 -2
- package/requests/restrict-requests.d.ts +2 -1
- package/requests/restrict-requests.js +2 -2
- package/requests/revoke-requests.d.ts +2 -1
- package/requests/revoke-requests.js +2 -2
- package/requests/send-requests.d.ts +22 -22
- package/requests/send-requests.js +44 -44
- package/requests/set-requests.d.ts +23 -22
- package/requests/set-requests.js +44 -44
- package/requests/stop-requests.d.ts +3 -2
- package/requests/stop-requests.js +4 -4
- package/requests/unban-requests.d.ts +3 -2
- package/requests/unban-requests.js +4 -4
- package/requests/unhide-requests.d.ts +2 -1
- package/requests/unhide-requests.js +2 -2
- package/requests/unpin-requests.d.ts +5 -4
- package/requests/unpin-requests.js +8 -8
- package/requests/upload-requests.d.ts +2 -1
- package/requests/upload-requests.js +2 -2
- package/requests/webhook-requests.d.ts +5 -4
- package/requests/webhook-requests.js +8 -8
- package/utils/reply-to-message-utils.d.ts +3 -3
- package/utils/reply-to-message-utils.js +1 -1
- package/utils/start-message-utils.d.ts +3 -3
- package/definitions/telegram-api-definitions.d.ts +0 -12
- package/definitions/telegram-api-definitions.js +0 -2
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-

|
|
2
|
-

|
|
3
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
4
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
5
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
6
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
7
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
8
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
9
|
-
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
10
|
-
[](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).
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
4
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
5
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
6
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
7
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=aracna_telegram-bot)
|
|
10
|
+
[](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).
|
package/apis/telegram-api.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
declare class API extends RestAPI<
|
|
1
|
+
import { FetchError, Queue, type RequestMethod, RestAPI } from '@aracna/core';
|
|
2
|
+
import { TelegramApiConfig } from '../definitions/interfaces';
|
|
3
|
+
declare class API extends RestAPI<TelegramApiConfig> {
|
|
4
4
|
queue: Queue;
|
|
5
|
-
post<V, W, X = undefined>(path: string, body: W | undefined, config
|
|
6
|
-
transformBody<V>(method: RequestMethod, path: string, body: V, config:
|
|
5
|
+
post<V, W, X = undefined>(path: string, body: W | undefined, config?: TelegramApiConfig): Promise<V | FetchError<X>>;
|
|
6
|
+
transformBody<V>(method: RequestMethod, path: string, body: V, config: TelegramApiConfig): Promise<V | FormData | undefined>;
|
|
7
|
+
getToken(): string | undefined;
|
|
8
|
+
setToken(token?: string): this;
|
|
7
9
|
}
|
|
8
10
|
export declare const TelegramAPI: API;
|
|
9
11
|
export {};
|
package/apis/telegram-api.js
CHANGED
|
@@ -5,11 +5,14 @@ const core_1 = require("@aracna/core");
|
|
|
5
5
|
class API extends core_1.RestAPI {
|
|
6
6
|
queue = new core_1.Queue({ autostart: true });
|
|
7
7
|
async post(path, body, config) {
|
|
8
|
-
let fn, callback
|
|
8
|
+
let token, promise, fn, callback;
|
|
9
|
+
token = config?.token ?? this.config?.token;
|
|
10
|
+
if (!token)
|
|
11
|
+
return core_1.FetchError.from(new Error(`The token is required.`));
|
|
9
12
|
promise = new core_1.DeferredPromise();
|
|
10
13
|
fn = async () => {
|
|
11
14
|
let response;
|
|
12
|
-
response = await super.post('/bot' +
|
|
15
|
+
response = await super.post('/bot' + token + '/' + path, body, config);
|
|
13
16
|
if (response instanceof Error)
|
|
14
17
|
return response;
|
|
15
18
|
return response.data.result;
|
|
@@ -38,6 +41,13 @@ class API extends core_1.RestAPI {
|
|
|
38
41
|
}
|
|
39
42
|
return body;
|
|
40
43
|
}
|
|
44
|
+
getToken() {
|
|
45
|
+
return this.config.token;
|
|
46
|
+
}
|
|
47
|
+
setToken(token) {
|
|
48
|
+
this.config.token = token;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
exports.TelegramAPI = new API('https://api.telegram.org', {
|
|
43
53
|
decode: {
|
|
@@ -50,6 +60,5 @@ exports.TelegramAPI = new API('https://api.telegram.org', {
|
|
|
50
60
|
json: {
|
|
51
61
|
castBigIntToString: true
|
|
52
62
|
}
|
|
53
|
-
}
|
|
54
|
-
token: undefined
|
|
63
|
+
}
|
|
55
64
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
declare class API extends RestAPI<
|
|
4
|
-
get<V, W = undefined>(path: string, config
|
|
1
|
+
import { FetchError, RestAPI } from '@aracna/core';
|
|
2
|
+
import type { TelegramFileApiConfig } from '../definitions/interfaces';
|
|
3
|
+
declare class API extends RestAPI<TelegramFileApiConfig> {
|
|
4
|
+
get<V, W = undefined>(path: string, config?: TelegramFileApiConfig): Promise<V | FetchError<W>>;
|
|
5
|
+
getToken(): string | undefined;
|
|
6
|
+
setToken(token?: string): this;
|
|
5
7
|
}
|
|
6
8
|
export declare const TelegramFileAPI: API;
|
|
7
9
|
export {};
|
|
@@ -4,11 +4,21 @@ exports.TelegramFileAPI = void 0;
|
|
|
4
4
|
const core_1 = require("@aracna/core");
|
|
5
5
|
class API extends core_1.RestAPI {
|
|
6
6
|
async get(path, config) {
|
|
7
|
-
let response;
|
|
8
|
-
|
|
7
|
+
let token, response;
|
|
8
|
+
token = config?.token ?? this.config?.token;
|
|
9
|
+
if (!token)
|
|
10
|
+
return core_1.FetchError.from(new Error(`The token is required.`));
|
|
11
|
+
response = await super.get('/file/bot' + token + '/' + path, config);
|
|
9
12
|
if (response instanceof Error)
|
|
10
13
|
return response;
|
|
11
14
|
return response.data;
|
|
12
15
|
}
|
|
16
|
+
getToken() {
|
|
17
|
+
return this.config.token;
|
|
18
|
+
}
|
|
19
|
+
setToken(token) {
|
|
20
|
+
this.config.token = token;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
13
23
|
}
|
|
14
24
|
exports.TelegramFileAPI = new API('https://api.telegram.org');
|
package/classes/client.js
CHANGED
|
@@ -32,11 +32,11 @@ class Client {
|
|
|
32
32
|
if (!options?.webhook?.url) {
|
|
33
33
|
return new Error(`The webhook URL is required.`);
|
|
34
34
|
}
|
|
35
|
-
del = await (0, webhook_requests_1.deleteWebhook)(
|
|
35
|
+
del = await (0, webhook_requests_1.deleteWebhook)(options.webhook.delete, { token: this.token });
|
|
36
36
|
if (del instanceof Error)
|
|
37
37
|
return del;
|
|
38
38
|
class_logger_1.ClassLogger.verbose('Telegram', 'connect', `The webhook has been deleted.`);
|
|
39
|
-
set = await (0, webhook_requests_1.setWebhook)(this.token
|
|
39
|
+
set = await (0, webhook_requests_1.setWebhook)(options.webhook, { token: this.token });
|
|
40
40
|
if (set instanceof Error)
|
|
41
41
|
return set;
|
|
42
42
|
class_logger_1.ClassLogger.info('Telegram', 'connect', `The webhook has been set.`);
|
|
@@ -49,7 +49,7 @@ class Client {
|
|
|
49
49
|
class_logger_1.ClassLogger.verbose('Telegram', 'disconnect', `The offset has been reset.`, [this.offset]);
|
|
50
50
|
(0, core_1.clearInterval)(this.id);
|
|
51
51
|
class_logger_1.ClassLogger.info('Telegram', 'disconnect', `The client has been disconnected.`);
|
|
52
|
-
await (0, webhook_requests_1.deleteWebhook)(this.token
|
|
52
|
+
await (0, webhook_requests_1.deleteWebhook)(options?.webhook, { token: this.token });
|
|
53
53
|
class_logger_1.ClassLogger.info('Telegram', 'disconnect', `The webhook has been deleted.`);
|
|
54
54
|
}
|
|
55
55
|
on(type, middleware, options) {
|
|
@@ -180,7 +180,7 @@ class Client {
|
|
|
180
180
|
return;
|
|
181
181
|
listener.middleware(query);
|
|
182
182
|
if (listener.options.deleteOnCallbackQuery && query.message) {
|
|
183
|
-
(0, delete_requests_1.deleteMessage)(
|
|
183
|
+
(0, delete_requests_1.deleteMessage)({ chat_id: body.c ? query.from.id : query.message.chat.id, message_id: query.message.message_id }, { token: this.token });
|
|
184
184
|
}
|
|
185
185
|
return listener;
|
|
186
186
|
}
|
|
@@ -337,7 +337,7 @@ class Client {
|
|
|
337
337
|
return;
|
|
338
338
|
listener.middleware(reply);
|
|
339
339
|
if (listener.id.length > 0 && listener.options.deleteOnReply && reply.from && reply.reply_to_message) {
|
|
340
|
-
(0, delete_requests_1.deleteMessages)(
|
|
340
|
+
(0, delete_requests_1.deleteMessages)({ chat_id: reply.from.id, message_ids: [reply.message_id, reply.reply_to_message.message_id] }, { token: this.token });
|
|
341
341
|
}
|
|
342
342
|
return listener;
|
|
343
343
|
}
|
|
@@ -358,7 +358,7 @@ class Client {
|
|
|
358
358
|
return;
|
|
359
359
|
listener.middleware(start);
|
|
360
360
|
if (listener.id.length > 0 && listener.options.deleteOnMessageStart) {
|
|
361
|
-
(0, delete_requests_1.deleteMessage)(
|
|
361
|
+
(0, delete_requests_1.deleteMessage)({ chat_id: body.c ? start.from?.id ?? 0n : start.chat.id, message_id: start.message_id }, { token: this.token });
|
|
362
362
|
}
|
|
363
363
|
return listener;
|
|
364
364
|
}
|
|
@@ -370,7 +370,7 @@ class Client {
|
|
|
370
370
|
offset: options?.offset ?? this.offset,
|
|
371
371
|
timeout: options?.timeout
|
|
372
372
|
};
|
|
373
|
-
updates = await (0, get_requests_1.getUpdates)(this.token
|
|
373
|
+
updates = await (0, get_requests_1.getUpdates)(body, { token: this.token });
|
|
374
374
|
if (updates instanceof Error)
|
|
375
375
|
return;
|
|
376
376
|
for (let update of updates) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FetchResponse, RestApiConfig } from '@aracna/core';
|
|
1
2
|
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
3
|
import type { ClientListenerMiddleware, InputFile, UpdateType } from './types';
|
|
3
4
|
export interface CallbackQuery<T = any> extends NativeCallbackQuery {
|
|
@@ -114,3 +115,14 @@ export interface StartBody<T = any> {
|
|
|
114
115
|
d?: T;
|
|
115
116
|
m?: string;
|
|
116
117
|
}
|
|
118
|
+
export interface TelegramApiConfig extends RestApiConfig {
|
|
119
|
+
token?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface TelegramApiResponse<T> extends FetchResponse<TelegramApiResponseData<T>> {
|
|
122
|
+
}
|
|
123
|
+
export interface TelegramApiResponseData<T> {
|
|
124
|
+
ok: boolean;
|
|
125
|
+
result: T;
|
|
126
|
+
}
|
|
127
|
+
export interface TelegramFileApiConfig extends TelegramApiConfig {
|
|
128
|
+
}
|