firtssocketia 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of firtssocketia might be problematic. Click here for more details.
- package/package.json +34 -0
- package/src/Public/Imagenes/asist.jpg +0 -0
- package/src/Public/css/estilos.css +433 -0
- package/src/Public/index.html +171 -0
- package/src/Public/js/clean_chat_mysql.js +94 -0
- package/src/Public/js/correction.js +85 -0
- package/src/Public/js/loby.js +32 -0
- package/src/Public/js/main.js +117 -0
- package/src/Public/web components/rasa component.js +78 -0
- package/src/Public/web components/recognition component.js +168 -0
- package/src/index.js +32 -0
- package/src/sockets.js +125 -0
package/src/sockets.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*const mysql = require('mysql');
|
|
2
|
+
|
|
3
|
+
const connectionB = mysql.createConnection({
|
|
4
|
+
host: 'localhost',
|
|
5
|
+
user: 'root',
|
|
6
|
+
password: '',
|
|
7
|
+
database: 'chat'
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
connectionB.connect(function(err) {
|
|
11
|
+
if (err) {
|
|
12
|
+
console.error('Error al conectarse a la base de datos: ' + err.stack);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
console.log('Conectado a la base de datos como el ID ' + connectionB.threadId);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
module.exports = function(io) {
|
|
19
|
+
io.on('connection', (socket) => {
|
|
20
|
+
console.log('Un usuario se ha conectado');
|
|
21
|
+
connectionB.query('SELECT * FROM messages ORDER BY msg_id ASC', function(error, results, fields) {
|
|
22
|
+
if (error) throw error;
|
|
23
|
+
results.forEach(function(result) {
|
|
24
|
+
socket.emit('new message', { message: result.msg, response: result.bots });
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
socket.on('Send message', function(data) {
|
|
29
|
+
const https = require('https');
|
|
30
|
+
const options = {
|
|
31
|
+
hostname: '25a0-200-24-154-53.ngrok.io/',
|
|
32
|
+
port: 443,
|
|
33
|
+
path: '/webhooks/rest/webhook',
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' }
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const req = https.request(options, (res) => {
|
|
39
|
+
let responseBody = '';
|
|
40
|
+
res.on('data', (chunk) => {
|
|
41
|
+
responseBody += chunk;
|
|
42
|
+
});
|
|
43
|
+
res.on('end', () => {
|
|
44
|
+
try {
|
|
45
|
+
const response = JSON.parse(responseBody);
|
|
46
|
+
const responseData = response[0].text;
|
|
47
|
+
io.emit('new message', { message: data, response: responseData });
|
|
48
|
+
const cleanMsg = responseData.replace(/\p{Emoji}/gu, '');
|
|
49
|
+
connectionB.query('INSERT INTO messages (incoming_msg_id, outgoing_msg_id, msg, bots) VALUES (?, ?, ?, ?)', [2, 3, data, cleanMsg], function(error, results, fields) {
|
|
50
|
+
if (error) throw error;
|
|
51
|
+
console.log('Mensaje insertado correctamente!');
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
req.on('error', (error) => {
|
|
60
|
+
console.error(error);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
req.write(JSON.stringify({ message: data }));
|
|
64
|
+
req.end();
|
|
65
|
+
});
|
|
66
|
+
socket.on('clear messages', function() {
|
|
67
|
+
try {
|
|
68
|
+
connectionB.query('DELETE FROM messages', function(error, results, fields) {
|
|
69
|
+
if (error) throw error;
|
|
70
|
+
console.log('Mensajes eliminados correctamente!');
|
|
71
|
+
socket.emit('clear chat');
|
|
72
|
+
});
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.log('Error al eliminar mensajes:', error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};*/
|
|
79
|
+
module.exports = function(io) {
|
|
80
|
+
io.on('connection', (socket) => {
|
|
81
|
+
console.log('Un usuario se ha conectado');
|
|
82
|
+
|
|
83
|
+
socket.on('Send message', function(data) {
|
|
84
|
+
io.emit('new message', { message: data });
|
|
85
|
+
const https = require('https');
|
|
86
|
+
const options = {
|
|
87
|
+
hostname: '25a0-200-24-154-53.ngrok.io/',
|
|
88
|
+
port: 443,
|
|
89
|
+
path: '/webhooks/rest/webhook',
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { 'Content-Type': 'application/json' }
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const req = https.request(options, (res) => {
|
|
95
|
+
let responseBody = '';
|
|
96
|
+
res.on('data', (chunk) => {
|
|
97
|
+
responseBody += chunk;
|
|
98
|
+
});
|
|
99
|
+
res.on('end', () => {
|
|
100
|
+
try {
|
|
101
|
+
const response = JSON.parse(responseBody);
|
|
102
|
+
const responseData = response[0].text;
|
|
103
|
+
io.emit('new message', { message: responseData });
|
|
104
|
+
const cleanMsg = responseData.replace(/\p{Emoji}/gu, '');
|
|
105
|
+
console.log('Mensaje insertado correctamente!');
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(error);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
req.on('error', (error) => {
|
|
113
|
+
console.error(error);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
req.write(JSON.stringify({ message: data }));
|
|
117
|
+
req.end();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
socket.on('clear messages', function() {
|
|
121
|
+
console.log('Mensajes eliminados correctamente!');
|
|
122
|
+
socket.emit('clear chat');
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|