4 Commits

Author SHA1 Message Date
Sharon Kennedy
687dfa84e9 2.0.2 2020-09-11 16:29:31 -04:00
Sharon Kennedy
b7da515969 Merge branch 'master' of github.com:nomadic-labs/ocrcc-bot 2020-09-11 16:29:08 -04:00
Sharon Kennedy
e2c291c040 change notice to signal 2020-09-11 16:12:01 -04:00
brent
87f2c5290f add timezone to dockerfile 2020-09-08 10:41:29 -04:00
4 changed files with 25 additions and 9 deletions

View File

@@ -1,6 +1,9 @@
FROM node:10-alpine FROM node:10-alpine
RUN apk add g++ make python RUN apk add g++ make python
RUN apk add tzdata
ENV TZ America/Montreal
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

14
dist/bot.js vendored
View File

@@ -27,6 +27,7 @@ var _encryptAttachment = _interopRequireDefault(require("./encrypt-attachment"))
global.Olm = require("olm"); global.Olm = require("olm");
const BOT_SIGNAL_END_CHAT = 'END_CHAT'; const BOT_SIGNAL_END_CHAT = 'END_CHAT';
const BOT_SIGNAL_CHAT_OFFLINE = 'CHAT_OFFLINE';
class OcrccBot { class OcrccBot {
constructor(botConfig) { constructor(botConfig) {
@@ -149,7 +150,7 @@ class OcrccBot {
} else { } else {
_logger.default.log('info', "NO FACILITATORS ONLINE"); _logger.default.log('info', "NO FACILITATORS ONLINE");
this.sendNotice(roomId, "CHAT_OFFLINE"); this.sendBotSignal(roomId, BOT_SIGNAL_CHAT_OFFLINE);
} }
} catch (err) { } catch (err) {
this.handleBotCrash(roomId, err); this.handleBotCrash(roomId, err);
@@ -574,10 +575,13 @@ class OcrccBot {
} }
setTimeoutforFacilitator(roomId) { setTimeoutforFacilitator(roomId) {
setTimeout(() => { setTimeout(async () => {
const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`); const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`);
if (stillWaiting) { if (stillWaiting) {
_logger.default.log("info", `FACILITATOR DID NOT JOIN CHAT WITHIN TIME LIMIT, SENDING SIGNAL TO END CHAT`);
await this.sendTextMessage(roomId, this.config.CHAT_NOT_AVAILABLE_MESSAGE);
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT); this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
} }
}, this.config.MAX_WAIT_TIME); }, this.config.MAX_WAIT_TIME);
@@ -590,8 +594,10 @@ class OcrccBot {
clearTimeout(oldTimeout); clearTimeout(oldTimeout);
} }
const newTimeout = setTimeout(() => { const newTimeout = setTimeout(async () => {
this.sendTextMessage(roomId, `This chat has been closed due to inactivity.`); _logger.default.log("info", `CHAT IS INACTIVE, SENDING SIGNAL TO END CHAT`);
await this.sendTextMessage(roomId, `This chat has been closed due to inactivity.`);
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT); this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT);
}, this.config.MAX_INACTIVE); }, this.config.MAX_INACTIVE);
this.inactivityTimers[roomId] = newTimeout; this.inactivityTimers[roomId] = newTimeout;

View File

@@ -1,6 +1,6 @@
{ {
"name": "private-safesupport-bot", "name": "private-safesupport-bot",
"version": "2.0.1", "version": "2.0.2",
"description": "Chatbot to manage interactions on Safe Support Chat", "description": "Chatbot to manage interactions on Safe Support Chat",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {

View File

@@ -12,6 +12,7 @@ import logger from "./logger";
import encrypt from "./encrypt-attachment"; import encrypt from "./encrypt-attachment";
const BOT_SIGNAL_END_CHAT = 'END_CHAT' const BOT_SIGNAL_END_CHAT = 'END_CHAT'
const BOT_SIGNAL_CHAT_OFFLINE = 'CHAT_OFFLINE'
class OcrccBot { class OcrccBot {
@@ -130,7 +131,7 @@ class OcrccBot {
this.localStorage.setItem(`${roomId}-invitations`, invitations) this.localStorage.setItem(`${roomId}-invitations`, invitations)
} else { } else {
logger.log('info', "NO FACILITATORS ONLINE") logger.log('info', "NO FACILITATORS ONLINE")
this.sendNotice(roomId, "CHAT_OFFLINE") this.sendBotSignal(roomId, BOT_SIGNAL_CHAT_OFFLINE)
} }
} catch(err) { } catch(err) {
@@ -596,9 +597,14 @@ class OcrccBot {
} }
setTimeoutforFacilitator(roomId) { setTimeoutforFacilitator(roomId) {
setTimeout(() => { setTimeout(async() => {
const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`) const stillWaiting = this.localStorage.getItem(`${roomId}-waiting`)
if (stillWaiting) { if (stillWaiting) {
logger.log("info", `FACILITATOR DID NOT JOIN CHAT WITHIN TIME LIMIT, SENDING SIGNAL TO END CHAT`);
await this.sendTextMessage(
roomId,
this.config.CHAT_NOT_AVAILABLE_MESSAGE
);
this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT) this.sendBotSignal(roomId, BOT_SIGNAL_END_CHAT)
} }
}, this.config.MAX_WAIT_TIME) }, this.config.MAX_WAIT_TIME)
@@ -611,8 +617,9 @@ class OcrccBot {
clearTimeout(oldTimeout); clearTimeout(oldTimeout);
} }
const newTimeout = setTimeout(() => { const newTimeout = setTimeout(async() => {
this.sendTextMessage( logger.log("info", `CHAT IS INACTIVE, SENDING SIGNAL TO END CHAT`);
await this.sendTextMessage(
roomId, roomId,
`This chat has been closed due to inactivity.` `This chat has been closed due to inactivity.`
); );