Skip to content

Commit 21844f1

Browse files
author
Hyunje Jun
committed
Improve rich menu API types and methods
1 parent 952e05e commit 21844f1

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/client.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,24 @@ export default class Client {
119119
return this.post(URL.leaveRoom(roomId));
120120
}
121121

122-
public getRichMenu(
123-
richMenuId: string,
124-
): Promise<Types.RichMenuId & Types.RichMenu> {
122+
public getRichMenu(richMenuId: string): Promise<Types.RichMenuResponse> {
125123
return this.get(URL.richMenu(richMenuId)).then(checkJSON);
126124
}
127125

128-
public createRichMenu(richMenu: Types.RichMenu): Promise<Types.RichMenuId> {
129-
return this.post(URL.richMenu(), richMenu).then(checkJSON);
126+
public createRichMenu(richMenu: Types.RichMenu): Promise<string> {
127+
return this.post(URL.richMenu(), richMenu)
128+
.then(checkJSON)
129+
.then(res => res.richMenuId);
130130
}
131131

132132
public deleteRichMenu(richMenuId: string): Promise<any> {
133133
return this.delete(URL.richMenu(richMenuId));
134134
}
135135

136-
public getRichMenuIdOfUser(userId: string): Promise<Types.RichMenuId> {
137-
return this.get(URL.userRichMenu(userId)).then(checkJSON);
136+
public getRichMenuIdOfUser(userId: string): Promise<string> {
137+
return this.get(URL.userRichMenu(userId))
138+
.then(checkJSON)
139+
.then(res => res.richMenuId);
138140
}
139141

140142
public linkRichMenuToUser(userId: string, richMenuId: string): Promise<any> {
@@ -160,8 +162,10 @@ export default class Client {
160162
return this.postBinary(URL.richMenuContent(richMenuId), data, contentType);
161163
}
162164

163-
public getRichMenuList(): Promise<Array<Types.RichMenuId & Types.RichMenu>> {
164-
return this.get(URL.richMenuList()).then(checkJSON);
165+
public getRichMenuList(): Promise<Array<Types.RichMenuResponse>> {
166+
return this.get(URL.richMenuList())
167+
.then(checkJSON)
168+
.then(res => res.richmenus);
165169
}
166170

167171
private authHeader(): { [key: string]: string } {

lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ export type Size = {
276276
height: number;
277277
};
278278

279-
export type RichMenuId = { richMenuId: string };
280-
281279
export type RichMenu = {
282280
size: Size;
283281
selected: boolean;
284282
name: string;
285283
chatBarText: string;
286284
areas: Array<{ bounds: Area; action: Action<{}> }>;
287285
};
286+
287+
export type RichMenuResponse = { richMenuId: string } & RichMenu;

0 commit comments

Comments
 (0)