@codebam/cf-workers-telegram-bot 3.48.0 → 4.0.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.
|
@@ -4,10 +4,10 @@ export default class TelegramApi extends BotApi {
|
|
|
4
4
|
constructor(commands, webhook, handler) {
|
|
5
5
|
super(commands, webhook, handler);
|
|
6
6
|
}
|
|
7
|
-
inlineQueryUpdate = async (update) => this.executeInlineCommand(update).then(async (response) =>
|
|
7
|
+
inlineQueryUpdate = async (update) => this.executeInlineCommand(update).then(async (response) => responseToJSON(response).then(() => response));
|
|
8
8
|
messageUpdate = async (update) => {
|
|
9
9
|
if (typeof (update.message?.text ?? false) === "string") {
|
|
10
|
-
return
|
|
10
|
+
return this.executeCommand(update).then(async () => this.greetUsers(update));
|
|
11
11
|
}
|
|
12
12
|
return this.updates.default;
|
|
13
13
|
};
|
|
@@ -16,20 +16,18 @@ export default class TelegramApi extends BotApi {
|
|
|
16
16
|
message: this.messageUpdate,
|
|
17
17
|
default: new Response(),
|
|
18
18
|
};
|
|
19
|
-
update = async (update) => (log({ update }) &&
|
|
20
|
-
update.message
|
|
21
|
-
|
|
22
|
-
(update.inline_query
|
|
23
|
-
update.inline_query.query
|
|
24
|
-
|
|
19
|
+
update = async (update) => ((log({ update }) &&
|
|
20
|
+
update.message &&
|
|
21
|
+
this.updates.message(update)) ||
|
|
22
|
+
(update.inline_query &&
|
|
23
|
+
update.inline_query.query === "" &&
|
|
24
|
+
undefined) ||
|
|
25
|
+
this.updates.inline_query(update)) ??
|
|
25
26
|
this.updates.default;
|
|
26
27
|
// greet new users who join
|
|
27
|
-
greetUsers = async (update) =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
return this.updates.default;
|
|
32
|
-
};
|
|
28
|
+
greetUsers = async (update) => (update.message?.new_chat_members &&
|
|
29
|
+
this.sendMessage(update.message.chat.id, `Welcome to ${update.message.chat.title}, ${update.message.from.username}`)) ??
|
|
30
|
+
this.updates.default;
|
|
33
31
|
getCommand = (args) => args[0]?.split("@")[0];
|
|
34
32
|
// run command passed from executeCommand
|
|
35
33
|
_executeCommand = async (update, text, args = []) => (log({ execute: { text, args } }) &&
|
|
@@ -47,11 +45,10 @@ export default class TelegramApi extends BotApi {
|
|
|
47
45
|
.split(" "))) ??
|
|
48
46
|
this.updates.default;
|
|
49
47
|
// execute the inline custom bot commands from bot configurations
|
|
50
|
-
executeInlineCommand = async (update) =>
|
|
51
|
-
|
|
52
|
-
this.updates.default;
|
|
48
|
+
executeInlineCommand = async (update) => this._executeCommand(update, update.inline_query?.query ?? "").then(async (command_response) => command_response &&
|
|
49
|
+
this._executeCommand(update, "inline", update.inline_query?.query.trimStart().split(" ")).then((_command_response) => _command_response)) ?? this.updates.default;
|
|
53
50
|
// execute the custom bot commands from bot configurations
|
|
54
|
-
executeCommand = async (update) => this._executeCommand(update, update.message?.text ?? "")
|
|
51
|
+
executeCommand = async (update) => this._executeCommand(update, update.message?.text ?? "") ??
|
|
55
52
|
this.updates.default;
|
|
56
53
|
// trigger answerInlineQuery command of BotAPI
|
|
57
54
|
answerInlineQuery = async (inline_query_id, results, cache_time = 0) => fetch(log(addSearchParams(new URL(`${this.webhook.api.origin}${this.webhook.api.pathname}/answerInlineQuery`), {
|
|
@@ -57,7 +57,7 @@ export default class TelegramBot extends TelegramApi {
|
|
|
57
57
|
// bot command: /kanye
|
|
58
58
|
kanye = async (update) => fetch("https://api.kanye.rest")
|
|
59
59
|
.then((response) => responseToJSON(response))
|
|
60
|
-
.then((json) => ((message) => (update.inline_query
|
|
60
|
+
.then((json) => ((message) => (update.inline_query &&
|
|
61
61
|
this.answerInlineQuery(update.inline_query.id, [
|
|
62
62
|
new TelegramInlineQueryResultArticle(message),
|
|
63
63
|
])) ||
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TelegramCommands, Handler, TelegramWebhook, TelegramBot, } from "../../main/src/main";
|
|
1
|
+
import { TelegramCommands, Handler, TelegramWebhook, TelegramBot, Libs, } from "../../main/src/main";
|
|
2
2
|
export default {
|
|
3
3
|
fetch: async (request, env) => new Handler([
|
|
4
4
|
{
|
|
@@ -49,5 +49,7 @@ export default {
|
|
|
49
49
|
"/start": TelegramCommands.commandList,
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
-
])
|
|
52
|
+
])
|
|
53
|
+
.handle(request)
|
|
54
|
+
.then(Libs.log),
|
|
53
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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,15 +29,15 @@
|
|
|
29
29
|
"url": "https://github.com/codebam/cf-workers-telegram-bot.git"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"worker": "^
|
|
32
|
+
"worker": "^4.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@cloudflare/workers-types": "^4.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
37
|
-
"@typescript-eslint/parser": "^5.
|
|
35
|
+
"@cloudflare/workers-types": "^4.20230221.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
38
38
|
"eslint": "^8.34.0",
|
|
39
39
|
"prettier": "^2.8.4",
|
|
40
40
|
"typescript": "^4.9.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "957149aedeb10d1fbc6e926f3d19ba5b4f211ad8"
|
|
43
43
|
}
|