mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:00:54 +00:00
refactor(line): share rich menu user batching
This commit is contained in:
@@ -10,6 +10,7 @@ type RichMenuRequest = messagingApi.RichMenuRequest;
|
||||
type RichMenuResponse = messagingApi.RichMenuResponse;
|
||||
type RichMenuArea = messagingApi.RichMenuArea;
|
||||
type Action = messagingApi.Action;
|
||||
const USER_BATCH_SIZE = 500;
|
||||
|
||||
export interface RichMenuSize {
|
||||
width: 2500;
|
||||
@@ -66,6 +67,14 @@ function getBlobClient(opts: RichMenuOpts = {}): messagingApi.MessagingApiBlobCl
|
||||
});
|
||||
}
|
||||
|
||||
function chunkUserIds(userIds: string[]): string[][] {
|
||||
const batches: string[][] = [];
|
||||
for (let i = 0; i < userIds.length; i += USER_BATCH_SIZE) {
|
||||
batches.push(userIds.slice(i, i + USER_BATCH_SIZE));
|
||||
}
|
||||
return batches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new rich menu
|
||||
* @returns The rich menu ID
|
||||
@@ -187,13 +196,7 @@ export async function linkRichMenuToUsers(
|
||||
): Promise<void> {
|
||||
const client = getClient(opts);
|
||||
|
||||
// LINE allows max 500 users per request
|
||||
const batches = [];
|
||||
for (let i = 0; i < userIds.length; i += 500) {
|
||||
batches.push(userIds.slice(i, i + 500));
|
||||
}
|
||||
|
||||
for (const batch of batches) {
|
||||
for (const batch of chunkUserIds(userIds)) {
|
||||
await client.linkRichMenuIdToUsers({
|
||||
richMenuId,
|
||||
userIds: batch,
|
||||
@@ -230,13 +233,7 @@ export async function unlinkRichMenuFromUsers(
|
||||
): Promise<void> {
|
||||
const client = getClient(opts);
|
||||
|
||||
// LINE allows max 500 users per request
|
||||
const batches = [];
|
||||
for (let i = 0; i < userIds.length; i += 500) {
|
||||
batches.push(userIds.slice(i, i + 500));
|
||||
}
|
||||
|
||||
for (const batch of batches) {
|
||||
for (const batch of chunkUserIds(userIds)) {
|
||||
await client.unlinkRichMenuIdFromUsers({
|
||||
userIds: batch,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user