@codebam/cf-workers-telegram-bot 4.11.0 → 5.1.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.
@@ -8,6 +8,5 @@ export default class Handler {
8
8
  postResponse: (_request?: Request, _bot?: BotApi) => Promise<Response>;
9
9
  responses: Record<string, (_request?: Request, _bot?: BotApi) => Promise<Response>>;
10
10
  getAccessKeys: (configs: PartialConfig[]) => Promise<Record<string, any> | Record<string, never>>;
11
- check_undefined: (x: any) => any;
12
11
  handle: (request: Request) => Promise<Response>;
13
12
  }
@@ -1,13 +1,12 @@
1
- import BotApi from "./bot_api";
2
1
  import { sha256, log } from "./libs";
3
- import { Webhook, Config, localhost, } from "./types";
2
+ import { Config, localhost } from "./types";
4
3
  export default class Handler {
5
4
  configs;
6
5
  constructor(configs) {
7
6
  this.configs = configs;
8
7
  }
9
8
  getResponse = async (_request, _bot) => {
10
- this.getAccessKeys(this.configs).then((access_keys) => Object.keys(access_keys).forEach((key) => log(`${access_keys[key].bot_name} ${((request_url) => `${request_url.origin}${request_url.pathname}`)(new URL(_request?.url ?? localhost))}/${key}`)));
9
+ this.getAccessKeys(this.configs).then((access_keys) => Object.keys(access_keys).forEach((key) => log(`${access_keys[key].bot_name} ${((request_url) => `${request_url.origin}${request_url.pathname}`)(new URL(_request?.url ?? localhost))}${key}`)));
11
10
  if (_bot?.webhook.token) {
12
11
  return _bot.webhook.process(new URL(_request?.url ?? localhost));
13
12
  }
@@ -31,28 +30,18 @@ export default class Handler {
31
30
  hash,
32
31
  bot_config,
33
32
  ]))).then((result) => Object.fromEntries(result));
34
- // check
35
- check_undefined = (x) => {
36
- if (x === undefined) {
37
- return {};
38
- }
39
- return x;
40
- };
41
33
  // handles the request
42
34
  handle = async (request) => this.getAccessKeys(this.configs).then((access_keys) => Object.keys(this.responses).includes(request.method)
43
- ? this.responses[request.method](request, ((access_keys) => {
44
- if (access_keys[new URL(request.url).pathname.substring(1)] ===
45
- undefined) {
46
- return () => {
47
- return new BotApi({}, new Webhook(new URL("https://seanbehan.ca"), "", new URL("https://seanbehan.ca")), new Handler([]));
48
- };
35
+ ? this.responses[request.method](request, ((key) => {
36
+ if (access_keys[key]) {
37
+ return new access_keys[key].api({
38
+ ...new Config(),
39
+ url: new URL(new URL(request.url).origin),
40
+ handler: this,
41
+ ...access_keys[key],
42
+ });
49
43
  }
50
- return access_keys[new URL(request.url).pathname.substring(1)];
51
- })(access_keys)({
52
- ...new Config(),
53
- url: new URL(new URL(request.url).origin),
54
- handler: this,
55
- ...access_keys[new URL(request.url).pathname.substring(1)],
56
- }))
44
+ return this.responses.default();
45
+ })(new URL(request.url).pathname.substring(1)))
57
46
  : this.responses.default());
58
47
  }
@@ -32,7 +32,7 @@ export default class TelegramApi extends BotApi {
32
32
  ? this.commands[command]?.(this, update, [...text_args, ...args])
33
33
  : log({
34
34
  error: `command '${command}' does not exist`,
35
- }))(
35
+ }) && this.updates.default)(
36
36
  // run the command
37
37
  this.getCommand(text_args)))(
38
38
  // get the command to run
@@ -51,5 +51,5 @@ export default {
51
51
  "/start": TelegramCommands.commandList,
52
52
  },
53
53
  },
54
- ]).handle(request).then(() => new Response()),
54
+ ]).handle(request),
55
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "4.11.0",
3
+ "version": "5.1.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",
@@ -32,11 +32,11 @@
32
32
  "@cloudflare/workers-types": "^4.20230518.0",
33
33
  "@typescript-eslint/eslint-plugin": "^5.60.1",
34
34
  "@typescript-eslint/parser": "^5.60.1",
35
- "eslint": "^8.44.0",
35
+ "eslint": "^8.43.0",
36
36
  "eslint-config-prettier": "^8.8.0",
37
37
  "lerna": "^7.1.1",
38
38
  "prettier": "^2.8.8",
39
39
  "typescript": "^5.1.6"
40
40
  },
41
- "gitHead": "359ffdca6d9b22b0f80d2cdd691471348feda8f0"
41
+ "gitHead": "a36c722da3898a8fb1c13d9c60527b6355fcdfe1"
42
42
  }