no message
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "digitalerdemenztest",
|
||||
"private_key_id": "1cb9f88917f63afddde619107e1ce106077c936e",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtI/uoe6Q48Ak3\nWyVqueUJAed4trmb2Bm6UeSrYU+5IGY6zO86JyOIUDwo3CxYq38q9N3xJdI91z36\nqDtPdf2j7bSfUPo1VMgVH4ZXLb06+ddJBFxxEXLlJrGbWsKareZC2+Zoat0oOhSv\n8XQIdTBwzwC/VJs5KFmb2eh6uNsMVPhFivpQc4dkMGslreLvgQdJMDje7prRB6su\nOnAvKl1cFPpMg++e6vfeKZmoGUSv81ytV8Iu5QbTRabJvmeEba1QgTSqDdZw7EcM\nxB38Jv7TCnALmCi0pBSKiyJk/7m07b2Vj4huIYPAWsAe6cPs6m+CZEGnvCXqgU+v\nfbmX3eZbAgMBAAECggEABobZOUAz8BuIVWhfsDbCvgSu25uTwp6yVZY5twYrkbB5\nehT4naoVClHv+qBWIZ+RYyao6SrCUqd3BChsV/H8Nj5DNVBBploEUtuF3mpwfDUn\n2u5Jp89/E8lSH6ebt2X/zJxqgpwoqxgJaJqDA8CbK116Szwev9hYDGp5+4pVY5EO\njDeZBJaY97hoDFjK4EKepLr0NPHWjfkxDBGzmm1kzfqYiVXw36tEyFIeuwJR9g1A\nQyLuyRfxWZ7o6sYNvSRciwGG+uzGcQpXoFfiOgzU0dzLeje+aQHdKmQLFsJ2Wnux\n45fe+IkePWtSWpr+zd0DEw8v2RGR2tEgONresylycQKBgQDXtm+9BSX9vEaOjxaI\ne8UTtoZ3t189E7bZ3xT2k5yRNPCMfnvR5RklFIv+zsbj1ilWIUTuMufdZWEy6sca\nyeifOL/Qqz2mokFa2gBO1zVl8kawWlxoeiPEAhpDw7XGwTCXgNDQsEaItdlosZUN\n4AHXjNmfzWQFZOhX9Fwgn6O3iwKBgQDNehuT50uC4zLjTCef+jypL/PMqssoFRxH\nXDqYoRkYHx8xwzSZsvc8eTboz8iC53IEbz8IAA7wYNxdun5sKGa56b1ZyyF+HQdj\ngCuHPKrWGVSuipxq68V3AJ8jqcfWxbmwzVJs4kUCjMCts1f8D+7D/c3knH1wbT+J\nh7mN+3nmcQKBgG+kpXo/8uS7EA1ycygaXuqP+lJ1np4e2PE0K0ZfKZZhvuoIAI+m\nsffmBXrQjFGZIvXH7EQYJrcIZGEU8A2mWHYnyeb26caXjZm24JftfF6SIRHfApq0\nNFSa/fr6jNccX8jZy7lmsmrJK4eq+UkgGfP0myHBDLZZ/oKfHxtnZDV3AoGABrDR\nMRG4/bwULh6Os8DcNM4g7CsrjlSRpSk1pz6nqIdq5p3qmo6fSlLQHOiXKNwMdGSC\n8um9kso0osCt2Su/nJIl3kSlBIxBb1X/FNo+3dXZUg2lZj3jIirdA7ZFkZLCpyUo\nZ+8+PAUFSSKr3MNQDQW4rJcD5qNIDFxlCGCF6aECgYEArXlfVjBTQVZGt30hRhoC\n21CFcy++vYsDSZK8ah1cfuMXnz8rAU7qQSPXSpbQC5/Jr1+FOszeHAuvIQRVF4ZZ\neP6QVicxxurN7v+oBzWpqFnpsyxHcTUxsokATg9VXSAYLHvG1bICLem/giC56Twa\ncRvr50JjmWe2XZX8Um94WU4=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "demenz-dialogflow@digitalerdemenztest.iam.gserviceaccount.com",
|
||||
"client_id": "114624321748994791485",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/demenz-dialogflow%40digitalerdemenztest.iam.gserviceaccount.com"
|
||||
}
|
||||
Generated
+2984
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "websocket_example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "ws-client.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"tunnel": "ngrok http 8000"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dialogflow": "^0.10.0",
|
||||
"express": "^4.17.1",
|
||||
"ngrok": "^3.1.1",
|
||||
"path": "^0.12.7",
|
||||
"websocket": "^1.0.28",
|
||||
"ws": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^12.0.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// dialogflow
|
||||
const dialogflow = require('dialogflow');
|
||||
|
||||
// server and websocket
|
||||
const WebSocket = require('ws');
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
|
||||
const webSocketsServerPort = 8000;
|
||||
const serverpath = '/ws';
|
||||
const app = express();
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', function (req, res) {
|
||||
res.sendFile(path.join(__dirname + '/index.html'));
|
||||
});
|
||||
|
||||
app.use(express.static(__dirname + '/../client'));
|
||||
|
||||
app.use('/', router);
|
||||
|
||||
var server = http.createServer(app);
|
||||
|
||||
server.listen(process.env.port || webSocketsServerPort, function () {
|
||||
console.log((new Date()) + ' Server is listening on port ' +
|
||||
webSocketsServerPort);
|
||||
});
|
||||
|
||||
const wss = new WebSocket.Server({ server: server, path: serverpath });
|
||||
|
||||
wss.on('connection', function connection (ws) {
|
||||
ws.id = wss.getUniqueID();
|
||||
|
||||
console.log(ws.id + ' connected');
|
||||
|
||||
ws.on('message', function incoming (message) {
|
||||
promptQuery(message, ws);
|
||||
});
|
||||
|
||||
ws.on('close', function (connection) {
|
||||
// close user connection
|
||||
});
|
||||
});
|
||||
|
||||
const projectId = 'digitalerdemenztest';
|
||||
|
||||
const sessionClient = new dialogflow.SessionsClient({
|
||||
keyFilename: 'dialogflow_cred_dem.json'
|
||||
});
|
||||
|
||||
// Send request and log result
|
||||
function promptQuery (prompt, wsock) {
|
||||
let sessionId = wsock.id;
|
||||
let sessionPath = sessionClient.sessionPath(projectId, sessionId);
|
||||
|
||||
const request = {
|
||||
session: sessionPath,
|
||||
queryInput: {
|
||||
text: {
|
||||
text: prompt,
|
||||
languageCode: 'de-DE'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
sessionClient
|
||||
.detectIntent(request)
|
||||
.then(responses => {
|
||||
const result = responses[0].queryResult;
|
||||
console.log(` Query: ${result.queryText}`);
|
||||
console.log(` Response: ${result.fulfillmentText}`);
|
||||
if (result.intent) {
|
||||
console.log(` Intent: ${result.intent.displayName}`);
|
||||
} else {
|
||||
console.log(` No intent matched.`);
|
||||
}
|
||||
wsock.send(JSON.stringify(result));
|
||||
|
||||
// checkIntent(result)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// create unique id
|
||||
wss.getUniqueID = function () {
|
||||
function s4 () {
|
||||
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
||||
}
|
||||
return s4() + s4() + '-' + s4();
|
||||
};
|
||||
Reference in New Issue
Block a user