npm i -g satoridb
npm i satori-node
const {Satori} = require('satori-node');
const satori = new Satori({host: 'ws://127.0.0.1:2321'});
async function main(){
await satori.connect();
const key = await satori.set({data: {"email" : "test@test.com"}});
console.log(await satori.get({key}))
await satori.put({key, replace_field: "email", replace_value: "tes2@test.com"})
await satori.delete({key})
}
import { Satori } from 'satori-node';
async function runChatbot() {
const client = new Satori({
username: 'admin',
password: '1234',
host: 'ws://127.0.0.1:2310'
});
await client.connect();
console.log("Chatbot ready");
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
async function askUser() {
readline.question('You: ', async (input) => {
if (input.toLowerCase() === 'exit') {
console.log('Closing chatbot...');
readline.close();
await cliente.disconnect();
process.exit(0);
}
// Guardar mensaje del usuario
const msgKey = `chat:msg:${Date.now()}`;
await cliente.set({
key: msgKey,
data: { sender: 'user', text: input, timestamp: Date.now() },
type: 'chat_message'
});
// Intentar responder usando la función ask (modelo NLP entrenado)
try {
const response = await cliente.ask({ question: input });
if (response && response.answer) {
console.log('Bot:', response.answer);
// Guardar respuesta del bot
const botMsgKey = `chat:msg:${Date.now()}-bot`;
await cliente.set({
key: botMsgKey,
data: { sender: 'bot', text: response.answer, timestamp: Date.now() },
type: 'chat_message'
});
} else {
// Respuesta por defecto si no hay resultado
console.log('Bot: Sorry, I do not understand.');
}
} catch (error) {
console.error('Error processing your question:', error);
console.log('Bot: Sorry, there was an error.');
}
askUser(); // Preguntar de nuevo
});
}
askUser();
}
runChatbot();
Was this page helpful?