@codebam/cf-workers-telegram-bot 5.4.0 → 5.8.0
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/dist/main/src/bot_api.d.ts +2 -2
- package/dist/main/src/bot_api.js +4 -4
- package/dist/main/src/handler.js +6 -9
- package/dist/main/src/telegram_api.js +1 -1
- package/dist/main/src/telegram_bot.js +14 -14
- package/dist/main/src/telegram_webhook.js +0 -1
- package/dist/main/src/types.d.ts +3 -3
- package/dist/main/src/types.js +4 -3
- package/package.json +8 -8
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
2
|
import Handler from "./handler";
|
|
3
|
-
import { Commands, Config, Update
|
|
3
|
+
import { Commands, Config, Update } from "./types";
|
|
4
4
|
export default class BotApi {
|
|
5
5
|
commands: Commands;
|
|
6
6
|
webhook: Config["webhook"];
|
|
7
7
|
handler: Handler;
|
|
8
8
|
update: (update: Update) => Promise<Response>;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(config: Partial<Config>);
|
|
10
10
|
}
|
package/dist/main/src/bot_api.js
CHANGED
|
@@ -3,9 +3,9 @@ export default class BotApi {
|
|
|
3
3
|
webhook;
|
|
4
4
|
handler;
|
|
5
5
|
update;
|
|
6
|
-
constructor(
|
|
7
|
-
this.commands = commands;
|
|
8
|
-
this.webhook = webhook;
|
|
9
|
-
this.handler = handler;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.commands = config.commands;
|
|
8
|
+
this.webhook = config.webhook;
|
|
9
|
+
this.handler = config.handler;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/dist/main/src/handler.js
CHANGED
|
@@ -31,15 +31,12 @@ export default class Handler {
|
|
|
31
31
|
// handles the request
|
|
32
32
|
handle = async (request) => this.getAccessKeys(this.configs).then((access_keys) => Object.keys(this.responses).includes(request.method)
|
|
33
33
|
? this.responses[request.method](request, ((key) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return this.responses.default();
|
|
34
|
+
return new access_keys[key].api({
|
|
35
|
+
...new Config(),
|
|
36
|
+
...access_keys[key],
|
|
37
|
+
url: new URL(new URL(request.url).origin),
|
|
38
|
+
handler: this,
|
|
39
|
+
});
|
|
43
40
|
})(new URL(request.url).pathname.substring(1)))
|
|
44
41
|
: this.responses.default());
|
|
45
42
|
}
|
|
@@ -2,7 +2,7 @@ import BotApi from "./bot_api";
|
|
|
2
2
|
import { addSearchParams, log } from "./libs";
|
|
3
3
|
export default class TelegramApi extends BotApi {
|
|
4
4
|
constructor(commands, webhook, handler) {
|
|
5
|
-
super(commands, webhook, handler);
|
|
5
|
+
super({ commands, webhook, handler });
|
|
6
6
|
}
|
|
7
7
|
inlineQueryUpdate = async (update) => this.executeInlineCommand(update);
|
|
8
8
|
messageUpdate = async (update) => typeof update.message?.text === "string"
|
|
@@ -123,20 +123,20 @@ export default class TelegramBot extends TelegramApi {
|
|
|
123
123
|
_average = (numbers) => parseFloat((numbers.reduce((prev, cur) => prev + cur, 0) / numbers.length || 0).toFixed(2));
|
|
124
124
|
// bot command: /recursion
|
|
125
125
|
recursion = async (update) => this.sendMessage(update.message?.chat.id ?? 0, "/recursion");
|
|
126
|
-
// .then((response) =>
|
|
127
|
-
// .then((result
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
126
|
+
// .then((response) => response.json())
|
|
127
|
+
// .then((result) =>
|
|
128
|
+
// this.handler.postResponse(
|
|
129
|
+
// new Request("", {
|
|
130
|
+
// method: "POST",
|
|
131
|
+
// body: JSON.stringify({
|
|
132
|
+
// message: {
|
|
133
|
+
// text: (result as { result: { text: string } }).result.text,
|
|
134
|
+
// chat: { id: update.message?.chat.id },
|
|
135
|
+
// },
|
|
136
|
+
// }),
|
|
137
|
+
// }),
|
|
138
|
+
// this
|
|
139
|
+
// )
|
|
140
140
|
// );
|
|
141
141
|
// bot command: /roll
|
|
142
142
|
roll = async (update, args) => ((outcome, message) => update.inline_query
|
|
@@ -14,7 +14,6 @@ export default class TelegramWebhook extends Webhook {
|
|
|
14
14
|
get = async () => fetch_json(new URL(`${this.api.origin}${this.api.pathname}/getWebhookInfo`));
|
|
15
15
|
delete = async () => fetch_json(new URL(`${this.api.origin}${this.api.pathname}/deleteWebhook`));
|
|
16
16
|
commands = {
|
|
17
|
-
...this.commands,
|
|
18
17
|
set: this.set,
|
|
19
18
|
get: this.get,
|
|
20
19
|
delete: this.delete,
|
package/dist/main/src/types.d.ts
CHANGED
|
@@ -10,12 +10,12 @@ export type Commands = Record<string, Command>;
|
|
|
10
10
|
export type Kv = Record<string, KVNamespace> | undefined;
|
|
11
11
|
export declare class Config {
|
|
12
12
|
bot_name: string;
|
|
13
|
-
api:
|
|
13
|
+
api: typeof BotApi;
|
|
14
14
|
webhook: Webhook;
|
|
15
15
|
commands: Record<string, Command>;
|
|
16
|
-
kv: Kv
|
|
16
|
+
kv: Kv;
|
|
17
17
|
url: URL;
|
|
18
|
-
handler: Handler
|
|
18
|
+
handler: Handler;
|
|
19
19
|
constructor(config?: Partial<Config>);
|
|
20
20
|
}
|
|
21
21
|
export declare const localhost: URL;
|
package/dist/main/src/types.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import BotApi from "./bot_api";
|
|
2
|
+
import Handler from "./handler";
|
|
1
3
|
import Webhook from "./webhook";
|
|
2
4
|
export { Webhook };
|
|
3
5
|
export class Config {
|
|
4
6
|
bot_name;
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
7
|
api;
|
|
7
8
|
webhook;
|
|
8
9
|
commands;
|
|
@@ -11,12 +12,12 @@ export class Config {
|
|
|
11
12
|
handler;
|
|
12
13
|
constructor(config = {}) {
|
|
13
14
|
this.bot_name = config.bot_name || "";
|
|
14
|
-
this.api = config.api ||
|
|
15
|
+
this.api = config.api || BotApi;
|
|
15
16
|
this.webhook = config.webhook || new Webhook(localhost, "", localhost);
|
|
16
17
|
this.commands = config.commands || {};
|
|
17
18
|
this.kv = config.kv;
|
|
18
19
|
this.url = config.url || new URL(localhost);
|
|
19
|
-
this.handler = config.handler;
|
|
20
|
+
this.handler = config.handler || new Handler([]);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
export const localhost = new URL("http://localhost");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.0",
|
|
4
4
|
"description": "serverless telegram bot on cf workers",
|
|
5
5
|
"main": "./dist/main/src/main.js",
|
|
6
6
|
"module": "./dist/main/src/main.js",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"url": "https://github.com/codebam/cf-workers-telegram-bot.git"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@cloudflare/workers-types": "^4.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
34
|
-
"@typescript-eslint/parser": "^6.
|
|
35
|
-
"eslint": "^8.
|
|
32
|
+
"@cloudflare/workers-types": "^4.20230914.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
34
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
35
|
+
"eslint": "^8.49.0",
|
|
36
36
|
"eslint-config-prettier": "^9.0.0",
|
|
37
37
|
"lerna": "^7.1.5",
|
|
38
|
-
"prettier": "^3.0.
|
|
39
|
-
"typescript": "^5.
|
|
38
|
+
"prettier": "^3.0.2",
|
|
39
|
+
"typescript": "^5.2.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "4101ac66eb6a0f94d2fb939863286b334f79cbbc"
|
|
42
42
|
}
|