서민정

Update code

...@@ -10,7 +10,6 @@ yarn-error.log* ...@@ -10,7 +10,6 @@ yarn-error.log*
10 10
11 .vscode 11 .vscode
12 12
13 -dev.js 13 +
14 -auth.js 14 +
15 -./server/config/dev.js 15 +.env
16 -./server/config/auth.js
...\ No newline at end of file ...\ No newline at end of file
......
1 ### 오픈소스sw개발 개인 프로젝트 1 ### 오픈소스sw개발 개인 프로젝트
2 ## CHATBOT WITH CRAWLING 2 ## CHATBOT WITH CRAWLING
3 3
4 -- 뉴스 크롤링 후 이미지 사이즈 80*80 인 것을 원본으로 변환할 수 있는 방법은..? 4 +-readme 수정하기
5 -- 구글 [Cloud Authentication](https://cloud.google.com/docs/authentication/getting-started?hl=ko) 으로 사용해서 로컬에서 실행시키는데, 5 +-로그인 시 페이지렌더링 안됨 ..... 수정하기
6 -만약 배포를 해야한다면 이 부분은 어떻게 해야할지 ..?
7 -- 회원으로 로그인 했을 때, 주어진 키워드로 챗봇이 "먼저 검색"해줄 수 있도록 설정하는 방법은?!
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "private": true, 4 "private": true,
5 "engines": { 5 "engines": {
6 - "node": "10.x.x", 6 + "node": "12.16.1",
7 - "npm": "6.x", 7 + "npm": "6.13.4",
8 "yarn" : ">=1.0.0 <2.0.0" 8 "yarn" : ">=1.0.0 <2.0.0"
9 }, 9 },
10 "dependencies": { 10 "dependencies": {
......
No preview for this file type
1 import React, {Suspense} from "react"; 1 import React, {Suspense} from "react";
2 -import { Route, Switch } from "react-router-dom"; 2 +import { Route, Switch, BrowserRouter} from "react-router-dom";
3 // import { Typography, Icon } from 'antd'; 3 // import { Typography, Icon } from 'antd';
4 // import Chatbot from './Chatbot/Chatbot'; 4 // import Chatbot from './Chatbot/Chatbot';
5 import chatpage from './views/chatpage'; 5 import chatpage from './views/chatpage';
...@@ -11,13 +11,15 @@ import registerpage from './views/registerpage'; ...@@ -11,13 +11,15 @@ import registerpage from './views/registerpage';
11 11
12 function App() { 12 function App() {
13 return ( 13 return (
14 - <Suspense fallback = {(<div>Loading...</div>)}> 14 + <BrowserRouter>
15 - <Switch> 15 + <Suspense fallback = {(<div>Loading...</div>)}>
16 - <Route exact path="/chat" component={chatpage}/> 16 + <Switch>
17 - <Route exact path="/" component={loginpage} /> 17 + <Route path="/chat" component={chatpage}/>
18 - <Route exact path="/register" component={registerpage} /> 18 + <Route path="/" exact component={loginpage} />
19 + <Route path="/register" component={registerpage} />
19 </Switch> 20 </Switch>
20 - </Suspense> 21 + </Suspense>
22 + </BrowserRouter>
21 ) 23 )
22 } 24 }
23 25
......
...@@ -6,69 +6,36 @@ import Message from './Sections/Message'; ...@@ -6,69 +6,36 @@ import Message from './Sections/Message';
6 import { List, Icon, Avatar } from 'antd'; 6 import { List, Icon, Avatar } from 'antd';
7 import Card from "./Sections/Card"; 7 import Card from "./Sections/Card";
8 import CheckString from './Check'; 8 import CheckString from './Check';
9 +import { text } from 'body-parser';
9 10
10 -function getUserInfo(){
11 - let url = window.location.href;
12 - let keyword = "";
13 - let name = "";
14 - let from = 0;
15 - let to = 0;
16 - let flag = false;
17 - if(!url) return keyword;
18 - for(var i = 0; i <= url.length; i++){
19 - if(flag && url[i] === '&'){
20 - to = i;
21 - break;
22 - }
23 - if(url[i] === '='){
24 - from = i+1;
25 - flag = true;
26 - }
27 - }
28 -
29 - keyword = url.substr(from,to-from);
30 - keyword = decodeURI(keyword);
31 - name = url.substr(to+6);
32 - name = decodeURI(name);
33 -
34 - var user = {
35 - keyword,
36 - name
37 - };
38 -
39 - return user;
40 -}
41 -
42 -const user = getUserInfo();
43 -let username = "유저";
44 let userKeyword = ""; 11 let userKeyword = "";
45 - 12 +let userName = "유저";
46 -if(user.keyword){ 13 +let autoSearch = 0;
47 - userKeyword = user.keyword; 14 +if(sessionStorage.length){
48 - username = user.name; 15 + userKeyword = sessionStorage.getItem("Now_userKeyword");
49 -} 16 + userName = sessionStorage.getItem("Now_userName");
17 + autoSearch = 1;
18 + sessionStorage.clear();
19 +}
50 20
51 21
52 function Chatbot() { 22 function Chatbot() {
53 - console.log("이름",username); 23 + console.log("이름",userName);
54 console.log("키워드",userKeyword); 24 console.log("키워드",userKeyword);
55 - var isUser = false; 25 +
56 - if(userKeyword) isUser = true;
57 const dispatch = useDispatch(); 26 const dispatch = useDispatch();
58 const messagesFromRedux = useSelector(state => state.message.messages) 27 const messagesFromRedux = useSelector(state => state.message.messages)
59 28
60 useEffect(() => { 29 useEffect(() => {
61 -
62 eventQuery('001_Welcome') 30 eventQuery('001_Welcome')
63 .then(eventQuery('002_Intro')) 31 .then(eventQuery('002_Intro'))
64 -
65 32
66 }, []) 33 }, [])
67 34
68 const textQuery = async (text) => { 35 const textQuery = async (text) => {
69 // First Need to take care of the message I sent 36 // First Need to take care of the message I sent
70 let conversation = { 37 let conversation = {
71 - who: username, 38 + who: userName,
72 content: { 39 content: {
73 text: { 40 text: {
74 text: text 41 text: text
...@@ -180,6 +147,21 @@ function Chatbot() { ...@@ -180,6 +147,21 @@ function Chatbot() {
180 147
181 } 148 }
182 149
150 + if(autoSearch === 1){
151 + setTimeout(function(){
152 + eventQuery('008_AutoSearch');
153 + }, 500);
154 +
155 + setTimeout(function(){
156 + textQuery(`@${userKeyword}_최신`);
157 + textQuery(`@${userKeyword}_정확도`);
158 + textQuery(`@${userKeyword}_소식`);
159 + }, 1000);
160 +
161 + autoSearch = 0;
162 + console.log("I am in autoSearch!!");
163 + }
164 +
183 165
184 const keyPressHanlder = (e) => { 166 const keyPressHanlder = (e) => {
185 if (e.key === "Enter") { 167 if (e.key === "Enter") {
...@@ -243,10 +225,10 @@ function Chatbot() { ...@@ -243,10 +225,10 @@ function Chatbot() {
243 225
244 return ( 226 return (
245 <div style={{ 227 <div style={{
246 - height: 650, width: 700, 228 + height: 610, width: 700,
247 border: '3px solid black', borderRadius: '7px' 229 border: '3px solid black', borderRadius: '7px'
248 }}> 230 }}>
249 - <div style={{ height: 594, width: '100%', overflow: 'auto'}}> 231 + <div style={{ height: 554, width: '100%', overflow: 'auto'}}>
250 232
251 233
252 {renderMessage(messagesFromRedux)} 234 {renderMessage(messagesFromRedux)}
......
1 import React from "react"; 1 import React from "react";
2 import { Typography, Form, Input, Icon, Button} from 'antd'; 2 import { Typography, Form, Input, Icon, Button} from 'antd';
3 -import { withRouter } from "react-router-dom"; 3 +import { withRouter, Link } from "react-router-dom";
4 import Axios from 'axios'; 4 import Axios from 'axios';
5 5
6 const { Title } = Typography; 6 const { Title } = Typography;
...@@ -17,12 +17,17 @@ const userInfo = async (info) => { ...@@ -17,12 +17,17 @@ const userInfo = async (info) => {
17 } 17 }
18 18
19 const response = await Axios.post('/api/login/userInfo', userVariables); 19 const response = await Axios.post('/api/login/userInfo', userVariables);
20 - if(response.data != 'FAIL'){ 20 + if(response.data !== 'FAIL'){
21 // loginForm.action = `/chat?${response.data}`; 21 // loginForm.action = `/chat?${response.data}`;
22 // loginForm.submit(); 22 // loginForm.submit();
23 var keyword = response.data.keyword; 23 var keyword = response.data.keyword;
24 var name = response.data.name; 24 var name = response.data.name;
25 - window.location.href=`/chat?keyword=${keyword}&name=${name}`; 25 +
26 + sessionStorage.setItem("Now_userKeyword", keyword);
27 + sessionStorage.setItem("Now_userName", name);
28 + window.history.replaceState('login','','/chat');
29 + window.history.go();
30 + // window.location.href = "/chat";
26 } else{ 31 } else{
27 alert("입력하신 정보와 일치하는 회원이 존재하지 않습니다 😥"); 32 alert("입력하신 정보와 일치하는 회원이 존재하지 않습니다 😥");
28 } 33 }
...@@ -66,25 +71,12 @@ function loginpage() { ...@@ -66,25 +71,12 @@ function loginpage() {
66 Log in 71 Log in
67 </Button> 72 </Button>
68 </div> 73 </div>
69 - <a href="/register">가입하기</a> Or <a href = "/chat"> 비회원으로 사용하기 </a> 74 + <Link to ="/register">가입하기</Link> Or <Link to = "/chat">비회원으로 사용하기</Link>
70 </Form.Item> 75 </Form.Item>
71 </form> 76 </form>
72 </div> 77 </div>
73 </div> 78 </div>
74 ); 79 );
75 - // return (
76 - // htmlType="submit"
77 -
78 -
79 -
80 -
81 -
82 - // <div>
83 - // <div style={{ display: 'flex', justifyContent: 'center', marginTop: '1rem' }}>
84 - // <Title level={2} >Login Page</Title>
85 - // </div>
86 - // </div>
87 - // )
88 } 80 }
89 81
90 export default withRouter(loginpage); 82 export default withRouter(loginpage);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,7 +2,6 @@ const express = require("express"); ...@@ -2,7 +2,6 @@ const express = require("express");
2 const path = require("path"); 2 const path = require("path");
3 const bodyParser = require("body-parser"); 3 const bodyParser = require("body-parser");
4 const app = express(); 4 const app = express();
5 -const config = require("./server/config/keys");
6 5
7 app.set('trust proxy',true); 6 app.set('trust proxy',true);
8 app.use(bodyParser.urlencoded({ extended: true })); 7 app.use(bodyParser.urlencoded({ extended: true }));
...@@ -19,14 +18,19 @@ app.use('/api/news',require('./server/routes/news')); ...@@ -19,14 +18,19 @@ app.use('/api/news',require('./server/routes/news'));
19 if (process.env.NODE_ENV === "production") { 18 if (process.env.NODE_ENV === "production") {
20 19
21 // Set static folder 20 // Set static folder
22 - app.use(express.static("client/build")); 21 + app.use(express.static(path.join(__dirname,'client/build')));
22 +
23 + app.get('/api/greeting',(req,res)=>{
24 + res.send("Hello World!");
25 + });
23 26
24 // index.html for all page routes 27 // index.html for all page routes
25 - app.get("/", (req, res) => { 28 + app.get('*', (req, res) => {
26 - res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); 29 + res.sendFile(path.join(__dirname + 'client/build','index.html'));
27 }); 30 });
28 } 31 }
29 32
33 +
30 const port = process.env.PORT || 5000; 34 const port = process.env.PORT || 5000;
31 35
32 app.listen(port, () => { 36 app.listen(port, () => {
...@@ -34,4 +38,5 @@ app.listen(port, () => { ...@@ -34,4 +38,5 @@ app.listen(port, () => {
34 }); 38 });
35 39
36 40
41 +
37 // res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); 42 // res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,10 +13,7 @@ ...@@ -13,10 +13,7 @@
13 "backend": "nodemon index.js", 13 "backend": "nodemon index.js",
14 "frontend": "npm run front --prefix client" 14 "frontend": "npm run front --prefix client"
15 }, 15 },
16 - "author": "Jaewon Ahn", 16 + "author": "",
17 - "contributors": [
18 - "Minjeong Seo"
19 - ],
20 "license": "ISC", 17 "license": "ISC",
21 "dependencies": { 18 "dependencies": {
22 "actions-on-google": "^2.12.0", 19 "actions-on-google": "^2.12.0",
......
1 -if (process.env.NODE_ENV === "production"){
2 - module.exports = require("./prod");
3 -}else{
4 - module.exports = require("./dev");
5 -}
...\ No newline at end of file ...\ No newline at end of file
1 -module.exports = {
2 - googleProjectID: process.env.GOOGLE_PROJECT_ID,
3 - dialogFlowSessionID: process.env.DIALOGFLOW_SESSION_ID,
4 - dialogFlowSessionLanguageCode: process.env.DIALOGFLOW_LANGUAGE_CODE,
5 - googleClientEmail:process.env.GOOGLE_CLIENT_EMAIL,
6 - googlePrivateKey: JSON.parse(process.env.GOOGLE_PRIVATE_KEY),
7 - mongoURI:process.env.MONGO_URI,
8 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,11 +3,12 @@ const router = express.Router(); ...@@ -3,11 +3,12 @@ const router = express.Router();
3 const structjson = require('./structjson.js'); 3 const structjson = require('./structjson.js');
4 const dialogflow = require('dialogflow'); 4 const dialogflow = require('dialogflow');
5 5
6 -const config = require('../config/keys'); 6 +require('dotenv').config();
7 +
8 +const projectId = process.env.googleProjectID
9 +const sessionId = process.env.dialogFlowSessionID
10 +const languageCode = process.env.dialogFlowSessionLanguageCode
7 11
8 -const projectId = config.googleProjectID
9 -const sessionId = config.dialogFlowSessionID
10 -const languageCode = config.dialogFlowSessionLanguageCode
11 12
12 13
13 // Create a new session 14 // Create a new session
......