-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample6.js
37 lines (30 loc) · 1.03 KB
/
sample6.js
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
33
34
35
36
37
const path = require("path");
const express = require("express");
const line = require("@line/bot-sdk");
const lineConfig = {
channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.LINE_CHANNEL_SECRET
};
const lineClient = new line.Client(lineConfig);
function createReplyMessage(input, name) {
return {
type: "text",
text: `${name}さんが${input}と言いました`
};
}
const server = express();
server.use("/images", express.static(path.join(__dirname, "images")));
server.post("/webhook", line.middleware(lineConfig), (req, res) => {
// LINEのサーバーに200を返す
res.sendStatus(200);
for (const event of req.body.events) {
if (event.type === "message" && event.message.type === "text") {
lineClient.getProfile(event.source.userId)
.then((profile) => {
const message = createReplyMessage(event.message.text, profile.displayName);
lineClient.replyMessage(event.replyToken, message);
});
}
}
});
server.listen(process.env.PORT || 8080);