Skip to content

Commit e637ca4

Browse files
committed
implement richmenu apis
1 parent cf53691 commit e637ca4

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

lib/client.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get, post, stream } from "./http";
1+
import { get, post, stream, delete as deleteRequest } from "./http";
22
import * as Types from "./types";
33
import * as URL from "./urls";
44
import { toArray } from "./util";
@@ -102,10 +102,54 @@ export default class Client {
102102
return this.post(URL.leaveRoom(roomId));
103103
}
104104

105+
public getRichMenu(richMenuId: string): Promise<any> {
106+
return this.get(URL.richMenu(richMenuId));
107+
}
108+
109+
public createRichMenu(richMenu: Types.RichMenu): Promise<any> {
110+
return this.post(URL.richMenu(), richMenu);
111+
}
112+
113+
public deleteRichMenu(richMenuId: string): Promise<any> {
114+
return this.delete(URL.richMenu(richMenuId));
115+
}
116+
117+
public getUserRichMenuIds(userId: string): Promise<any> {
118+
return this.get(URL.userRichMenu(userId));
119+
}
120+
121+
public linkRichMenuWithUser(
122+
userId: string,
123+
richMenuId: string,
124+
): Promise<any> {
125+
return this.post(URL.userRichMenu(userId, richMenuId));
126+
}
127+
128+
public unlinkRichMenuWithUser(
129+
userId: string,
130+
richMenuId: string,
131+
): Promise<any> {
132+
return this.delete(URL.userRichMenu(userId, richMenuId));
133+
}
134+
135+
public getRichMenuContent(richMenuId: string): Promise<any> {
136+
return this.stream(URL.richMenuContent(richMenuId));
137+
}
138+
139+
// TODO: implement method for uploading richmenu image
140+
141+
public getRichMenuList(): Promise<any> {
142+
return this.get(URL.richMenuList());
143+
}
144+
105145
private authHeader(): { [key: string]: string } {
106146
return { Authorization: "Bearer " + this.config.channelAccessToken };
107147
}
108148

149+
private delete(url: string): Promise<any> {
150+
return deleteRequest(url, this.authHeader());
151+
}
152+
109153
private get(url: string): Promise<any> {
110154
return get(url, this.authHeader());
111155
}

lib/http.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,14 @@ export function post(url: string, headers: any, data?: any): Promise<any> {
6464
.then(res => checkJSON(res.data))
6565
.catch(wrapError);
6666
}
67+
68+
function del(url: string, headers: any): Promise<any> {
69+
headers["User-Agent"] = userAgent;
70+
71+
return axios
72+
.delete(url, { headers })
73+
.then(res => checkJSON(res.data))
74+
.catch(wrapError);
75+
}
76+
77+
export { del as delete };

lib/types.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export type ImageMapMessage = {
170170
type: "image";
171171
baseUrl: string;
172172
altText: string;
173-
baseSize: { width: number; height: number };
173+
baseSize: Size;
174174
actions: ImageMapAction[];
175175
};
176176

@@ -270,3 +270,21 @@ export type TemplateDatetimePickerAction = {
270270
max?: string;
271271
min?: string;
272272
};
273+
274+
export type Size = {
275+
width: number;
276+
height: number;
277+
};
278+
279+
export type RichMenuArea = {
280+
bounds: ImageMapArea;
281+
action: TemplateAction<any>;
282+
};
283+
284+
export type RichMenu = {
285+
size: Size;
286+
selected: boolean;
287+
name: string;
288+
chatBarText: string;
289+
areas: RichMenuArea[];
290+
};

0 commit comments

Comments
 (0)