Showing
22 changed files
with
438 additions
and
135 deletions
... | @@ -4,36 +4,36 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo | ... | @@ -4,36 +4,36 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo |
4 | 4 | ||
5 | In the project directory, you can run: | 5 | In the project directory, you can run: |
6 | 6 | ||
7 | -### `yarn start` | 7 | +### `npm start` |
8 | 8 | ||
9 | -Runs the app in the development mode.<br /> | 9 | +Runs the app in the development mode.<br> |
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | 10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. |
11 | 11 | ||
12 | -The page will reload if you make edits.<br /> | 12 | +The page will reload if you make edits.<br> |
13 | You will also see any lint errors in the console. | 13 | You will also see any lint errors in the console. |
14 | 14 | ||
15 | -### `yarn test` | 15 | +### `npm test` |
16 | 16 | ||
17 | -Launches the test runner in the interactive watch mode.<br /> | 17 | +Launches the test runner in the interactive watch mode.<br> |
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | 18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. |
19 | 19 | ||
20 | -### `yarn build` | 20 | +### `npm run build` |
21 | 21 | ||
22 | -Builds the app for production to the `build` folder.<br /> | 22 | +Builds the app for production to the `build` folder.<br> |
23 | It correctly bundles React in production mode and optimizes the build for the best performance. | 23 | It correctly bundles React in production mode and optimizes the build for the best performance. |
24 | 24 | ||
25 | -The build is minified and the filenames include the hashes.<br /> | 25 | +The build is minified and the filenames include the hashes.<br> |
26 | Your app is ready to be deployed! | 26 | Your app is ready to be deployed! |
27 | 27 | ||
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. |
29 | 29 | ||
30 | -### `yarn eject` | 30 | +### `npm run eject` |
31 | 31 | ||
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** |
33 | 33 | ||
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. |
35 | 35 | ||
36 | -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | 36 | +Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. |
37 | 37 | ||
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. |
39 | 39 | ||
... | @@ -63,6 +63,6 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/ad | ... | @@ -63,6 +63,6 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/ad |
63 | 63 | ||
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment |
65 | 65 | ||
66 | -### `yarn build` fails to minify | 66 | +### `npm run build` fails to minify |
67 | 67 | ||
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify | ... | ... |
client/package-lock.json
0 → 100644
This diff could not be displayed because it is too large.
... | @@ -4,14 +4,13 @@ | ... | @@ -4,14 +4,13 @@ |
4 | "private": true, | 4 | "private": true, |
5 | "dependencies": { | 5 | "dependencies": { |
6 | "antd": "^3.26.5", | 6 | "antd": "^3.26.5", |
7 | - "axios": "^0.18.0", | 7 | + "axios": "^0.18.1", |
8 | "prop-types": "^15.7.2", | 8 | "prop-types": "^15.7.2", |
9 | - "@testing-library/jest-dom": "^4.2.4", | 9 | + "react": "^16.12.0", |
10 | - "@testing-library/react": "^9.3.2", | 10 | + "react-dom": "^16.12.0", |
11 | - "@testing-library/user-event": "^7.1.2", | 11 | + "react-redux": "^7.1.3", |
12 | - "react": "^16.13.1", | 12 | + "react-router-dom": "^5.0.0", |
13 | - "react-dom": "^16.13.1", | 13 | + "react-scripts": "2.1.8", |
14 | - "react-scripts": "3.4.1", | ||
15 | "redux": "^4.0.5", | 14 | "redux": "^4.0.5", |
16 | "redux-promise": "^0.6.0", | 15 | "redux-promise": "^0.6.0", |
17 | "redux-thunk": "^2.3.0", | 16 | "redux-thunk": "^2.3.0", | ... | ... |
No preview for this file type
... | @@ -2,19 +2,29 @@ | ... | @@ -2,19 +2,29 @@ |
2 | <html lang="en"> | 2 | <html lang="en"> |
3 | <head> | 3 | <head> |
4 | <meta charset="utf-8" /> | 4 | <meta charset="utf-8" /> |
5 | - <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | 5 | + <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> |
6 | - <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
7 | - <meta name="theme-color" content="#000000" /> | ||
8 | <meta | 6 | <meta |
9 | - name="description" | 7 | + name="viewport" |
10 | - content="Web site created using create-react-app" | 8 | + content="width=device-width, initial-scale=1, shrink-to-fit=no" |
11 | /> | 9 | /> |
12 | - <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | 10 | + <meta name="theme-color" content="#000000" /> |
11 | + | ||
13 | <!-- | 12 | <!-- |
14 | manifest.json provides metadata used when your web app is installed on a | 13 | manifest.json provides metadata used when your web app is installed on a |
15 | user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | 14 | user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ |
16 | --> | 15 | --> |
16 | + | ||
17 | <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | 17 | <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> |
18 | + <!-- <script charset="utf-8" src="//cdn.iframe.ly/embed.js?api_key=3d0d059e07f98dcecefab2"></script> | ||
19 | + | ||
20 | + <script> | ||
21 | + document.querySelectorAll( 'oembed[url]' ).forEach( element => { | ||
22 | + iframely.load( element, element.attributes.url.value ); | ||
23 | + } ); | ||
24 | + </script> --> | ||
25 | + | ||
26 | + | ||
27 | + | ||
18 | <!-- | 28 | <!-- |
19 | Notice the use of %PUBLIC_URL% in the tags above. | 29 | Notice the use of %PUBLIC_URL% in the tags above. |
20 | It will be replaced with the URL of the `public` folder during the build. | 30 | It will be replaced with the URL of the `public` folder during the build. |
... | @@ -24,7 +34,7 @@ | ... | @@ -24,7 +34,7 @@ |
24 | work correctly both with client-side routing and a non-root public URL. | 34 | work correctly both with client-side routing and a non-root public URL. |
25 | Learn how to configure a non-root public URL by running `npm run build`. | 35 | Learn how to configure a non-root public URL by running `npm run build`. |
26 | --> | 36 | --> |
27 | - <title>React App</title> | 37 | + |
28 | </head> | 38 | </head> |
29 | <body> | 39 | <body> |
30 | <noscript>You need to enable JavaScript to run this app.</noscript> | 40 | <noscript>You need to enable JavaScript to run this app.</noscript> |
... | @@ -40,4 +50,9 @@ | ... | @@ -40,4 +50,9 @@ |
40 | To create a production bundle, use `npm run build` or `yarn build`. | 50 | To create a production bundle, use `npm run build` or `yarn build`. |
41 | --> | 51 | --> |
42 | </body> | 52 | </body> |
53 | + | ||
54 | + <!-- Include your favorite highlight.js stylesheet --> | ||
55 | + | ||
56 | + | ||
57 | + | ||
43 | </html> | 58 | </html> | ... | ... |
... | @@ -6,16 +6,6 @@ | ... | @@ -6,16 +6,6 @@ |
6 | "src": "favicon.ico", | 6 | "src": "favicon.ico", |
7 | "sizes": "64x64 32x32 24x24 16x16", | 7 | "sizes": "64x64 32x32 24x24 16x16", |
8 | "type": "image/x-icon" | 8 | "type": "image/x-icon" |
9 | - }, | ||
10 | - { | ||
11 | - "src": "logo192.png", | ||
12 | - "type": "image/png", | ||
13 | - "sizes": "192x192" | ||
14 | - }, | ||
15 | - { | ||
16 | - "src": "logo512.png", | ||
17 | - "type": "image/png", | ||
18 | - "sizes": "512x512" | ||
19 | } | 9 | } |
20 | ], | 10 | ], |
21 | "start_url": ".", | 11 | "start_url": ".", | ... | ... |
1 | import React from "react"; | 1 | import React from "react"; |
2 | import { Typography, Icon } from 'antd'; | 2 | import { Typography, Icon } from 'antd'; |
3 | -import chatbot from './chatbot/chatbot'; | 3 | +import Chatbot from './Chatbot/Chatbot'; |
4 | const { Title } = Typography; | 4 | const { Title } = Typography; |
5 | 5 | ||
6 | function App() { | 6 | function App() { | ... | ... |
client/src/App.test.js
deleted
100644 → 0
1 | -import React from 'react'; | ||
2 | -import { render } from '@testing-library/react'; | ||
3 | -import App from './App'; | ||
4 | - | ||
5 | -test('renders learn react link', () => { | ||
6 | - const { getByText } = render(<App />); | ||
7 | - const linkElement = getByText(/learn react/i); | ||
8 | - expect(linkElement).toBeInTheDocument(); | ||
9 | -}); |
1 | -import React, {useEffect} from 'react'; | 1 | +import React, { useEffect } from 'react'; |
2 | import Axios from 'axios'; | 2 | import Axios from 'axios'; |
3 | -import {useDispatch, useSelector} from 'react-redux'; | 3 | +import { useDispatch, useSelector } from 'react-redux'; |
4 | -import {saveMessage} from '../_actions/message_actions'; | 4 | +import { saveMessage } from '../_actions/message_actions'; |
5 | -import Message from './sections/msg'; | 5 | +import Message from './Sections/Message'; |
6 | -import Card from './sections/card'; | 6 | +import { List, Icon, Avatar } from 'antd'; |
7 | -import {List, Icon, Avatar} from 'antd'; | 7 | +import Card from "./Sections/Card"; |
8 | - | 8 | +function Chatbot() { |
9 | -function chatbot(){ | ||
10 | const dispatch = useDispatch(); | 9 | const dispatch = useDispatch(); |
11 | - const messageFromRedux = useSelector(state => state.message.messages) | 10 | + const messagesFromRedux = useSelector(state => state.message.messages) |
12 | 11 | ||
13 | useEffect(() => { | 12 | useEffect(() => { |
14 | - eventQuery('') //처음 시작했을 때 시작할 쿼리 설정 | 13 | + |
14 | + eventQuery('welcomeToMyWebsite') | ||
15 | + | ||
15 | }, []) | 16 | }, []) |
16 | 17 | ||
17 | - const textQuery = async(text) => { | 18 | + |
19 | + const textQuery = async (text) => { | ||
20 | + | ||
21 | + // First Need to take care of the message I sent | ||
18 | let conversation = { | 22 | let conversation = { |
19 | who: 'user', | 23 | who: 'user', |
20 | content: { | 24 | content: { |
... | @@ -25,7 +29,174 @@ function chatbot(){ | ... | @@ -25,7 +29,174 @@ function chatbot(){ |
25 | } | 29 | } |
26 | 30 | ||
27 | dispatch(saveMessage(conversation)) | 31 | dispatch(saveMessage(conversation)) |
32 | + // console.log('text I sent', conversation) | ||
33 | + | ||
34 | + var inputString = conversation.content.text.text | ||
35 | + | ||
36 | + // We need to take care of the message Chatbot sent | ||
37 | + const textQueryVariables = { | ||
38 | + text | ||
39 | + } | ||
40 | + try { | ||
41 | + if(inputString[0] === '@'){ | ||
42 | + const response = await Axios.post('/api/crawling/textQuery', textQueryVariables) | ||
43 | + } else { | ||
44 | + //I will send request to the textQuery ROUTE | ||
45 | + const response = await Axios.post('/api/dialogflow/textQuery', textQueryVariables) | ||
46 | + | ||
47 | + for (let content of response.data.fulfillmentMessages) { | ||
48 | + | ||
49 | + conversation = { | ||
50 | + who: 'bot', | ||
51 | + content: content | ||
52 | + } | ||
53 | + | ||
54 | + dispatch(saveMessage(conversation)) | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | + } catch (error) { | ||
59 | + conversation = { | ||
60 | + who: 'bot', | ||
61 | + content: { | ||
62 | + text: { | ||
63 | + text: " Error just occured, please check the problem" | ||
64 | + } | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + dispatch(saveMessage(conversation)) | ||
69 | + } | ||
70 | + | ||
28 | } | 71 | } |
72 | + | ||
73 | + | ||
74 | + const eventQuery = async (event) => { | ||
75 | + | ||
76 | + // We need to take care of the message Chatbot sent | ||
77 | + const eventQueryVariables = { | ||
78 | + event | ||
79 | + } | ||
80 | + try { | ||
81 | + //I will send request to the textQuery ROUTE | ||
82 | + const response = await Axios.post('/api/dialogflow/eventQuery', eventQueryVariables) | ||
83 | + for (let content of response.data.fulfillmentMessages) { | ||
84 | + | ||
85 | + let conversation = { | ||
86 | + who: 'bot', | ||
87 | + content: content | ||
88 | + } | ||
89 | + | ||
90 | + dispatch(saveMessage(conversation)) | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + } catch (error) { | ||
95 | + let conversation = { | ||
96 | + who: 'bot', | ||
97 | + content: { | ||
98 | + text: { | ||
99 | + text: " Error just occured, please check the problem" | ||
100 | + } | ||
101 | + } | ||
102 | + } | ||
103 | + dispatch(saveMessage(conversation)) | ||
104 | + } | ||
105 | + | ||
106 | + } | ||
107 | + | ||
108 | + | ||
109 | + const keyPressHanlder = (e) => { | ||
110 | + if (e.key === "Enter") { | ||
111 | + | ||
112 | + if (!e.target.value) { | ||
113 | + return alert('you need to type somthing first') | ||
114 | + } | ||
115 | + | ||
116 | + //we will send request to text query route | ||
117 | + textQuery(e.target.value) | ||
118 | + | ||
119 | + | ||
120 | + e.target.value = ""; | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + const renderCards = (cards) => { | ||
125 | + return cards.map((card,i) => <Card key={i} cardInfo={card.structValue} />) | ||
126 | + } | ||
127 | + | ||
128 | + | ||
129 | + const renderOneMessage = (message, i) => { | ||
130 | + console.log('message', message) | ||
131 | + | ||
132 | + // we need to give some condition here to separate message kinds | ||
133 | + | ||
134 | + // template for normal text | ||
135 | + if (message.content && message.content.text && message.content.text.text) { | ||
136 | + return <Message key={i} who={message.who} text={message.content.text.text} /> | ||
137 | + } else if (message.content && message.content.payload.fields.card) { | ||
138 | + | ||
139 | + const AvatarSrc = message.who === 'bot' ? <Icon type="robot" /> : <Icon type="smile" /> | ||
140 | + | ||
141 | + return <div> | ||
142 | + <List.Item style={{ padding: '1rem' }}> | ||
143 | + <List.Item.Meta | ||
144 | + avatar={<Avatar icon={AvatarSrc} />} | ||
145 | + title={message.who} | ||
146 | + description={renderCards(message.content.payload.fields.card.listValue.values)} | ||
147 | + /> | ||
148 | + </List.Item> | ||
149 | + </div> | ||
150 | + } | ||
151 | + | ||
152 | + | ||
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | ||
157 | + // template for card message | ||
158 | + | ||
159 | + | ||
160 | + | ||
161 | + | ||
162 | + } | ||
163 | + | ||
164 | + const renderMessage = (returnedMessages) => { | ||
165 | + | ||
166 | + if (returnedMessages) { | ||
167 | + return returnedMessages.map((message, i) => { | ||
168 | + return renderOneMessage(message, i); | ||
169 | + }) | ||
170 | + } else { | ||
171 | + return null; | ||
172 | + } | ||
173 | + } | ||
174 | + | ||
175 | + | ||
176 | + return ( | ||
177 | + <div style={{ | ||
178 | + height: 500, width: 700, | ||
179 | + border: '3px solid black', borderRadius: '7px' | ||
180 | + }}> | ||
181 | + <div style={{ height: 444, width: '100%', overflow: 'auto' }}> | ||
182 | + | ||
183 | + | ||
184 | + {renderMessage(messagesFromRedux)} | ||
185 | + | ||
186 | + | ||
187 | + </div> | ||
188 | + <input | ||
189 | + style={{ | ||
190 | + margin: 0, width: '100%', height: 50, | ||
191 | + borderRadius: '4px', padding: '5px', fontSize: '1rem' | ||
192 | + }} | ||
193 | + placeholder="Send a message..." | ||
194 | + onKeyPress={keyPressHanlder} | ||
195 | + type="text" | ||
196 | + /> | ||
197 | + | ||
198 | + </div> | ||
199 | + ) | ||
29 | } | 200 | } |
30 | 201 | ||
31 | -export default chatbot; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
202 | +export default Chatbot; | ... | ... |
client/src/chatbot/sections/Message.js
0 → 100644
1 | +import React from 'react' | ||
2 | +import { List, Icon, Avatar } from 'antd'; | ||
3 | + | ||
4 | +function Message(props) { | ||
5 | + | ||
6 | + const AvatarSrc = props.who ==='bot' ? <Icon type="robot" /> : <Icon type="smile" /> | ||
7 | + | ||
8 | + return ( | ||
9 | + <List.Item style={{ padding: '1rem' }}> | ||
10 | + <List.Item.Meta | ||
11 | + avatar={<Avatar icon={AvatarSrc} />} | ||
12 | + title={props.who} | ||
13 | + description={props.text} | ||
14 | + /> | ||
15 | + </List.Item> | ||
16 | + ) | ||
17 | +} | ||
18 | + | ||
19 | +export default Message |
1 | +import React from 'react' | ||
2 | +import { Card, Icon } from 'antd'; | ||
3 | + | ||
4 | +const { Meta } = Card; | ||
5 | + | ||
6 | +function CardComponent(props) { | ||
7 | + return ( | ||
8 | + <Card | ||
9 | + style={{ width: 300 }} | ||
10 | + cover={ | ||
11 | + <img | ||
12 | + alt={props.cardInfo.fields.description.stringValue} | ||
13 | + src={props.cardInfo.fields.image.stringValue} /> | ||
14 | + } | ||
15 | + actions={[ | ||
16 | + <a target="_blank" rel="noopener noreferrer" href={props.cardInfo.fields.link.stringValue}> | ||
17 | + <Icon type="ellipsis" key="ellipsis" /> | ||
18 | + </a> | ||
19 | + ]} | ||
20 | + > | ||
21 | + <Meta | ||
22 | + title={props.cardInfo.fields.stack.stringValue} | ||
23 | + description={props.cardInfo.fields.description.stringValue} | ||
24 | + /> | ||
25 | + | ||
26 | + </Card> | ||
27 | + | ||
28 | + ) | ||
29 | +} | ||
30 | + | ||
31 | +export default CardComponent | ... | ... |
client/src/chatbot/sections/msg.js
deleted
100644 → 0
File mode changed
1 | -import React from 'react'; | 1 | +import React from "react"; |
2 | -import ReactDOM from 'react-dom'; | 2 | +import ReactDOM from "react-dom"; |
3 | import './index.css'; | 3 | import './index.css'; |
4 | -import App from './App'; | 4 | +import "antd/dist/antd.css"; |
5 | -import * as serviceWorker from './serviceWorker'; | 5 | + |
6 | +import App from "./App"; | ||
7 | + | ||
8 | +import Reducer from './_reducers'; | ||
9 | +import { Provider } from 'react-redux'; | ||
10 | +import { createStore, applyMiddleware } from 'redux'; | ||
11 | +import promiseMiddleware from 'redux-promise'; | ||
12 | +import ReduxThunk from 'redux-thunk'; | ||
13 | +import { BrowserRouter } from "react-router-dom"; | ||
14 | + | ||
15 | +import * as serviceWorker from "./serviceWorker"; | ||
16 | +const createStoreWithMiddleware = applyMiddleware(promiseMiddleware, ReduxThunk)(createStore); | ||
6 | 17 | ||
7 | ReactDOM.render( | 18 | ReactDOM.render( |
8 | - <React.StrictMode> | 19 | + <Provider |
9 | - <App /> | 20 | + store={createStoreWithMiddleware( |
10 | - </React.StrictMode>, | 21 | + Reducer, |
11 | - document.getElementById('root') | 22 | + window.__REDUX_DEVTOOLS_EXTENSION__ && |
23 | + window.__REDUX_DEVTOOLS_EXTENSION__() | ||
24 | + )} | ||
25 | + > | ||
26 | + <BrowserRouter> | ||
27 | + <App /> | ||
28 | + </BrowserRouter> | ||
29 | + </Provider> | ||
30 | + | ||
31 | + , | ||
32 | + document.getElementById("root") | ||
12 | ); | 33 | ); |
13 | 34 | ||
14 | // If you want your app to work offline and load faster, you can change | 35 | // If you want your app to work offline and load faster, you can change | ... | ... |
... | @@ -14,7 +14,7 @@ const isLocalhost = Boolean( | ... | @@ -14,7 +14,7 @@ const isLocalhost = Boolean( |
14 | window.location.hostname === 'localhost' || | 14 | window.location.hostname === 'localhost' || |
15 | // [::1] is the IPv6 localhost address. | 15 | // [::1] is the IPv6 localhost address. |
16 | window.location.hostname === '[::1]' || | 16 | window.location.hostname === '[::1]' || |
17 | - // 127.0.0.0/8 are considered localhost for IPv4. | 17 | + // 127.0.0.1/8 is considered localhost for IPv4. |
18 | window.location.hostname.match( | 18 | window.location.hostname.match( |
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ | 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ |
20 | ) | 20 | ) |
... | @@ -100,9 +100,7 @@ function registerValidSW(swUrl, config) { | ... | @@ -100,9 +100,7 @@ function registerValidSW(swUrl, config) { |
100 | 100 | ||
101 | function checkValidServiceWorker(swUrl, config) { | 101 | function checkValidServiceWorker(swUrl, config) { |
102 | // Check if the service worker can be found. If it can't reload the page. | 102 | // Check if the service worker can be found. If it can't reload the page. |
103 | - fetch(swUrl, { | 103 | + fetch(swUrl) |
104 | - headers: { 'Service-Worker': 'script' }, | ||
105 | - }) | ||
106 | .then(response => { | 104 | .then(response => { |
107 | // Ensure service worker exists, and that we really are getting a JS file. | 105 | // Ensure service worker exists, and that we really are getting a JS file. |
108 | const contentType = response.headers.get('content-type'); | 106 | const contentType = response.headers.get('content-type'); |
... | @@ -130,12 +128,8 @@ function checkValidServiceWorker(swUrl, config) { | ... | @@ -130,12 +128,8 @@ function checkValidServiceWorker(swUrl, config) { |
130 | 128 | ||
131 | export function unregister() { | 129 | export function unregister() { |
132 | if ('serviceWorker' in navigator) { | 130 | if ('serviceWorker' in navigator) { |
133 | - navigator.serviceWorker.ready | 131 | + navigator.serviceWorker.ready.then(registration => { |
134 | - .then(registration => { | 132 | + registration.unregister(); |
135 | - registration.unregister(); | 133 | + }); |
136 | - }) | ||
137 | - .catch(error => { | ||
138 | - console.error(error.message); | ||
139 | - }); | ||
140 | } | 134 | } |
141 | } | 135 | } | ... | ... |
This diff could not be displayed because it is too large.
... | @@ -4,26 +4,31 @@ const bodyParser = require("body-parser"); | ... | @@ -4,26 +4,31 @@ const bodyParser = require("body-parser"); |
4 | const app = express(); | 4 | const app = express(); |
5 | 5 | ||
6 | const config = require("./server/config/keys"); | 6 | const config = require("./server/config/keys"); |
7 | +// const mongoose = require("mongoose"); | ||
8 | +// mongoose.connect(config.mongoURI, { useNewUrlParser: true, useUnifiedTopology: true }) | ||
9 | +// .then(() => console.log('MongoDB Connected...')) | ||
10 | +// .catch(err => console.log(err)); | ||
11 | + | ||
7 | app.use(bodyParser.urlencoded({ extended: true })); | 12 | app.use(bodyParser.urlencoded({ extended: true })); |
8 | app.use(bodyParser.json()); | 13 | app.use(bodyParser.json()); |
9 | 14 | ||
15 | + | ||
10 | app.use('/api/dialogflow', require('./server/routes/dialogflow')); | 16 | app.use('/api/dialogflow', require('./server/routes/dialogflow')); |
11 | 17 | ||
12 | // Serve static assets if in production | 18 | // Serve static assets if in production |
13 | if (process.env.NODE_ENV === "production") { | 19 | if (process.env.NODE_ENV === "production") { |
14 | 20 | ||
15 | - // Set static folder | 21 | + // Set static folder |
16 | - app.use(express.static("client/build")); | 22 | + app.use(express.static("client/build")); |
17 | 23 | ||
18 | - // index.html for all page routes | 24 | + // index.html for all page routes |
19 | - app.get("*", (req, res) => { | 25 | + app.get("*", (req, res) => { |
20 | - res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); | 26 | + res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); |
21 | - }); | 27 | + }); |
22 | } | 28 | } |
23 | 29 | ||
24 | const port = process.env.PORT || 5000; | 30 | const port = process.env.PORT || 5000; |
25 | 31 | ||
26 | app.listen(port, () => { | 32 | app.listen(port, () => { |
27 | - console.log(`Server Running at ${port}`) | 33 | + console.log(`Server Running at ${port}`) |
28 | }); | 34 | }); |
29 | - | ... | ... |
note.md
0 → 100644
1 | +1. dialogflow로 기본 기능 구현 | ||
2 | +2. React로 프론트엔드 구현 | ||
3 | +3. routing으로 @가수명 입력하면 해당 라우팅(크롤링) 함수로 들어가게 구현 | ||
4 | +4. 크롤링 구현 (네이버TV 최신 영상 3개 json으로 가져오기) | ||
5 | +5. json파일 카드로 넘겨주기 | ||
6 | + | ||
7 | + | ||
8 | +node 서버: localhost: 5000 | ||
9 | +프론트엔드/ localhost: 3000 | ||
10 | + | ||
11 | +---- 정리 | ||
12 | + | ||
13 | +리덕스 참고: https://velopert.com/3528 | ||
14 | + | ||
15 | +dialogflow | ||
16 | +화자의 의도 intent ,사용자가 말하는 것과 dialogflow가 수행해야할 작업간의 매핑을 나타내는 것. | ||
17 | +fallback intent : 사용자의 대화가 어떤 intent 와도 매칭되지 않을 때 선택되어지는 intent | ||
18 | + | ||
19 | +화자의 속성 entity | ||
20 | +ex. 내일 오후 2시 되나요? 에서 '내일', '오후 2시'를 파라미터로 뽑아내는 것. | ||
21 | + | ||
22 | +문맥 context | ||
23 | +내일 오후 2시 되나요? 에서 무엇을 위한 내일 오후 2시인가를 파악하기 위해서 그 전에 대화가 되었던 '수리'라는 것을 기억하는 것을 의미함 | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | +----- | ||
28 | +001 - welcome | ||
29 | +002 - 인사 | ||
30 | +003 - @'가수명' | ||
31 | +-> 해당 가수명으로 크롤링을 했을 때 null이 3개이상 나오면 가수명이 없다고 판단함. | ||
32 | +-> 만약 가수가 아니더라도 크롤링 시 해당되는 내용이 3개 이상 나오면 해당 내용을 리턴함. | ||
33 | +----- | ||
34 | + | ||
35 | + |
package-lock.json
0 → 100644
This diff could not be displayed because it is too large.
1 | { | 1 | { |
2 | - "name": "chatbot-app", | 2 | + "name": "chatbot-app", |
3 | - "version": "1.0.0", | 3 | + "version": "1.0.0", |
4 | - "description": "chatbot-app", | 4 | + "description": "chatbot-app", |
5 | - "main": "index.js", | 5 | + "main": "index.js", |
6 | - "engines": { | 6 | + "engines": { |
7 | - "node": "12.16.1", | 7 | + "node": "10.15.0", |
8 | - "npm": "6.13.4" | 8 | + "npm": "6.9.0" |
9 | - }, | 9 | + }, |
10 | - "scripts": { | 10 | + "scripts": { |
11 | - "start": "node index.js" | 11 | + "start": "node index.js", |
12 | - }, | 12 | + "backend": "nodemon index.js", |
13 | - "author": "Minjeong Seo", | 13 | + "frontend": "npm run front --prefix client", |
14 | - "dependencies": { | 14 | + "dev": "concurrently \"npm run backend\" \"npm run start --prefix client\"" |
15 | - "actions-on-google": "^2.6.0", | 15 | + }, |
16 | - "body-parser": "^1.18.3", | 16 | + "author": "Jaewon Ahn", |
17 | - "dialogflow": "^0.8.2", | 17 | + "license": "ISC", |
18 | - "dialogflow-fulfillment": "^0.6.1", | 18 | + "dependencies": { |
19 | - "express": "^4.16.4" | 19 | + "actions-on-google": "^2.12.0", |
20 | - } | 20 | + "body-parser": "^1.18.3", |
21 | + "dialogflow": "^0.8.2", | ||
22 | + "dialogflow-fulfillment": "^0.6.1", | ||
23 | + "express": "^4.16.4", | ||
24 | + "mongoose": "^5.4.20" | ||
25 | + }, | ||
26 | + "devDependencies": { | ||
27 | + "concurrently": "^4.1.0", | ||
28 | + "nodemon": "^1.18.10" | ||
21 | } | 29 | } |
22 | - | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
30 | +} | ... | ... |
plan.md
deleted
100644 → 0
server/models/Opinion.js
0 → 100644
1 | const express = require('express'); | 1 | const express = require('express'); |
2 | const router = express.Router(); | 2 | const router = express.Router(); |
3 | -const dialogflow = require('dialogflow'); | ||
4 | const structjson = require('./structjson.js'); | 3 | const structjson = require('./structjson.js'); |
5 | - | 4 | +const dialogflow = require('dialogflow'); |
5 | +const uuid = require('uuid'); | ||
6 | 6 | ||
7 | const config = require('../config/keys'); | 7 | const config = require('../config/keys'); |
8 | 8 | ||
... | @@ -10,51 +10,74 @@ const projectId = config.googleProjectID | ... | @@ -10,51 +10,74 @@ const projectId = config.googleProjectID |
10 | const sessionId = config.dialogFlowSessionID | 10 | const sessionId = config.dialogFlowSessionID |
11 | const languageCode = config.dialogFlowSessionLanguageCode | 11 | const languageCode = config.dialogFlowSessionLanguageCode |
12 | 12 | ||
13 | + | ||
13 | // Create a new session | 14 | // Create a new session |
14 | const sessionClient = new dialogflow.SessionsClient(); | 15 | const sessionClient = new dialogflow.SessionsClient(); |
15 | const sessionPath = sessionClient.sessionPath(projectId, sessionId); | 16 | const sessionPath = sessionClient.sessionPath(projectId, sessionId); |
16 | 17 | ||
17 | -//Text Query Route | 18 | +// We will make two routes |
18 | -router.post('/textQuery',async (req,res) => { | 19 | + |
20 | + | ||
21 | +// Text Query Route | ||
22 | + | ||
23 | +router.post('/textQuery', async (req, res) => { | ||
24 | + //We need to send some information that comes from the client to Dialogflow API | ||
25 | + // The text query request. | ||
19 | const request = { | 26 | const request = { |
20 | session: sessionPath, | 27 | session: sessionPath, |
21 | queryInput: { | 28 | queryInput: { |
22 | text: { | 29 | text: { |
23 | - // dialogflow agent에 보내는 query | 30 | + // The query to send to the dialogflow agent |
24 | text: req.body.text, | 31 | text: req.body.text, |
25 | - // 사용자언어 (ko) | 32 | + // The language used by the client (en-US) |
26 | languageCode: languageCode, | 33 | languageCode: languageCode, |
27 | }, | 34 | }, |
28 | }, | 35 | }, |
29 | }; | 36 | }; |
30 | 37 | ||
31 | - const response = await sessionClient.detectIntent(request); | 38 | + // Send request and log result |
32 | - console.log('Detected Intent'); | 39 | + const responses = await sessionClient.detectIntent(request); |
33 | - const result = response[0].queryResult; | 40 | + console.log('Detected intent'); |
41 | + const result = responses[0].queryResult; | ||
42 | + console.log(` Query: ${result.queryText}`); | ||
43 | + console.log(` Response: ${result.fulfillmentText}`); | ||
34 | 44 | ||
35 | res.send(result) | 45 | res.send(result) |
36 | -}); | 46 | +}) |
47 | + | ||
37 | 48 | ||
38 | 49 | ||
50 | +//Event Query Route | ||
39 | 51 | ||
40 | -// Event Query Route | 52 | +router.post('/eventQuery', async (req, res) => { |
41 | -router.post('/eventQuery',async (req,res) => { | 53 | + //We need to send some information that comes from the client to Dialogflow API |
54 | + // The text query request. | ||
42 | const request = { | 55 | const request = { |
43 | session: sessionPath, | 56 | session: sessionPath, |
44 | queryInput: { | 57 | queryInput: { |
45 | - text: { | 58 | + event: { |
46 | - name: req.body.text, | 59 | + // The query to send to the dialogflow agent |
47 | - // 사용자언어 (ko) | 60 | + name: req.body.event, |
61 | + // The language used by the client (en-US) | ||
48 | languageCode: languageCode, | 62 | languageCode: languageCode, |
49 | }, | 63 | }, |
50 | }, | 64 | }, |
51 | }; | 65 | }; |
52 | 66 | ||
53 | - const response = await sessionClient.detectIntent(request); | 67 | + // Send request and log result |
54 | - console.log('Detected Intent'); | 68 | + const responses = await sessionClient.detectIntent(request); |
55 | - const result = response[0].queryResult; | 69 | + console.log('Detected intent'); |
70 | + const result = responses[0].queryResult; | ||
71 | + console.log(` Query: ${result.queryText}`); | ||
72 | + console.log(` Response: ${result.fulfillmentText}`); | ||
56 | 73 | ||
57 | res.send(result) | 74 | res.send(result) |
58 | -}); | 75 | +}) |
76 | + | ||
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | ||
81 | + | ||
59 | 82 | ||
60 | -module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
83 | +module.exports = router; | ... | ... |
-
Please register or login to post a comment