nonotify 0.1.0 → 0.1.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.
- package/.github/workflows/release.yml +113 -0
- package/README.md +2 -4
- package/dist/cli.js +125 -97
- package/dist/config.js +15 -11
- package/dist/display.js +5 -5
- package/dist/prompt.js +7 -7
- package/dist/telegram.js +12 -10
- package/nonotify-0.1.2.tgz +0 -0
- package/package.json +8 -2
- package/src/cli.ts +308 -223
- package/src/config.ts +39 -36
- package/src/display.ts +20 -17
- package/src/prompt.ts +36 -27
- package/src/telegram.ts +77 -53
- package/tsconfig.json +1 -3
package/dist/prompt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cancel, confirm, isCancel, select, text } from
|
|
1
|
+
import { cancel, confirm, isCancel, select, text } from "@clack/prompts";
|
|
2
2
|
export async function askRequired(question) {
|
|
3
3
|
return askRequiredWithInitial(question);
|
|
4
4
|
}
|
|
@@ -8,14 +8,14 @@ export async function askRequiredWithInitial(question, initialValue) {
|
|
|
8
8
|
message,
|
|
9
9
|
initialValue,
|
|
10
10
|
validate(input) {
|
|
11
|
-
if (!input || input.trim() ===
|
|
12
|
-
return
|
|
11
|
+
if (!input || input.trim() === "") {
|
|
12
|
+
return "Value cannot be empty";
|
|
13
13
|
}
|
|
14
14
|
return undefined;
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
if (isCancel(value)) {
|
|
18
|
-
cancel(
|
|
18
|
+
cancel("Operation cancelled.");
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
return value.trim();
|
|
@@ -26,7 +26,7 @@ export async function askConfirm(question, initialValue = false) {
|
|
|
26
26
|
initialValue,
|
|
27
27
|
});
|
|
28
28
|
if (isCancel(value)) {
|
|
29
|
-
cancel(
|
|
29
|
+
cancel("Operation cancelled.");
|
|
30
30
|
process.exit(1);
|
|
31
31
|
}
|
|
32
32
|
return value;
|
|
@@ -37,11 +37,11 @@ export async function askSelect(question, options) {
|
|
|
37
37
|
options,
|
|
38
38
|
});
|
|
39
39
|
if (isCancel(value)) {
|
|
40
|
-
cancel(
|
|
40
|
+
cancel("Operation cancelled.");
|
|
41
41
|
process.exit(1);
|
|
42
42
|
}
|
|
43
43
|
return value;
|
|
44
44
|
}
|
|
45
45
|
function normalizeQuestion(question) {
|
|
46
|
-
return question.trim().replace(/:\s*$/,
|
|
46
|
+
return question.trim().replace(/:\s*$/, "");
|
|
47
47
|
}
|
package/dist/telegram.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
async function telegramRequest(botToken, method, payload) {
|
|
2
2
|
const response = await fetch(`https://api.telegram.org/bot${botToken}/${method}`, {
|
|
3
|
-
method:
|
|
3
|
+
method: "POST",
|
|
4
4
|
headers: {
|
|
5
|
-
|
|
5
|
+
"content-type": "application/json",
|
|
6
6
|
},
|
|
7
7
|
body: JSON.stringify(payload),
|
|
8
8
|
});
|
|
9
9
|
if (!response.ok) {
|
|
10
10
|
throw new Error(`Telegram API HTTP ${response.status}`);
|
|
11
11
|
}
|
|
12
|
-
const json = await response.json();
|
|
12
|
+
const json = (await response.json());
|
|
13
13
|
if (!json.ok) {
|
|
14
14
|
throw new Error(json.description);
|
|
15
15
|
}
|
|
16
16
|
return json.result;
|
|
17
17
|
}
|
|
18
18
|
export async function getLatestUpdateOffset(botToken) {
|
|
19
|
-
const updates = await telegramRequest(botToken,
|
|
19
|
+
const updates = await telegramRequest(botToken, "getUpdates", {
|
|
20
20
|
timeout: 0,
|
|
21
|
-
allowed_updates: [
|
|
21
|
+
allowed_updates: ["message"],
|
|
22
22
|
});
|
|
23
23
|
if (updates.length === 0) {
|
|
24
24
|
return 0;
|
|
@@ -32,25 +32,27 @@ export async function waitForChatId(botToken, offset, timeoutSeconds = 120) {
|
|
|
32
32
|
while ((Date.now() - startedAt) / 1000 < timeoutSeconds) {
|
|
33
33
|
const remainingSeconds = timeoutSeconds - Math.floor((Date.now() - startedAt) / 1000);
|
|
34
34
|
const pollTimeout = Math.max(1, Math.min(25, remainingSeconds));
|
|
35
|
-
const updates = await telegramRequest(botToken,
|
|
35
|
+
const updates = await telegramRequest(botToken, "getUpdates", {
|
|
36
36
|
offset: currentOffset,
|
|
37
37
|
timeout: pollTimeout,
|
|
38
|
-
allowed_updates: [
|
|
38
|
+
allowed_updates: ["message"],
|
|
39
39
|
});
|
|
40
40
|
for (const update of updates) {
|
|
41
41
|
currentOffset = Math.max(currentOffset, update.update_id + 1);
|
|
42
42
|
if (update.message?.chat?.id !== undefined) {
|
|
43
43
|
return {
|
|
44
44
|
chatId: String(update.message.chat.id),
|
|
45
|
-
username: update.message.from?.username ??
|
|
45
|
+
username: update.message.from?.username ??
|
|
46
|
+
update.message.chat.username ??
|
|
47
|
+
null,
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
throw new Error(
|
|
52
|
+
throw new Error("Timed out waiting for Telegram message. Send a message to your bot and try again.");
|
|
51
53
|
}
|
|
52
54
|
export async function sendTelegramMessage(botToken, chatId, text) {
|
|
53
|
-
await telegramRequest(botToken,
|
|
55
|
+
await telegramRequest(botToken, "sendMessage", {
|
|
54
56
|
chat_id: chatId,
|
|
55
57
|
text,
|
|
56
58
|
});
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nonotify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "nnt CLI for Telegram notifications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"nnt": "dist/cli.js"
|
|
7
|
+
"nnt": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
+
"prettier:check": "npx prettier --check .",
|
|
11
|
+
"prettier:fix": "npx prettier --write .",
|
|
12
|
+
"check": "npm run prettier:check",
|
|
13
|
+
"fix": "npm run prettier:fix",
|
|
14
|
+
"test": "npm run check",
|
|
10
15
|
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
11
17
|
"dev": "tsx src/cli.ts",
|
|
12
18
|
"start": "node dist/cli.js"
|
|
13
19
|
},
|