Skip to content

Commit 14ba023

Browse files
SombreroElGringoHyunje Jun
authored andcommitted
Add getLinkToken (#96)
Function getLinkToken added #95
1 parent c79d65c commit 14ba023

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/api-reference/client.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Client {
4343
setDefaultRichMenu(richMenuId: string): Promise<{}>
4444
getDefaultRichMenuId(): Promise<string>
4545
deleteDefaultRichMenu(): Promise<{}>
46+
47+
// Account link
48+
getLinkToken(userId: string): Promise<string>
4649
}
4750
```
4851

@@ -354,3 +357,13 @@ It corresponds to the [Get default rich menu ID](https://developers.line.me/en/r
354357
### `deleteDefaultRichMenu(): Promise<{}>`
355358

356359
It corresponds to the [Cancel default rich menu](https://developers.line.me/en/reference/messaging-api/#cancel-default-rich-menu) API.
360+
361+
### Account link
362+
363+
#### `getLinkToken(userId: string): Promise<string>`
364+
365+
Send an HTTP POST request to the `/bot/user/{userId}/linkToken` endpoint,
366+
and [issue a link token](https://developers.line.me/en/reference/messaging-api/#issue-link-token) for the user you are attempting to link.
367+
368+
If the request succeeds, a link token will be returned.
369+
Link tokens are valid for 10 minutes and can only be used once.

lib/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ export default class Client {
200200
public deleteDefaultRichMenu(): Promise<{}> {
201201
return this.http.delete("/user/all/richmenu");
202202
}
203+
204+
public getLinkToken(userId: string): Promise<string> {
205+
return this.http
206+
.post<any>(`/user/${userId}/linkToken`)
207+
.then(checkJSON)
208+
.then(res => res.linkToken);
209+
}
203210
}

test/client.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,13 @@ describe("client", () => {
323323
deepEqual(res, {});
324324
});
325325
});
326+
327+
it("getLinkToken", () => {
328+
return client.getLinkToken("test_user_id").then(() => {
329+
const req = getRecentReq();
330+
equal(req.headers.authorization, "Bearer test_channel_access_token");
331+
equal(req.path, "/user/test_user_id/linkToken");
332+
equal(req.method, "POST");
333+
});
334+
});
326335
});

0 commit comments

Comments
 (0)