정세호

git app_reply 추가

......@@ -6,22 +6,33 @@ mother project : kakaoBot<br>
# :page_with_curl:목차
---
> 1.소개
> 2.기본세팅
> 소개
mother project chatbot를 바탕으로 aws-comprehend api기능을 추가하여
어떤 문자를 보냈을때 그 메세지에 내포된 감정을 반환하도록 하였다.
> 기본세팅
WHAT WE NEED:
line messanger api channel token
aws access,access-secret token
> > 개발 환경
visual studio code
node js
> > 사용 언어
node.js
> 3.빌드 방법
0. npm install
1. npm install aws-sdk
2. /home/user 디렉토리의 .aws안의 credentials파일을 수정한다
->aws access key, secret key 입력
->region: us-east-1
->aws session token입력
> 4.사용 방법
(temp)
1. send message
2. it will return your sentiment
> > 사용 API
1. aws comprehend api
2. line notify,messendger api
> liscense
# :speaker:소개
---
......
......@@ -2,7 +2,6 @@ var express = require('express');
var app = express();
const line = require('@line/bot-sdk');
//papago api
var request = require('request');
......@@ -67,7 +66,6 @@ function handleEvent(event) {
//언어 감지가 제대로 됐는지 확인
console.log(detect_body.langCode);
//번역은 한국어->영어 / 영어->한국어만 지원
if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
source = detect_body.langCode == 'ko' ? 'ko':'en';
......
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = '2COGs98oPL/IUlCY23t4YMh98apwu0w2wlCWMjTvpNpHZwJoMWpYJP2/S00b/bwCKRTK0D9zgLbQq0gLokge0cXHb5gCJ6UQBTV4KHiynPN/WKydHNxqAwGlzvN+YUJoP9VG/crGAfy5xaU7k2EANAdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "www.chatbot-test.ml"
const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message['text']);
var AWS = require("aws-sdk");
AWS.config.update({region:'us-east-1'});
var params={LanguageCode:'en',TextList:[eventObj.message['text']]};
var comprehend = new AWS.Comprehend();
comprehend.batchDetectSentiment(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {console.log(data.ResultList[0]['Sentiment']);
send(eventObj.replyToken,data.ResultList[0]['Sentiment'])
} // successful response
});
res.sendStatus(200);
});
function send(replyToken,result){
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":"what can I help you?"
},
{
"type":"text",
"text":"you look"+result
}
]
}
},(error, response, body) => {
console.log(body)
});
}
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
};
HTTPS.createServer(option, app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
0. npm install
1. npm install aws-sdk
2.aws configure
->캡처2에 들어가있는 access key, secret key 입력
->aws access key, secret key 입력
->region은 us-east-1
\ No newline at end of file
......