Showing
6 changed files
with
191 additions
and
0 deletions
client/package-lock.json
0 → 100644
This diff could not be displayed because it is too large.
client/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "name": "client", | ||
| 3 | + "version": "0.1.0", | ||
| 4 | + "private": true, | ||
| 5 | + "dependencies": { | ||
| 6 | + "antd": "^3.26.5", | ||
| 7 | + "axios": "^0.18.0", | ||
| 8 | + "prop-types": "^15.7.2", | ||
| 9 | + "react": "^16.12.0", | ||
| 10 | + "react-dom": "^16.12.0", | ||
| 11 | + "react-redux": "^7.1.3", | ||
| 12 | + "react-router-dom": "^5.0.0", | ||
| 13 | + "react-scripts": "2.1.8", | ||
| 14 | + "redux": "^4.0.5", | ||
| 15 | + "redux-promise": "^0.6.0", | ||
| 16 | + "redux-thunk": "^2.3.0", | ||
| 17 | + "uuid": "^3.3.2" | ||
| 18 | + }, | ||
| 19 | + "scripts": { | ||
| 20 | + "start": "react-scripts start", | ||
| 21 | + "build": "react-scripts build", | ||
| 22 | + "test": "react-scripts test", | ||
| 23 | + "eject": "react-scripts eject" | ||
| 24 | + }, | ||
| 25 | + "eslintConfig": { | ||
| 26 | + "extends": "react-app" | ||
| 27 | + }, | ||
| 28 | + "browserslist": { | ||
| 29 | + "production": [ | ||
| 30 | + ">0.2%", | ||
| 31 | + "not dead", | ||
| 32 | + "not op_mini all" | ||
| 33 | + ], | ||
| 34 | + "development": [ | ||
| 35 | + "last 1 chrome version", | ||
| 36 | + "last 1 firefox version", | ||
| 37 | + "last 1 safari version" | ||
| 38 | + ] | ||
| 39 | + }, | ||
| 40 | + "devDependencies": { | ||
| 41 | + "http-proxy-middleware": "^0.19.1" | ||
| 42 | + } | ||
| 43 | +} |
| ... | @@ -3,6 +3,7 @@ const path = require("path"); | ... | @@ -3,6 +3,7 @@ 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 | 5 | ||
| 6 | +const config = require("./server/config/keys"); | ||
| 6 | app.use(bodyParser.urlencoded({ extended: true })); | 7 | app.use(bodyParser.urlencoded({ extended: true })); |
| 7 | app.use(bodyParser.json()); | 8 | app.use(bodyParser.json()); |
| 8 | 9 | ... | ... |
plan.md
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'); | 3 | const dialogflow = require('dialogflow'); |
| 4 | +const structjson = require('./structjson.js'); | ||
| 5 | + | ||
| 4 | 6 | ||
| 5 | const config = require('../config/keys'); | 7 | const config = require('../config/keys'); |
| 6 | 8 | ||
| ... | @@ -13,8 +15,46 @@ const sessionClient = new dialogflow.SessionsClient(); | ... | @@ -13,8 +15,46 @@ const sessionClient = new dialogflow.SessionsClient(); |
| 13 | const sessionPath = sessionClient.sessionPath(projectId, sessionId); | 15 | const sessionPath = sessionClient.sessionPath(projectId, sessionId); |
| 14 | 16 | ||
| 15 | //Text Query Route | 17 | //Text Query Route |
| 18 | +router.post('/textQuery',async (req,res) => { | ||
| 19 | + const request = { | ||
| 20 | + session: sessionPath, | ||
| 21 | + queryInput: { | ||
| 22 | + text: { | ||
| 23 | + // dialogflow agent에 보내는 query | ||
| 24 | + text: req.body.text, | ||
| 25 | + // 사용자언어 (ko) | ||
| 26 | + languageCode: languageCode, | ||
| 27 | + }, | ||
| 28 | + }, | ||
| 29 | + }; | ||
| 30 | + | ||
| 31 | + const response = await sessionClient.detectIntent(request); | ||
| 32 | + console.log('Detected Intent'); | ||
| 33 | + const result = response[0].queryResult; | ||
| 34 | + | ||
| 35 | + res.send(result) | ||
| 36 | +}); | ||
| 37 | + | ||
| 38 | + | ||
| 16 | 39 | ||
| 17 | // Event Query Route | 40 | // Event Query Route |
| 41 | +router.post('/eventQuery',async (req,res) => { | ||
| 42 | + const request = { | ||
| 43 | + session: sessionPath, | ||
| 44 | + queryInput: { | ||
| 45 | + text: { | ||
| 46 | + name: req.body.text, | ||
| 47 | + // 사용자언어 (ko) | ||
| 48 | + languageCode: languageCode, | ||
| 49 | + }, | ||
| 50 | + }, | ||
| 51 | + }; | ||
| 52 | + | ||
| 53 | + const response = await sessionClient.detectIntent(request); | ||
| 54 | + console.log('Detected Intent'); | ||
| 55 | + const result = response[0].queryResult; | ||
| 18 | 56 | ||
| 57 | + res.send(result) | ||
| 58 | +}); | ||
| 19 | 59 | ||
| 20 | module.exports = router; | 60 | module.exports = router; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
server/routes/structjson.js
0 → 100644
| 1 | +/** | ||
| 2 | + * Copyright 2017, Google, Inc. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * @fileoverview Utilities for converting between JSON and goog.protobuf.Struct | ||
| 18 | + * proto. | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +'use strict'; | ||
| 22 | + | ||
| 23 | +function jsonToStructProto(json) { | ||
| 24 | + const fields = {}; | ||
| 25 | + for (let k in json) { | ||
| 26 | + fields[k] = jsonValueToProto(json[k]); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + return {fields}; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +const JSON_SIMPLE_TYPE_TO_PROTO_KIND_MAP = { | ||
| 33 | + [typeof 0]: 'numberValue', | ||
| 34 | + [typeof '']: 'stringValue', | ||
| 35 | + [typeof false]: 'boolValue', | ||
| 36 | +}; | ||
| 37 | + | ||
| 38 | +const JSON_SIMPLE_VALUE_KINDS = new Set([ | ||
| 39 | + 'numberValue', | ||
| 40 | + 'stringValue', | ||
| 41 | + 'boolValue', | ||
| 42 | +]); | ||
| 43 | + | ||
| 44 | +function jsonValueToProto(value) { | ||
| 45 | + const valueProto = {}; | ||
| 46 | + | ||
| 47 | + if (value === null) { | ||
| 48 | + valueProto.kind = 'nullValue'; | ||
| 49 | + valueProto.nullValue = 'NULL_VALUE'; | ||
| 50 | + } else if (value instanceof Array) { | ||
| 51 | + valueProto.kind = 'listValue'; | ||
| 52 | + valueProto.listValue = {values: value.map(jsonValueToProto)}; | ||
| 53 | + } else if (typeof value === 'object') { | ||
| 54 | + valueProto.kind = 'structValue'; | ||
| 55 | + valueProto.structValue = jsonToStructProto(value); | ||
| 56 | + } else if (typeof value in JSON_SIMPLE_TYPE_TO_PROTO_KIND_MAP) { | ||
| 57 | + const kind = JSON_SIMPLE_TYPE_TO_PROTO_KIND_MAP[typeof value]; | ||
| 58 | + valueProto.kind = kind; | ||
| 59 | + valueProto[kind] = value; | ||
| 60 | + } else { | ||
| 61 | + console.warn('Unsupported value type ', typeof value); | ||
| 62 | + } | ||
| 63 | + return valueProto; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +function structProtoToJson(proto) { | ||
| 67 | + if (!proto || !proto.fields) { | ||
| 68 | + return {}; | ||
| 69 | + } | ||
| 70 | + const json = {}; | ||
| 71 | + for (const k in proto.fields) { | ||
| 72 | + json[k] = valueProtoToJson(proto.fields[k]); | ||
| 73 | + } | ||
| 74 | + return json; | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +function valueProtoToJson(proto) { | ||
| 78 | + if (!proto || !proto.kind) { | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + if (JSON_SIMPLE_VALUE_KINDS.has(proto.kind)) { | ||
| 83 | + return proto[proto.kind]; | ||
| 84 | + } else if (proto.kind === 'nullValue') { | ||
| 85 | + return null; | ||
| 86 | + } else if (proto.kind === 'listValue') { | ||
| 87 | + if (!proto.listValue || !proto.listValue.values) { | ||
| 88 | + console.warn('Invalid JSON list value proto: ', JSON.stringify(proto)); | ||
| 89 | + } | ||
| 90 | + return proto.listValue.values.map(valueProtoToJson); | ||
| 91 | + } else if (proto.kind === 'structValue') { | ||
| 92 | + return structProtoToJson(proto.structValue); | ||
| 93 | + } else { | ||
| 94 | + console.warn('Unsupported JSON value proto kind: ', proto.kind); | ||
| 95 | + return null; | ||
| 96 | + } | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +module.exports = { | ||
| 100 | + jsonToStructProto, | ||
| 101 | + structProtoToJson, | ||
| 102 | +}; |
-
Please register or login to post a comment