-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateRichMenu.mjs
32 lines (29 loc) · 944 Bytes
/
CreateRichMenu.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import richmenu from './richmenu.json' assert { type: 'json' };
import { readFile } from 'node:fs/promises';
(await import('dotenv')).config()
const channelAccessToken = process.env.CHANNELACCESSTOKEN
// create rich menu
const richid = (await (await fetch("https://api.line.me/v2/bot/richmenu", {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${channelAccessToken}`
},
body: JSON.stringify(richmenu),
})).json()).richMenuId;
// Upload image to rich menu
await fetch(`https://api-data.line.me/v2/bot/richmenu/${richid}/content`, {
method: "POST",
headers: {
'Content-Type': 'image/jpeg',
'Authorization': `Bearer ${channelAccessToken}`
},
body: await readFile('./button.jpg')
})
// set rich menu to default
await fetch(`https://api.line.me/v2/bot/user/all/richmenu/${richid}`, {
method: "POST",
headers: {
'Authorization': `Bearer ${channelAccessToken}`
}
})