Skip to content

Commit

Permalink
Merge pull request #465 from line/next
Browse files Browse the repository at this point in the history
Release 7.6.0
  • Loading branch information
Yang-33 authored Sep 21, 2023
2 parents 65254a9 + bdf71d6 commit 8957eb1
Show file tree
Hide file tree
Showing 12 changed files with 1,140 additions and 636 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependency
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js 14
uses: actions/setup-node@v3
with:
Expand All @@ -22,7 +22,7 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: Clone Doc History
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'gh-pages'
path: 'doc-dist'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Node.js ${{ matrix.node }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
Expand Down
82 changes: 82 additions & 0 deletions docs/api-reference/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Client {
broadcast(messages: Message | Message[], notificationDisabled: boolean = false): Promise<MessageAPIResponseBase>
getMessageContent(messageId: string): Promise<Readable>

// Validate message objects
validatePushMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
validateReplyMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
validateMulticastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
validateNarrowcastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>
validateBroadcastMessageObjects(messages: Types.Message | Types.Message[]): Promise<Types.MessageAPIResponseBase>

// Profile
getProfile(userId: string): Promise<Profile>

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

// AudienceGroup
createUploadAudienceGroup(uploadAudienceGroup: {
Expand Down Expand Up @@ -307,6 +315,72 @@ client.getMessageContent('message_id')
stream.pipe(...)
})
```
### Validate message objects

#### `validatePushMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`

It corresponds to the [Validate push message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-push-message) API.

The argument is messages to be sent.

``` js
client.validatePushMessageObjects({
type: 'text',
text: 'hello, world',
})
```

#### `validateReplyMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`

It corresponds to the [Validate reply message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-reply-message) API.

The argument is messages to be sent.

``` js
client.validateReplyMessageObjects({
type: 'text',
text: 'hello, world',
})
```

#### `validateMulticastMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`

It corresponds to the [Validate multicast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-multicast-message) API.

The argument is messages to be sent.

``` js
client.validateMulticastMessageObjects({
type: 'text',
text: 'hello, world',
})
```

#### `validateNarrowcastMessageObjects(messages: Message | Message[]): Promise<MessageAPIResponseBase>`

It corresponds to the [Validate narrowcast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-narrowcast-message) API.

The argument is messages to be sent.

``` js
client.validateNarrowcastMessageObjects({
type: 'text',
text: 'hello, world',
})
```

#### `validateBroadcastMessageObjects(messages: Message | Message[], notificationDisabled: boolean = false): Promise<any>`

It corresponds to the [Validate broadcast message objects](https://developers.line.biz/en/reference/messaging-api/#validate-message-objects-of-broadcast-message) API.

The argument is messages to be sent.

``` js
client.validateBroadcastMessageObjects({
type: 'text',
text: 'hello, world',
})
```

### Profile

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

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

#### `getUserInteractionStatistics(): Promise<Types.UserInteractionStatistics>`

It corresponds to the [Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event) API.

#### `getStatisticsPerUnit(): Promise<Types.StatisticsPerUnit>`

It corresponds to the [Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit) API.

### Bot

#### `getBotInfo(): Promise<BotInfoResponse>`
Expand Down
105 changes: 105 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export default class Client {
to: string,
messages: Types.Message | Types.Message[],
notificationDisabled: boolean = false,
customAggregationUnits?: string[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/push`,
{
messages: toArray(messages),
to,
notificationDisabled,
customAggregationUnits,
},
this.generateRequestConfig(),
);
Expand All @@ -94,13 +96,15 @@ export default class Client {
to: string[],
messages: Types.Message | Types.Message[],
notificationDisabled: boolean = false,
customAggregationUnits?: string[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/multicast`,
{
messages: toArray(messages),
to,
notificationDisabled,
customAggregationUnits,
},
this.generateRequestConfig(),
);
Expand Down Expand Up @@ -140,6 +144,89 @@ export default class Client {
);
}

public validatePushMessageObjects(
messages: Types.Message | Types.Message[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/validate/push`,
{
messages: toArray(messages),
},
this.generateRequestConfig(),
);
}

public validateReplyMessageObjects(
messages: Types.Message | Types.Message[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(`${MESSAGING_API_PREFIX}/message/validate/reply`, {
messages: toArray(messages),
});
}

public async validateMulticastMessageObjects(
messages: Types.Message | Types.Message[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/validate/multicast`,
{
messages: toArray(messages),
},
this.generateRequestConfig(),
);
}

public async validateNarrowcastMessageObjects(
messages: Types.Message | Types.Message[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/validate/narrowcast`,
{
messages: toArray(messages),
},
this.generateRequestConfig(),
);
}

public async validateBroadcastMessageObjects(
messages: Types.Message | Types.Message[],
): Promise<Types.MessageAPIResponseBase> {
return this.http.post(
`${MESSAGING_API_PREFIX}/message/validate/broadcast`,
{
messages: toArray(messages),
},
this.generateRequestConfig(),
);
}

public validateCustomAggregationUnits(units: string[]): {
messages: string[];
valid: boolean;
} {
const messages: string[] = [];
if (units.length > 1) {
messages.push("customAggregationUnits can only contain one unit");
}
units.forEach((unit, index) => {
if (unit.length > 30) {
messages.push(
`customAggregationUnits[${index}] must be less than or equal to 30 characters`,
);
}
if (!/^[a-zA-Z0-9_]+$/.test(unit)) {
messages.push(
`customAggregationUnits[${index}] must be alphanumeric characters or underscores`,
);
}
});

return {
messages,
valid: messages.length === 0,
};
}

public async getProfile(userId: string): Promise<Types.Profile> {
const profile = await this.http.get<Types.Profile>(
`${MESSAGING_API_PREFIX}/profile/${userId}`,
Expand Down Expand Up @@ -515,6 +602,17 @@ export default class Client {
return ensureJSON(res);
}

public async getStatisticsPerUnit(
customAggregationUnit: string,
from: string,
to: string,
): Promise<Types.StatisticsPerUnit> {
const res = await this.http.get<Types.StatisticsPerUnit>(
`${MESSAGING_API_PREFIX}/insight/message/event/aggregation?customAggregationUnit=${customAggregationUnit}&from=${from}&to=${to}`,
);
return ensureJSON(res);
}

public async createUploadAudienceGroup(uploadAudienceGroup: {
description: string;
isIfaAudience?: boolean;
Expand Down Expand Up @@ -722,6 +820,13 @@ export default class Client {
);
return ensureJSON(res);
}

public async validateRichMenu(richMenu: Types.RichMenu): Promise<{}> {
return await this.http.post<{}>(
`${MESSAGING_API_PREFIX}/richmenu/validate`,
richMenu,
);
}
}

export class OAuth {
Expand Down
10 changes: 8 additions & 2 deletions lib/exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
export class SignatureValidationFailed extends Error {
constructor(message: string, public signature?: string) {
constructor(
message: string,
public signature?: string,
) {
super(message);
}
}

export class JSONParseError extends Error {
constructor(message: string, public raw: any) {
constructor(
message: string,
public raw: any,
) {
super(message);
}
}
Expand Down
Loading

0 comments on commit 8957eb1

Please sign in to comment.