유명현

Set line-bot sdk, .env

var express = require("express");
var app = express();
const express = require("express");
const line = require("@line/bot-sdk");
require("dotenv").config();
console.log(process.env.channelAccessToken, process.env.channelSecret);
const config = {
channelAccessToken: process.env.channelAccessToken,
channelSecret: process.env.channelSecret,
};
app.get("/", function (req, res) {
res.send("<h1>hello express!</h1>");
const app = express();
app.post("/webhook", line.middleware(config), (req, res) => {
Promise.all(req.body.events.map(handleEvent)).then((result) =>
res.json(result)
);
});
const client = new line.Client(config);
function handleEvent(event) {
if (event.type !== "message" || event.message.type !== "text") {
return Promise.resolve(null);
}
console.log(event);
// push
client.pushMessage(event.source.userId, {
type: "text",
text: "hihihi",
});
return client.replyMessage(event.replyToken, {
type: "text",
text: event.message.text,
});
}
app.listen(3000);
......
......@@ -7,7 +7,7 @@
"": {
"name": "secondhand-noti-bot",
"version": "1.0.0",
"license": "ISC",
"license": "MIT",
"dependencies": {
"express": "^4.18.1",
"nodemon": "^2.0.16"
......