@yaebal/broadcast 0.0.1 → 0.0.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/lib/index.d.ts +5 -5
- package/lib/index.js +3 -3
- package/package.json +2 -2
- package/src/index.test.ts +1 -1
- package/src/index.ts +6 -6
package/lib/index.d.ts
CHANGED
|
@@ -4,15 +4,15 @@ export interface BroadcastResult {
|
|
|
4
4
|
failed: number;
|
|
5
5
|
}
|
|
6
6
|
export interface BroadcastOptions {
|
|
7
|
-
/**
|
|
7
|
+
/** extra params merged into every `sendMessage` (parse_mode, reply_markup, …). */
|
|
8
8
|
extra?: Record<string, unknown>;
|
|
9
|
-
/**
|
|
9
|
+
/** called for each chat that failed (blocked the bot, deleted account, …). */
|
|
10
10
|
onError?: (chatId: number | string, error: unknown) => void;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* abort the run.
|
|
13
|
+
* send `text` to many chats, one at a time, counting successes and failures.
|
|
14
|
+
* failures (a user blocked the bot, etc.) are swallowed so one bad chat doesn't
|
|
15
|
+
* abort the run. pair with `@yaebal/throttle` to stay under telegram's rate limit.
|
|
16
16
|
*/
|
|
17
17
|
export declare function broadcast(api: Api, chatIds: Array<number | string>, text: string, options?: BroadcastOptions): Promise<BroadcastResult>;
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* abort the run.
|
|
2
|
+
* send `text` to many chats, one at a time, counting successes and failures.
|
|
3
|
+
* failures (a user blocked the bot, etc.) are swallowed so one bad chat doesn't
|
|
4
|
+
* abort the run. pair with `@yaebal/throttle` to stay under telegram's rate limit.
|
|
5
5
|
*/
|
|
6
6
|
export async function broadcast(api, chatIds, text, options = {}) {
|
|
7
7
|
let sent = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaebal/broadcast",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "yaebal broadcast — send a message to many chats, counting successes and failures.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@yaebal/core": "0.0.
|
|
19
|
+
"@yaebal/core": "0.0.8"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "latest"
|
package/src/index.test.ts
CHANGED
|
@@ -44,7 +44,7 @@ test("broadcast merges extra params into every send", async () => {
|
|
|
44
44
|
return Promise.resolve({ message_id: 1 });
|
|
45
45
|
},
|
|
46
46
|
} as never;
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
await broadcast(api, [10], "yo", { extra: { parse_mode: "HTML" } });
|
|
49
49
|
assert.deepEqual(seen, [{ chat_id: 10, text: "yo", parse_mode: "HTML" }]);
|
|
50
50
|
});
|
package/src/index.ts
CHANGED
|
@@ -6,16 +6,16 @@ export interface BroadcastResult {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface BroadcastOptions {
|
|
9
|
-
/**
|
|
9
|
+
/** extra params merged into every `sendMessage` (parse_mode, reply_markup, …). */
|
|
10
10
|
extra?: Record<string, unknown>;
|
|
11
|
-
/**
|
|
11
|
+
/** called for each chat that failed (blocked the bot, deleted account, …). */
|
|
12
12
|
onError?: (chatId: number | string, error: unknown) => void;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* abort the run.
|
|
16
|
+
* send `text` to many chats, one at a time, counting successes and failures.
|
|
17
|
+
* failures (a user blocked the bot, etc.) are swallowed so one bad chat doesn't
|
|
18
|
+
* abort the run. pair with `@yaebal/throttle` to stay under telegram's rate limit.
|
|
19
19
|
*/
|
|
20
20
|
export async function broadcast(
|
|
21
21
|
api: Api,
|
|
@@ -36,6 +36,6 @@ export async function broadcast(
|
|
|
36
36
|
options.onError?.(chatId, error);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
return { sent, failed };
|
|
41
41
|
}
|