Skip to content

Commit 909048d

Browse files
committed
update basic docs
1 parent 4010af3 commit 909048d

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

docs/getting-started/basic-usage.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ import * as line from '@line/bot-sdk';
1818
## Configuration
1919

2020
For the usage of webhook and client, LINE channel access token and secret are
21-
needed. About issuing the token and secret, please refer to [Getting started with the Messaging API](https://developers.line.biz/en/docs/messaging-api/getting-started/).
21+
needed. About issuing the token and secret, please refer
22+
to [Getting started with the Messaging API](https://developers.line.biz/en/docs/messaging-api/getting-started/).
2223

2324
``` js
24-
const config = {
25+
new line.messagingApi.MessagingApiClient({
26+
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
27+
});
28+
line.middleware({
2529
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
2630
channelSecret: 'YOUR_CHANNEL_SECRET'
27-
};
28-
29-
new line.Client(config);
30-
line.middleware(config);
31+
});
3132
```
3233

3334
## Synopsis
@@ -50,21 +51,27 @@ app.post('/webhook', line.middleware(config), (req, res) => {
5051
.then((result) => res.json(result));
5152
});
5253

53-
const client = new line.Client(config);
54+
const client = new line.messagingApi.MessagingApiClient({
55+
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
56+
});
5457
function handleEvent(event) {
5558
if (event.type !== 'message' || event.message.type !== 'text') {
5659
return Promise.resolve(null);
5760
}
5861

59-
return client.replyMessage(event.replyToken, {
60-
type: 'text',
61-
text: event.message.text
62+
return client.replyMessage({
63+
replyToken: event.replyToken,
64+
messages: [{
65+
type: 'text',
66+
text: event.message.text
67+
}],
6268
});
6369
}
6470

6571
app.listen(3000);
6672
```
6773

68-
The full examples with comments can be found in [examples](https://github.com/line/line-bot-sdk-nodejs/tree/master/examples/).
74+
The full examples with comments can be found
75+
in [examples](https://github.com/line/line-bot-sdk-nodejs/tree/master/examples/).
6976

7077
For the specifications of API, please refer to [API Reference](../api-reference.md).

docs/guide/client.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@ For type signatures of the methods, please refer to [its API reference](../api-r
77

88
## Create a client
99

10-
The `Client` class is provided by the main module.
10+
The `MessagingApiClient` class is provided by the main module.
1111

1212
``` js
1313
// CommonJS
14-
const Client = require('@line/bot-sdk').Client;
14+
const MessagingApiClient = require('@line/bot-sdk').messagingApi.MessagingApiClient;
1515

1616
// ES6 modules or TypeScript
17-
import { Client } from '@line/bot-sdk';
17+
import { messagingApi } from '@line/bot-sdk';
18+
const { MessagingApiClient } = messagingApi;
1819
```
1920

2021
To create a client instance:
2122

2223
```js
23-
const client = new Client({
24-
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
25-
channelSecret: 'YOUR_CHANNEL_SECRET'
24+
const client = new MessagingApiClient({
25+
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
2626
});
2727
```
2828

2929
And now you can call client functions as usual:
3030

3131
``` js
32-
client.pushMessage(userId, { type: 'text', text: 'hello, world' });
32+
client.pushMessage({
33+
to: userId,
34+
messages: [{ type: 'text', text: 'hello, world' }]
35+
});
3336
```
3437

3538
## Retrieving parameters from webhook
@@ -52,9 +55,12 @@ if (event.type === 'message') {
5255
} else if (event.source.type === 'group') {
5356
client.leaveGroup(event.source.groupId);
5457
} else {
55-
client.replyMessage(event.replyToken, {
56-
type: 'text',
57-
text: 'I cannot leave a 1-on-1 chat!',
58+
client.replyMessage({
59+
replyToken: event.replyToken,
60+
messages: [{
61+
type: 'text',
62+
text: 'I cannot leave a 1-on-1 chat!',
63+
}]
5864
});
5965
}
6066
}
@@ -74,13 +80,17 @@ There are 4 types of errors caused by client usage.
7480
- `HTTPError`: Server returns a non-2xx response.
7581
- `JSONParseError`: JSON parsing fails for response body.
7682

77-
For methods returning `Promise`, you can handle the errors with [`catch()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
83+
For methods returning `Promise`, you can handle the errors
84+
with [`catch()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
7885
method. For others returning `ReadableStream`, you can observe the `'error'`
7986
event for the stream.
8087

8188
``` js
8289
client
83-
.replyMessage(replyToken, message)
90+
.replyMessage({
91+
replyToken: replyToken,
92+
messages: [message]
93+
})
8494
.catch((err) => {
8595
if (err instanceof HTTPError) {
8696
console.error(err.statusCode);

docs/guide/typescript.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ and prevent possible typo and mistakes.
1616
``` typescript
1717
const config = {
1818
channelAccessToken: "", // typo Token
19-
channelSecret: "",
2019
}
2120

22-
const c = new Client(config) // will throw a compile error
21+
const c = new MessagingApiClient(config) // will throw a compile error
2322
```
2423

2524
Also, when building a complex message object, you can make use of types for
@@ -73,5 +72,5 @@ import {
7372
```
7473

7574
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).
75+
e.g. `TemplateMessage` or `Event`. For declarations of the types, please
76+
refer to [lib/](https://github.com/line/line-bot-sdk-nodejs/blob/master/lib/).

0 commit comments

Comments
 (0)