Skip to content

Commit 5fbbf66

Browse files
louis70109xingoxu
andauthored
feat: Get follower ids (#278)
* feat: make box's contents can empty and add animated property * Modify to original * add to document * feat: followers ids api * 🔥 make function public * remove wrap function Co-authored-by: xingo xu <xingoxu@users.noreply.github.com> Co-authored-by: xingoxu <xingoxu@gmail.com>
1 parent 11e1149 commit 5fbbf66

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

docs/api-reference/client.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ client.getGroupMemberIds('group_id').then((ids) => {
369369
})
370370
```
371371

372+
373+
#### `getBotFollowersIds(): Promise<string[]>`
374+
375+
It corresponds to the [Bot Followers IDs](https://developers.line.biz/en/reference/messaging-api/#get-follower-ids) API.
376+
377+
*FYI: This feature is available only for verified or premium accounts.*
378+
379+
``` js
380+
client.getBotFollowersIds().then((ids) => {
381+
ids.forEach((id) => console.log(id));
382+
})
383+
```
384+
372385
#### `leaveGroup(groupId: string): Promise<any>`
373386

374387
It corresponds to the [Leave group](https://developers.line.biz/en/reference/messaging-api/#leave-group) API.

lib/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ export default class Client {
200200
return this.getChatMemberIds("room", roomId);
201201
}
202202

203+
public async getBotFollowersIds(): Promise<string[]> {
204+
let userIds: string[] = [];
205+
206+
let start: string;
207+
do {
208+
const res = await this.http.get<{ userIds: string[]; next?: string }>(
209+
`${MESSAGING_API_PREFIX}/followers/ids`,
210+
start ? { start } : null,
211+
);
212+
ensureJSON(res);
213+
userIds = userIds.concat(res.userIds);
214+
start = res.next;
215+
} while (start);
216+
217+
return userIds;
218+
}
219+
203220
public async getGroupMembersCount(
204221
groupId: string,
205222
): Promise<Types.MembersCountResponse> {

test/client.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ describe("client", () => {
375375
]);
376376
});
377377

378+
it("getBotFollowersIds", async () => {
379+
const scope = mockGet(MESSAGING_API_PREFIX, "/followers/ids");
380+
const ids = await client.getBotFollowersIds();
381+
equal(scope.isDone(), true);
382+
});
383+
378384
it("getGroupMembersCount", async () => {
379385
const groupId = "groupId";
380386
const scope = mockGet(

0 commit comments

Comments
 (0)