Commit 813e8ce8 authored by Anastasios Kalogeropoulos's avatar Anastasios Kalogeropoulos
Browse files

store messages in history

parent 03e112d2
......@@ -34,4 +34,4 @@ app.post('/facilitator/newStatus', cors(), (req, res) => {
}
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
\ No newline at end of file
app.listen(port, () => console.log(`Facilitator status handler listening on port ${port}!`))
\ No newline at end of file
......@@ -13,10 +13,18 @@ const server = http.createServer(app);
const wss = new WebSocket.Server({ server, path: '/webplugin' }); // Accept only connections matching this path
const END_OF_CONVERSATION_TEXT = "END_OF_CONVERSATION"
class Client {
constructor(ws, uuid) {
this.ws = ws;
this.uuid = uuid;
this.conversation_history = [];
}
saveMessageInHistory(text) {
this.conversation_history.push(text);
}
}
......@@ -59,10 +67,13 @@ wss.on('connection', (ws) => {
return obj.uuid === incomingMessage['sender']['id'];
});
//Send the incoming message to slack bot
//Incoming message from Web plugin - send it slack bot
if (incomingMessage['message']) {
console.log("Incoming message: ", incomingMessage['message']['text']);
rtm.sendMessage(incomingMessage['message']['text'], channel)
let incomingText = incomingMessage['message']['text'];
console.log("Incoming message: ", incomingText);
currentClient.saveMessageInHistory(incomingText);
rtm.sendMessage(incomingText, channel)
.then((res) => {
// `res` contains information about the posted message
console.log('Message sent: ', res.ts);
......@@ -76,8 +87,9 @@ wss.on('connection', (ws) => {
let conversationStatus = getConversationStatus(ws, uuid);
ws.send(JSON.stringify(conversationStatus));
});
});
// Get message from slack bot and send it to web-plugin
rtm.on('message', (message) => {
// Skip messages that are from a bot or my own user ID
......@@ -87,11 +99,15 @@ rtm.on('message', (message) => {
}
console.log(`(channel:${message.channel}) ${message.user} says: ${message.text}`);
//Get text from slack bot and send it to web-plugin
let outgoingMessage = createOutgoingMessage(message.text, currentClient.uuid);
currentClient.ws.send(JSON.stringify(outgoingMessage));
let outgoingMessage = createOutgoingMessage(message.text, currentClient.uuid);
currentClient.saveMessageInHistory(message.text);
if(message.text.includes(END_OF_CONVERSATION_TEXT)) {
console.log(currentClient.conversation_history);
console.log(message.text);
} else {
currentClient.ws.send(JSON.stringify(outgoingMessage));
}
});
function createOutgoingMessage(text, uuid) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment