EC2 Default User

Implement reply function

Showing 1 changed file with 35 additions and 9 deletions
const express = require('express');
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'P5+e9JkPRckzKu1Fv7ghZl1MfP0wrYwYcgBVzHWe1OHO4Gtv1PIa9BARYqxoAThaXPSf8MyVKcpDE88V5jOnoS4o2xCNcgH9Ne4wcrPuNX6AT4gsfYEz0Y7n/A4+rT4vXHYARK34YPbkzzQbiXiyiQdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2020105659.osschatbot.cf"
const sslport = 23023;
//Configure webhook
//Webhook
const bodyParser = require('body-parser');
const app = express();
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (request, response) {
app.post('/hook', function (req, res) {
var eventObj = request.body.events[0];
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', request.body);
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
response.sendStatus(200);
//Reply
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":eventObj.replyToken,
"messages":[
{
"type":"text",
"text":"안녕하세요"
},
{
"type":"text",
"text":"끝말잇기봇입니다"
}
]
}
},(error, response, body) => {
console.log(body)
});
res.sendStatus(200);
});
//Set SSL
//SSL
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
......