Skip to content

Commit c5086af

Browse files
SombreroElGringoxingoxu
authored andcommitted
Features and Enhancement (#147)
Features: - Get the target limit for additional messages - Get number of messages sent this month - Get number of sent broadcast messages Enhancement: - Reply message - Send push message - Send multicast message - Send broadcast message
1 parent 09d95b0 commit c5086af

File tree

4 files changed

+186
-7
lines changed

4 files changed

+186
-7
lines changed

docs/api-reference/client.md

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class Client {
1212
constructor(config: ClientConfig) {}
1313

1414
// Message
15-
pushMessage(to: string, messages: Message | Message[]): Promise<any>
16-
replyMessage(replyToken: string, messages: Message | Message[]): Promise<any>
17-
multicast(to: string[], messages: Message | Message[]): Promise<any>
15+
pushMessage(to: string, messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>
16+
replyMessage(replyToken: string, messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>
17+
multicast(to: string[], messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>
18+
broadcast(messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>
1819
getMessageContent(messageId: string): Promise<Readable>
1920

2021
// Profile
@@ -53,6 +54,9 @@ class Client {
5354
getNumberOfSentReplyMessages(date: string): Promise<NumberOfMessagesSentResponse>
5455
getNumberOfSentPushMessages(date: string): Promise<NumberOfMessagesSentResponse>
5556
getNumberOfSentMulticastMessages(date: string): Promise<NumberOfMessagesSentResponse>
57+
getTargetLimitForAdditionalMessages(): Promise<TargetLimitForAdditionalMessages>
58+
getNumberOfMessagesSentThisMonth(): Promise<NumberOfMessagesSentThisMonth>
59+
getNumberOfSentBroadcastMessages(date: string): Promise<NumberOfSentBroadcastMessages>
5660
}
5761
```
5862

@@ -84,7 +88,7 @@ in [the Client guide](../guide/client.md).
8488

8589
### Message
8690

87-
#### `pushMessage(to: string, messages: Message | Message[]): Promise<any>`
91+
#### `pushMessage(to: string, messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`
8892

8993
It corresponds to the [Push message](https://developers.line.me/en/docs/messaging-api/reference/#send-push-message) API.
9094

@@ -97,7 +101,7 @@ client.pushMessage('user_or_group_or_room_id', {
97101
})
98102
```
99103

100-
#### `replyMessage(replyToken: string, messages: Message | Message[]): Promise<any>`
104+
#### `replyMessage(replyToken: string, messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`
101105

102106
It corresponds to the [Reply message](https://developers.line.me/en/docs/messaging-api/reference/#send-reply-message) API.
103107

@@ -112,7 +116,7 @@ client.replyMessage(event.replyToken, {
112116
})
113117
```
114118

115-
#### `multicast(to: string[], messages: Message | Message[]): Promise<any>`
119+
#### `multicast(to: string[], messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`
116120

117121
It corresponds to the [Multicast](https://developers.line.me/en/docs/messaging-api/reference/#send-multicast-messages) API.
118122

@@ -126,6 +130,19 @@ client.multicast(['user_id_1', 'user_id_2', 'room_id_1'], {
126130
})
127131
```
128132

133+
#### `broadcast(messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`
134+
135+
Sends push messages to multiple users at any time.
136+
137+
Note: LINE@ accounts cannot call this API endpoint. Please migrate it to a LINE official account. For more information, see [Migration of LINE@ accounts](https://developers.line.biz/en/docs/messaging-api/migrating-line-at/).
138+
139+
``` js
140+
client.broadcast({
141+
type: 'text',
142+
text: 'hello, world',
143+
})
144+
```
145+
129146
#### `getMessageContent(messageId: string): Promise<Readable>`
130147

131148
It corresponds to the [Content](https://developers.line.me/en/docs/messaging-api/reference/#get-content) API.
@@ -435,3 +452,49 @@ client.getNumberOfSentMulticastMessages('20191231').then((response) => {
435452
console.log(response);
436453
})
437454
```
455+
456+
#### `getTargetLimitForAdditionalMessages(): Promise<TargetLimitForAdditionalMessages>`
457+
458+
Gets the target limit for additional messages in the current month.
459+
460+
The number of messages retrieved by this operation includes the number of messages sent from LINE Official Account Manager.
461+
462+
Set a target limit with LINE Official Account Manager. For the procedures, refer to the LINE Official Account Manager manual.
463+
464+
Note: LINE@ accounts cannot call this API endpoint.
465+
466+
``` js
467+
client.getTargetLimitForAdditionalMessages().then((response) => {
468+
console.log(response);
469+
})
470+
```
471+
472+
#### `getNumberOfMessagesSentThisMonth(): Promise<NumberOfMessagesSentThisMonth>`
473+
474+
Gets the number of messages sent in the current month.
475+
476+
The number of messages retrieved by this operation includes the number of messages sent from LINE Official Account Manager.
477+
478+
The number of messages retrieved by this operation is approximate. To get the correct number of sent messages, use LINE Official Account Manager or execute API operations for getting the number of sent messages.
479+
480+
Note: LINE@ accounts cannot call this API endpoint.
481+
482+
``` js
483+
client.getNumberOfMessagesSentThisMonth().then((response) => {
484+
console.log(response);
485+
})
486+
```
487+
488+
#### `getNumberOfSentBroadcastMessages(date: string): Promise<NumberOfSentBroadcastMessages>`
489+
490+
Gets the number of messages sent with the `/bot/message/broadcast` endpoint.
491+
492+
The number of messages retrieved by this operation does not include the number of messages sent from LINE Official Account Manager.
493+
494+
Note: LINE@ accounts cannot call this API endpoint. Please migrate it to a LINE official account. For more information, see [Migration of LINE@ accounts](https://developers.line.biz/en/docs/messaging-api/migrating-line-at/).
495+
496+
``` js
497+
client.getNumberOfSentBroadcastMessages('20191231').then((response) => {
498+
console.log(response);
499+
})
500+
```

lib/client.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,46 @@ export default class Client {
3838
public async pushMessage(
3939
to: string,
4040
messages: Types.Message | Types.Message[],
41+
notificationDisabled: boolean = false,
4142
): Promise<any> {
4243
return this.http.post("/message/push", {
4344
messages: toArray(messages),
4445
to,
46+
notificationDisabled,
4547
});
4648
}
4749

4850
public async replyMessage(
4951
replyToken: string,
5052
messages: Types.Message | Types.Message[],
53+
notificationDisabled: boolean = false,
5154
): Promise<any> {
5255
return this.http.post("/message/reply", {
5356
messages: toArray(messages),
5457
replyToken,
58+
notificationDisabled,
5559
});
5660
}
5761

5862
public async multicast(
5963
to: string[],
6064
messages: Types.Message | Types.Message[],
65+
notificationDisabled: boolean = false,
6166
): Promise<any> {
6267
return this.http.post("/message/multicast", {
6368
messages: toArray(messages),
6469
to,
70+
notificationDisabled,
71+
});
72+
}
73+
74+
public async broadcast(
75+
messages: Types.Message | Types.Message[],
76+
notificationDisabled: boolean = false,
77+
): Promise<any> {
78+
return this.http.post("/message/broadcast", {
79+
messages: toArray(messages),
80+
notificationDisabled,
6581
});
6682
}
6783

@@ -256,4 +272,31 @@ export default class Client {
256272
);
257273
return ensureJSON(res);
258274
}
275+
276+
public async getTargetLimitForAdditionalMessages(): Promise<
277+
Types.TargetLimitForAdditionalMessages
278+
> {
279+
const res = await this.http.get<Types.TargetLimitForAdditionalMessages>(
280+
"/message/quota",
281+
);
282+
return ensureJSON(res);
283+
}
284+
285+
public async getNumberOfMessagesSentThisMonth(): Promise<
286+
Types.NumberOfMessagesSentThisMonth
287+
> {
288+
const res = await this.http.get<Types.NumberOfMessagesSentThisMonth>(
289+
"/message/quota/consumption",
290+
);
291+
return ensureJSON(res);
292+
}
293+
294+
public async getNumberOfSentBroadcastMessages(
295+
date: string,
296+
): Promise<Types.NumberOfSentBroadcastMessages> {
297+
const res = await this.http.get<Types.NumberOfSentBroadcastMessages>(
298+
`/message/delivery/broadcast?date=${date}`,
299+
);
300+
return ensureJSON(res);
301+
}
259302
}

lib/types.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,3 +1762,41 @@ export type NumberOfMessagesSentResponse = {
17621762
*/
17631763
success?: number;
17641764
};
1765+
1766+
export type TargetLimitForAdditionalMessages = {
1767+
/**
1768+
* One of the following values to indicate whether a target limit is set or not.
1769+
* - `none`: This indicates that a target limit is not set.
1770+
* - `limited`: This indicates that a target limit is set.
1771+
*/
1772+
type: "none" | "limited";
1773+
/**
1774+
* The target limit for additional messages in the current month.
1775+
* This property is returned when the `type` property has a value of `limited`.
1776+
*/
1777+
value?: number;
1778+
};
1779+
1780+
export type NumberOfMessagesSentThisMonth = {
1781+
/**
1782+
* The number of sent messages in the current month
1783+
*/
1784+
totalUsage: number;
1785+
};
1786+
1787+
export type NumberOfSentBroadcastMessages = {
1788+
/**
1789+
* Status of the counting process. One of the following values is returned:
1790+
* - `ready`: You can get the number of messages.
1791+
* - `unready`: The message counting process for the date specified in date has not been completed yet.
1792+
* Retry your request later. Normally, the counting process is completed within the next day.
1793+
* - `out_of_service`: The date specified in date is earlier than March 31, 2018,
1794+
* when the operation of the counting system started.
1795+
*/
1796+
status: "ready" | "unready" | "out_of_service";
1797+
/**
1798+
* The number of messages sent with the Messaging API on the date specified in `date`.
1799+
* The response has this property only when the value of `status` is `ready`.
1800+
*/
1801+
success?: number;
1802+
};

test/client.spec.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { readFileSync } from "fs";
22
import { join } from "path";
33
import { deepEqual, equal } from "assert";
4-
import { Readable } from "stream";
54
import Client from "../lib/client";
65
import * as Types from "../lib/types";
76
import { getStreamData } from "./helpers/stream";
@@ -84,6 +83,16 @@ describe("client", () => {
8483
deepEqual(res, {});
8584
});
8685

86+
it("broadcast", async () => {
87+
const res = await client.broadcast([testMsg, testMsg]);
88+
const req = getRecentReq();
89+
equal(req.headers.authorization, "Bearer test_channel_access_token");
90+
equal(req.path, "/message/broadcast");
91+
equal(req.method, "POST");
92+
deepEqual(req.body.messages, [testMsg, testMsg]);
93+
deepEqual(res, {});
94+
});
95+
8796
it("getProfile", async () => {
8897
const res = await client.getProfile("test_user_id");
8998
const req = getRecentReq();
@@ -362,4 +371,30 @@ describe("client", () => {
362371
equal(req.query.date, date);
363372
equal(req.method, "GET");
364373
});
374+
375+
it("getTargetLimitForAdditionalMessages", async () => {
376+
await client.getTargetLimitForAdditionalMessages();
377+
const req = getRecentReq();
378+
equal(req.headers.authorization, "Bearer test_channel_access_token");
379+
equal(req.path, "/message/quota");
380+
equal(req.method, "GET");
381+
});
382+
383+
it("getNumberOfMessagesSentThisMonth", async () => {
384+
await client.getNumberOfMessagesSentThisMonth();
385+
const req = getRecentReq();
386+
equal(req.headers.authorization, "Bearer test_channel_access_token");
387+
equal(req.path, "/message/quota/consumption");
388+
equal(req.method, "GET");
389+
});
390+
391+
it("getNumberOfSentBroadcastMessages", async () => {
392+
const date = "20191231";
393+
await client.getNumberOfSentBroadcastMessages(date);
394+
const req = getRecentReq();
395+
equal(req.headers.authorization, "Bearer test_channel_access_token");
396+
equal(req.path, "/message/delivery/broadcast");
397+
equal(req.query.date, date);
398+
equal(req.method, "GET");
399+
});
365400
});

0 commit comments

Comments
 (0)