Skip to content

Commit 2344314

Browse files
author
Hyunje Jun
committed
Update docs according to the recent changes
1 parent a0074d5 commit 2344314

File tree

9 files changed

+76
-41
lines changed

9 files changed

+76
-41
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# How to contribute to LINE Bot SDK for Node.js
22

33
First of all, thank you so much for taking your time to contribute! LINE Bot SDK
4-
for Node.js is not very different from any other open source projects you are
5-
aware of. It will be amazing if you could help us by doing any of the following:
4+
for Node.js is not very different from any other open source projects. It will
5+
be fantastic if you help us by doing any of the following:
66

77
- File an issue in [the issue tracker](https://github.com/line/line-bot-sdk-nodejs/issues)
88
to report bugs and propose new features and improvements.
@@ -17,7 +17,6 @@ Here are each top-level directory explained:
1717

1818
* `lib`: TypeScript source code. You may modify files under this directory.
1919
* `test`: Mocha test suites. Please add tests for modification if possible.
20-
* `types`: Project-level type declarations
2120
* `examples`: Example projects using this SDK
2221
* `docs`: [GitBook](https://www.gitbook.com/) markdowns for project documentation
2322
* `tools`: Useful tools

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
* [validateSignature](pages/api-reference/validate-signature.md)
1414
* [middleware](pages/api-reference/middleware.md)
1515
* [Exceptions](pages/api-reference/exceptions.md)
16+
* [Message and event objects](pages/api-reference/message-and-event-objects.md)
1617
* [Contributing](CONTRIBUTING.md)
1718
* [GitHub](https://github.com/line/line-bot-sdk-nodejs/)

docs/pages/api-reference.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API Reference
22

3-
When imported via `require` or `import`, 3 interfaces are exposed.
3+
Please import the library via `require` or `import`.
44

55
``` js
66
// CommonJS
@@ -15,15 +15,5 @@ For the detailed API reference of each, please refer to their own pages.
1515
- [Client](api-reference/client.md)
1616
- [validateSignature](api-reference/validate-signature.md)
1717
- [middleware](api-reference/middleware.md)
18-
19-
Exceptions can be imported via `@line/bot-sdk/exceptions`.
20-
21-
``` js
22-
// CommonJS
23-
const JSONParseError = require('@line/bot-sdk/exceptions').JSONParseError;
24-
25-
// ES2015 modules or TypeScript
26-
import { JSONParseError } from '@line/bot-sdk/exceptions';
27-
```
28-
2918
- [Exceptions](api-reference/exceptions.md)
19+
- [Message and event objects](api-reference/message-and-event-objects.md)

docs/pages/api-reference/client.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ class Client {
2626
```
2727

2828
`Message` is a valid message object. About message object structure, please
29-
refer to [Send message object](https://developers.line.me/en/docs/messaging-api/reference/#message-objects)
30-
of the official documentation.
29+
refer to [Message and event objects](./message-and-event-objects.md) on this guide, or
30+
[Send message object](https://developers.line.me/en/docs/messaging-api/reference/#message-objects)
31+
on the official documentation.
3132

32-
`ClientConfig` type is like below, except that it also allows fields
33-
from [MiddlewareConfig](./middleware.md) too.
33+
`ClientConfig` type is like below.
3434

3535
``` typescript
36-
type ClientConfig = {
37-
channelAccessToken: string,
36+
interface ClientConfig {
37+
channelAccessToken: string;
38+
channelSecret?: string;
3839
}
3940
```
4041

docs/pages/api-reference/exceptions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Exceptions
22

3-
Exception classes can be imported via `@line/bot-sdk/exceptions'`.
3+
Exception classes can also be imported from `@line/bot-sdk`.
44

55
``` js
6-
// CommonJS
7-
const HTTPError = require('@line/bot-sdk/exceptions').HTTPError;
8-
const JSONParseError = require('@line/bot-sdk/exceptions').JSONParseError;
9-
const ReadError = require('@line/bot-sdk/exceptions').ReadError;
10-
const RequestError = require('@line/bot-sdk/exceptions').RequestError;
11-
const SignatureValidationFailed = require('@line/bot-sdk/exceptions').SignatureValidationFailed;
6+
// CommonJS (destructuring can be used for Node.js >= 6)
7+
const HTTPError = require('@line/bot-sdk').HTTPError;
8+
const JSONParseError = require('@line/bot-sdk').JSONParseError;
9+
const ReadError = require('@line/bot-sdk').ReadError;
10+
const RequestError = require('@line/bot-sdk').RequestError;
11+
const SignatureValidationFailed = require('@line/bot-sdk').SignatureValidationFailed;
1212

1313
// ES2015 modules or TypeScript
1414
import {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Message and event objects
2+
3+
The message objects and event objects are plain JS objects with no
4+
abstraction. This SDK provides TypeScript types for them, which can be imported
5+
from `@line/bot-sdk`.
6+
7+
Please beware that the types only work in TypeScript, and will be removed when
8+
built into JavaScript.
9+
10+
``` typescript
11+
import {
12+
// webhook event objects
13+
WebhookEvent,
14+
MessageEvent,
15+
EventSource,
16+
VideoEventMessage,
17+
18+
// message event objects
19+
Message,
20+
TemplateMessage,
21+
TemplateContent,
22+
} from "@line/bot-sdk";
23+
```
24+
25+
For the actual type definitions, please refer to [types.ts](https://github.com/line/line-bot-sdk-nodejs/blob/master/lib/types.ts)
26+
directly.
27+
28+
You can also refer to the official specification:
29+
30+
- [Message objects](https://developers.line.me/en/docs/messaging-api/reference/#message-objects)
31+
- [Webhook event objects](https://developers.line.me/en/docs/messaging-api/reference/#webhook-event-objects)

docs/pages/api-reference/middleware.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ by several Node.js web frameworks such as [Express](https://expressjs.com/).
99
function middleware(config: MiddlewareConfig): Middleware
1010
```
1111

12-
The types of `MiddlewareConfig` and `Middleware` are like below, except that the config allows
13-
fields from [ClientConfig](./client.md) too.
12+
The types of `MiddlewareConfig` and `Middleware` are like below.
1413

1514
``` typescript
16-
type MiddlewareConfig = {
17-
channelSecret: string,
15+
interface MiddlewareConfig {
16+
channelAccessToken?: string;
17+
channelSecret: string;
1818
}
1919
2020
type Middleware =

docs/pages/guide/typescript.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Also, when building a complex message object, you can make use of types for
2626
its fields.
2727

2828
``` typescript
29-
const message: Line.TemplateMessage = {
29+
const message: TemplateMessage = {
3030
type: "template",
3131
altText: "cannot display template message",
3232
template: {
@@ -45,7 +45,7 @@ const message: Line.TemplateMessage = {
4545
```
4646

4747
The object above will be type-checked to have the type of
48-
`Line.TemplateMessage`, and thus ensured not to miss any required field.
48+
`TemplateMessage`, and thus ensured not to miss any required field.
4949

5050
Also, [literal type](https://www.typescriptlang.org/docs/handbook/advanced-types.html)
5151
is used for `type` fields, which means the compiler will complain if a wrong
@@ -57,9 +57,21 @@ The library is built to just-work with TypeScript too, so import the library and
5757
there you go.
5858

5959
``` typescript
60-
import { Client, validateSignature, middleware } from "@line/bot-sdk";
60+
import {
61+
// main APIs
62+
Client,
63+
middleware,
64+
65+
// exceptions
66+
JSONParseError,
67+
SignatureValidationFailed,
68+
69+
// types
70+
TemplateMessage,
71+
WebhookEvent,
72+
} from "@line/bot-sdk";
6173
```
6274

63-
Webhook event and message object types are defined in the `Line` namespace, e.g.
64-
`Line.WebhookEvent` or `Line.Message`. For declarations of the types, please
65-
refer to [global.d.ts](https://github.com/line/line-bot-sdk-nodejs/blob/master/types/global.d.ts).
75+
Message object and webhook event types can be also imported from `@line/bot-sdk`,
76+
e.g. `TemplateMessage` or `WebhookEvent`. For declarations of the types, please
77+
refer to [types.ts](https://github.com/line/line-bot-sdk-nodejs/blob/master/lib/types.ts).

docs/pages/guide/webhook.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function to do this.
2020

2121
**Webhook event object parsing** is literally parsing webhook event objects,
2222
which contains information of each webhook event. The objects are provided as
23-
request body in JSON format, so any body parser will work here.
23+
request body in JSON format, so any body parser will work here. For interal
24+
object types in this SDK, please refer to [Message and event objects](../api-reference/message-and-event-objects.md).
2425

2526
There is a function to generate a [connect](https://github.com/senchalabs/connect) middleware,
2627
[`middleware()`](../api-reference/middleware.md), to conduct both of them. If
@@ -131,8 +132,8 @@ The errors can be handled with [error middleware](https://github.com/senchalabs/
131132
``` js
132133
const express = require('express')
133134
const middleware = require('@line/bot-sdk').middleware
134-
const JSONParseError = require('@line/bot-sdk/exceptions').JSONParseError
135-
const SignatureValidationFailed = require('@line/bot-sdk/exceptions').SignatureValidationFailed
135+
const JSONParseError = require('@line/bot-sdk').JSONParseError
136+
const SignatureValidationFailed = require('@line/bot-sdk').SignatureValidationFailed
136137

137138
const app = express()
138139

0 commit comments

Comments
 (0)