Skip to content

Commit 8957eb1

Browse files
authored
Merge pull request #465 from line/next
Release 7.6.0
2 parents 65254a9 + bdf71d6 commit 8957eb1

File tree

12 files changed

+1140
-636
lines changed

12 files changed

+1140
-636
lines changed

.github/workflows/commit-changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
1818
- name: Install Dependency

.github/workflows/deploy-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: Use Node.js 14
1515
uses: actions/setup-node@v3
1616
with:
@@ -22,7 +22,7 @@ jobs:
2222
git config --global user.email "action@github.com"
2323
git config --global user.name "GitHub Action"
2424
- name: Clone Doc History
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626
with:
2727
ref: 'gh-pages'
2828
path: 'doc-dist'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
# Setup .npmrc file to publish to GitHub Packages
1111
- uses: actions/setup-node@v3
1212
with:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
name: Node.js ${{ matrix.node }}
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020
- name: Setup Node.js
2121
uses: actions/setup-node@v3
2222
with:

docs/api-reference/client.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class Client {
3030
broadcast(messages: Message | Message[], notificationDisabled: boolean = false): Promise<MessageAPIResponseBase>
3131
getMessageContent(messageId: string): Promise<Readable>
3232

33+
// Validate message objects
34+
validatePushMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
35+
validateReplyMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
36+
validateMulticastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
37+
validateNarrowcastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
38+
validateBroadcastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
39+
3340
// Profile
3441
getProfile(userId: string): Promise<Profile>
3542

@@ -84,6 +91,7 @@ class Client {
8491
getNumberOfFollowers(date: string): Promise<Types.NumberOfFollowersResponse>
8592
getFriendDemographics(): Promise<Types.FriendDemographics>
8693
getUserInteractionStatistics(requestId: string): Promise<Types.UserInteractionStatistics>
94+
getStatisticsPerUnit(customAggregationUnit: string, from: string, to: string): Promise<Types.StatisticsPerUnit>
8795

8896
// AudienceGroup
8997
createUploadAudienceGroup(uploadAudienceGroup: {
@@ -307,6 +315,72 @@ client.getMessageContent('message_id')
307315
stream.pipe(...)
308316
})
309317
```
318+
### Validate message objects
319+
320+
#### `validatePushMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`
321+
322+
It corresponds to the [Validate push message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-push-message) API.
323+
324+
The argument is messages to be sent.
325+
326+
``` js
327+
client.validatePushMessageObjects({
328+
type: 'text',
329+
text: 'hello, world',
330+
})
331+
```
332+
333+
#### `validateReplyMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`
334+
335+
It corresponds to the [Validate reply message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-reply-message) API.
336+
337+
The argument is messages to be sent.
338+
339+
``` js
340+
client.validateReplyMessageObjects({
341+
type: 'text',
342+
text: 'hello, world',
343+
})
344+
```
345+
346+
#### `validateMulticastMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`
347+
348+
It corresponds to the [Validate multicast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-multicast-message) API.
349+
350+
The argument is messages to be sent.
351+
352+
``` js
353+
client.validateMulticastMessageObjects({
354+
type: 'text',
355+
text: 'hello, world',
356+
})
357+
```
358+
359+
#### `validateNarrowcastMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`
360+
361+
It corresponds to the [Validate narrowcast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-narrowcast-message) API.
362+
363+
The argument is messages to be sent.
364+
365+
``` js
366+
client.validateNarrowcastMessageObjects({
367+
type: 'text',
368+
text: 'hello, world',
369+
})
370+
```
371+
372+
#### `validateBroadcastMessageObjects(messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`
373+
374+
It corresponds to the [Validate broadcast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-broadcast-message) API.
375+
376+
The argument is messages to be sent.
377+
378+
``` js
379+
client.validateBroadcastMessageObjects({
380+
type: 'text',
381+
text: 'hello, world',
382+
})
383+
```
310384

311385
### Profile
312386

@@ -751,6 +825,14 @@ It corresponds to the [Get number of followers](https://developers.line.biz/en/r
751825

752826
It corresponds to the [Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic) API.
753827

828+
#### `getUserInteractionStatistics(): Promise<Types.UserInteractionStatistics>`
829+
830+
It corresponds to the [Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event) API.
831+
832+
#### `getStatisticsPerUnit(): Promise<Types.StatisticsPerUnit>`
833+
834+
It corresponds to the [Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit) API.
835+
754836
### Bot
755837

756838
#### `getBotInfo(): Promise<BotInfoResponse>`

lib/client.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ export default class Client {
6666
to: string,
6767
messages: Types.Message | Types.Message[],
6868
notificationDisabled: boolean = false,
69+
customAggregationUnits?: string[],
6970
): Promise<Types.MessageAPIResponseBase> {
7071
return this.http.post(
7172
`${MESSAGING_API_PREFIX}/message/push`,
7273
{
7374
messages: toArray(messages),
7475
to,
7576
notificationDisabled,
77+
customAggregationUnits,
7678
},
7779
this.generateRequestConfig(),
7880
);
@@ -94,13 +96,15 @@ export default class Client {
9496
to: string[],
9597
messages: Types.Message | Types.Message[],
9698
notificationDisabled: boolean = false,
99+
customAggregationUnits?: string[],
97100
): Promise<Types.MessageAPIResponseBase> {
98101
return this.http.post(
99102
`${MESSAGING_API_PREFIX}/message/multicast`,
100103
{
101104
messages: toArray(messages),
102105
to,
103106
notificationDisabled,
107+
customAggregationUnits,
104108
},
105109
this.generateRequestConfig(),
106110
);
@@ -140,6 +144,89 @@ export default class Client {
140144
);
141145
}
142146

147+
public validatePushMessageObjects(
148+
messages: Types.Message | Types.Message[],
149+
): Promise<Types.MessageAPIResponseBase> {
150+
return this.http.post(
151+
`${MESSAGING_API_PREFIX}/message/validate/push`,
152+
{
153+
messages: toArray(messages),
154+
},
155+
this.generateRequestConfig(),
156+
);
157+
}
158+
159+
public validateReplyMessageObjects(
160+
messages: Types.Message | Types.Message[],
161+
): Promise<Types.MessageAPIResponseBase> {
162+
return this.http.post(`${MESSAGING_API_PREFIX}/message/validate/reply`, {
163+
messages: toArray(messages),
164+
});
165+
}
166+
167+
public async validateMulticastMessageObjects(
168+
messages: Types.Message | Types.Message[],
169+
): Promise<Types.MessageAPIResponseBase> {
170+
return this.http.post(
171+
`${MESSAGING_API_PREFIX}/message/validate/multicast`,
172+
{
173+
messages: toArray(messages),
174+
},
175+
this.generateRequestConfig(),
176+
);
177+
}
178+
179+
public async validateNarrowcastMessageObjects(
180+
messages: Types.Message | Types.Message[],
181+
): Promise<Types.MessageAPIResponseBase> {
182+
return this.http.post(
183+
`${MESSAGING_API_PREFIX}/message/validate/narrowcast`,
184+
{
185+
messages: toArray(messages),
186+
},
187+
this.generateRequestConfig(),
188+
);
189+
}
190+
191+
public async validateBroadcastMessageObjects(
192+
messages: Types.Message | Types.Message[],
193+
): Promise<Types.MessageAPIResponseBase> {
194+
return this.http.post(
195+
`${MESSAGING_API_PREFIX}/message/validate/broadcast`,
196+
{
197+
messages: toArray(messages),
198+
},
199+
this.generateRequestConfig(),
200+
);
201+
}
202+
203+
public validateCustomAggregationUnits(units: string[]): {
204+
messages: string[];
205+
valid: boolean;
206+
} {
207+
const messages: string[] = [];
208+
if (units.length > 1) {
209+
messages.push("customAggregationUnits can only contain one unit");
210+
}
211+
units.forEach((unit, index) => {
212+
if (unit.length > 30) {
213+
messages.push(
214+
`customAggregationUnits[${index}] must be less than or equal to 30 characters`,
215+
);
216+
}
217+
if (!/^[a-zA-Z0-9_]+$/.test(unit)) {
218+
messages.push(
219+
`customAggregationUnits[${index}] must be alphanumeric characters or underscores`,
220+
);
221+
}
222+
});
223+
224+
return {
225+
messages,
226+
valid: messages.length === 0,
227+
};
228+
}
229+
143230
public async getProfile(userId: string): Promise<Types.Profile> {
144231
const profile = await this.http.get<Types.Profile>(
145232
`${MESSAGING_API_PREFIX}/profile/${userId}`,
@@ -515,6 +602,17 @@ export default class Client {
515602
return ensureJSON(res);
516603
}
517604

605+
public async getStatisticsPerUnit(
606+
customAggregationUnit: string,
607+
from: string,
608+
to: string,
609+
): Promise<Types.StatisticsPerUnit> {
610+
const res = await this.http.get<Types.StatisticsPerUnit>(
611+
`${MESSAGING_API_PREFIX}/insight/message/event/aggregation?customAggregationUnit=${customAggregationUnit}&from=${from}&to=${to}`,
612+
);
613+
return ensureJSON(res);
614+
}
615+
518616
public async createUploadAudienceGroup(uploadAudienceGroup: {
519617
description: string;
520618
isIfaAudience?: boolean;
@@ -722,6 +820,13 @@ export default class Client {
722820
);
723821
return ensureJSON(res);
724822
}
823+
824+
public async validateRichMenu(richMenu: Types.RichMenu): Promise<{}> {
825+
return await this.http.post<{}>(
826+
`${MESSAGING_API_PREFIX}/richmenu/validate`,
827+
richMenu,
828+
);
829+
}
725830
}
726831

727832
export class OAuth {

lib/exceptions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
export class SignatureValidationFailed extends Error {
2-
constructor(message: string, public signature?: string) {
2+
constructor(
3+
message: string,
4+
public signature?: string,
5+
) {
36
super(message);
47
}
58
}
69

710
export class JSONParseError extends Error {
8-
constructor(message: string, public raw: any) {
11+
constructor(
12+
message: string,
13+
public raw: any,
14+
) {
915
super(message);
1016
}
1117
}

0 commit comments

Comments
 (0)