Skip to content

Commit b5e882a

Browse files
SombreroElGringoHyunje Jun
authored andcommitted
Get number of messages sent #115 (#116)
* Get number of messages sent #115 • Get number of sent reply messages • Get number of sent push messages • Get number of sent multicast messages * Update docs * Update docs
1 parent c5817ca commit b5e882a

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

docs/api-reference/client.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Client {
4646

4747
// Account link
4848
getLinkToken(userId: string): Promise<string>
49+
50+
// Get number of messages sent
51+
getNumberOfSentReplyMessages(date: string): Promise<NumberOfMessagesSentResponse>
52+
getNumberOfSentPushMessages(date: string): Promise<NumberOfMessagesSentResponse>
53+
getNumberOfSentMulticastMessages(date: string): Promise<NumberOfMessagesSentResponse>
4954
}
5055
```
5156

@@ -362,8 +367,49 @@ It corresponds to the [Cancel default rich menu](https://developers.line.me/en/r
362367

363368
#### `getLinkToken(userId: string): Promise<string>`
364369

365-
Send an HTTP POST request to the `/bot/user/{userId}/linkToken` endpoint,
370+
Send an HTTP POST request to the `/bot/user/{userId}/linkToken` endpoint,
366371
and [issue a link token](https://developers.line.me/en/reference/messaging-api/#issue-link-token) for the user you are attempting to link.
367372

368-
If the request succeeds, a link token will be returned.
373+
If the request succeeds, a link token will be returned.
369374
Link tokens are valid for 10 minutes and can only be used once.
375+
376+
### Get number of messages sent
377+
378+
#### `getNumberOfSentReplyMessages(date: string): Promise<NumberOfMessagesSentResponse>`
379+
380+
Gets the number of messages sent with the `/bot/message/reply` endpoint.
381+
382+
The number of messages retrieved by this operation does not include
383+
the number of messages sent from LINE@ Manager.
384+
385+
``` js
386+
client.getNumberOfSentReplyMessages('20191231').then((response) => {
387+
console.log(response);
388+
})
389+
```
390+
391+
#### `getNumberOfSentPushMessages(date: string): Promise<NumberOfMessagesSentResponse>`
392+
393+
Gets the number of messages sent with the `/bot/message/push` endpoint.
394+
395+
The number of messages retrieved by this operation does not include
396+
the number of messages sent from LINE@ Manager.
397+
398+
``` js
399+
client.getNumberOfSentPushMessages('20191231').then((response) => {
400+
console.log(response);
401+
})
402+
```
403+
404+
#### `getNumberOfSentMulticastMessages(date: string): Promise<NumberOfMessagesSentResponse>`
405+
406+
Gets the number of messages sent with the `/bot/message/multicast` endpoint.
407+
408+
The number of messages retrieved by this operation does not include
409+
the number of messages sent from LINE@ Manager.
410+
411+
``` js
412+
client.getNumberOfSentMulticastMessages('20191231').then((response) => {
413+
console.log(response);
414+
})
415+
```

lib/client.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,34 @@ export default class Client {
213213
.then(checkJSON)
214214
.then(res => res.linkToken);
215215
}
216+
217+
public getNumberOfSentReplyMessages(
218+
date: string,
219+
): Promise<Types.NumberOfMessagesSentResponse> {
220+
return this.http
221+
.get<Types.NumberOfMessagesSentResponse>(
222+
`/message/delivery/reply?date=${date}`,
223+
)
224+
.then(checkJSON);
225+
}
226+
227+
public getNumberOfSentPushMessages(
228+
date: string,
229+
): Promise<Types.NumberOfMessagesSentResponse> {
230+
return this.http
231+
.get<Types.NumberOfMessagesSentResponse>(
232+
`/message/delivery/push?date=${date}`,
233+
)
234+
.then(checkJSON);
235+
}
236+
237+
public getNumberOfSentMulticastMessages(
238+
date: string,
239+
): Promise<Types.NumberOfMessagesSentResponse> {
240+
return this.http
241+
.get<Types.NumberOfMessagesSentResponse>(
242+
`/message/delivery/multicast?date=${date}`,
243+
)
244+
.then(checkJSON);
245+
}
216246
}

lib/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,3 +1603,19 @@ export type RichMenu = {
16031603
};
16041604

16051605
export type RichMenuResponse = { richMenuId: string } & RichMenu;
1606+
1607+
export type NumberOfMessagesSentResponse = {
1608+
/**
1609+
* Status of the counting process. One of the following values is returned:
1610+
* - `ready`: You can get the number of messages.
1611+
* - `unready`: The message counting process for the date specified in date has not been completed yet.
1612+
* Retry your request later. Normally, the counting process is completed within the next day.
1613+
* - `out_of_service`: The date specified in date is earlier than March 31, 2018, when the operation of the counting system started.
1614+
*/
1615+
status: "ready" | "unready" | "out_of_service";
1616+
/**
1617+
* The number of messages sent with the Messaging API on the date specified in date.
1618+
* The response has this property only when the value of status is `ready`.
1619+
*/
1620+
success?: number;
1621+
};

test/client.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,37 @@ describe("client", () => {
332332
equal(req.method, "POST");
333333
});
334334
});
335+
336+
it("getNumberOfSentReplyMessages", () => {
337+
const date = "20191231";
338+
return client.getNumberOfSentReplyMessages(date).then(() => {
339+
const req = getRecentReq();
340+
equal(req.headers.authorization, "Bearer test_channel_access_token");
341+
equal(req.path, "/message/delivery/reply");
342+
equal(req.query.date, date);
343+
equal(req.method, "GET");
344+
});
345+
});
346+
347+
it("getNumberOfSentPushMessages", () => {
348+
const date = "20191231";
349+
return client.getNumberOfSentPushMessages(date).then(() => {
350+
const req = getRecentReq();
351+
equal(req.headers.authorization, "Bearer test_channel_access_token");
352+
equal(req.path, "/message/delivery/push");
353+
equal(req.query.date, date);
354+
equal(req.method, "GET");
355+
});
356+
});
357+
358+
it("getNumberOfSentMulticastMessages", () => {
359+
const date = "20191231";
360+
return client.getNumberOfSentMulticastMessages(date).then(() => {
361+
const req = getRecentReq();
362+
equal(req.headers.authorization, "Bearer test_channel_access_token");
363+
equal(req.path, "/message/delivery/multicast");
364+
equal(req.query.date, date);
365+
equal(req.method, "GET");
366+
});
367+
});
335368
});

0 commit comments

Comments
 (0)