9 Commits

Author SHA1 Message Date
Sharon Kennedy
4cddeae508 1.1.0 2020-06-11 11:00:57 -04:00
Sharon Kennedy
a323602a1d remove unused env var 2020-06-11 10:59:56 -04:00
Sharon Kennedy
21a15c5efc add metadata to file upload so it works on the app 2020-06-11 01:54:36 -04:00
Sharon Kennedy
16c9fd4148 move offline messaging to chatbox 2020-06-10 16:59:28 -04:00
edwardsbrentg
f7a9851b7d Merge pull request #1 from nomadic-labs/feature/add-dockerfile
add dockerfile
2020-05-29 14:54:01 -04:00
Sharon Kennedy
74a1e29f1b 1.0.1 2020-05-27 22:25:57 -04:00
Sharon Kennedy
b35bcd7dc7 rename package to private-safesupport-bot 2020-05-27 22:25:47 -04:00
Sharon Kennedy
189140e1f9 use room membership for chat invitations instead of community membership to fix presence bug 2020-05-27 22:24:14 -04:00
brent
6c877c9016 add dockerfile 2020-05-24 21:23:21 -04:00
6 changed files with 51 additions and 32 deletions

View File

@@ -3,5 +3,6 @@ BOT_DISPLAY_NAME=
BOT_USERNAME= BOT_USERNAME=
BOT_PASSWORD= BOT_PASSWORD=
BOT_USERID= BOT_USERID=
FACILITATOR_GROUP_ID=
FACILITATOR_ROOM_ID= FACILITATOR_ROOM_ID=
CHAT_OFFLINE_MESSAGE= CAPTURE_TRANSCRIPTS

20
Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
FROM node:10-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY ./src/ ./src/
COPY ./transcripts/ ./transcripts/
COPY package*.json ./
USER node
RUN npm config set strict-ssl false
RUN npm install
RUN npm config set strict-ssl true
RUN npm run build
COPY --chown=node:node . .
CMD ["npm", "start"]

View File

@@ -1,6 +1,6 @@
{ {
"name": "safesupport-bot", "name": "private-safesupport-bot",
"version": "1.0.0", "version": "1.1.0",
"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": {
@@ -13,7 +13,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"matrix-js-sdk": "^5.0.1", "matrix-js-sdk": "^6.2.1",
"node-localstorage": "^2.1.5", "node-localstorage": "^2.1.5",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz", "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
"uuidv4": "^6.0.2", "uuidv4": "^6.0.2",

View File

@@ -109,15 +109,14 @@ class OcrccBot {
let chatOffline = true; let chatOffline = true;
try { try {
const data = await this.client.getGroupUsers(this.config.FACILITATOR_GROUP_ID) const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
const members = data.chunk const members = Object.keys(roomMembers["joined"]);
members.forEach(member => { members.forEach(memberId => {
const memberId = member.user_id;
const user = this.client.getUser(memberId); const user = this.client.getUser(memberId);
if ( if (
user && user &&
user.presence === "online" && (user.presence === "online") &&
memberId !== this.config.BOT_USERID memberId !== this.config.BOT_USERID
) { ) {
chatOffline = false; chatOffline = false;
@@ -127,8 +126,7 @@ class OcrccBot {
if (chatOffline) { if (chatOffline) {
logger.log('info', "NO FACILITATORS ONLINE") logger.log('info', "NO FACILITATORS ONLINE")
this.sendTextMessage(roomId, this.config.CHAT_OFFLINE_MESSAGE); this.sendNotice(roomId, "CHAT_OFFLINE")
this.sendNotice(roomId, "Chat is offline")
} }
} catch(err) { } catch(err) {
@@ -142,18 +140,17 @@ class OcrccBot {
this.localStorage.removeItem(`${roomId}-waiting`) this.localStorage.removeItem(`${roomId}-waiting`)
try { try {
const groupUsers = await this.client.getGroupUsers(this.config.FACILITATOR_GROUP_ID) const facilitatorsRoomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
const roomMembers = await this.client.getJoinedRoomMembers(roomId) const supportRoomMembers = await this.client.getJoinedRoomMembers(roomId)
const roomMemberIds = Object.keys(roomMembers["joined"]); const roomMembersIds = Object.keys(supportRoomMembers["joined"]);
const groupMemberIds = groupUsers["chunk"] const facilitatorsIds = Object.keys(facilitatorsRoomMembers["joined"]);
if (!roomMemberIds || !groupMemberIds) return; if (!roomMembersIds || !facilitatorsIds) return;
const facilitatorsIds = groupMemberIds.map(f => f.user_id);
facilitatorsIds.forEach(f => { facilitatorsIds.forEach(f => {
if (!roomMemberIds.includes(f)) { if (!roomMembersIds.includes(f)) {
this.kickUserFromRoom(roomId, f); this.kickUserFromRoom(roomId, f);
} }
}); });
@@ -291,17 +288,20 @@ class OcrccBot {
} }
const filename = path.basename(transcriptFile) || "Transcript"; const filename = path.basename(transcriptFile) || "Transcript";
const stream = fs.createReadStream(transcriptFile); const file = fs.readFileSync(transcriptFile);
const stats = fs.statSync(transcriptFile);
const contentUrl = await this.client.uploadContent({ const url = await this.client.uploadContent(file, { rawResponse: false, type: 'text/plain' })
stream: stream, logger.log('info', url)
name: filename
})
const content = { const content = {
msgtype: "m.file", msgtype: "m.file",
body: filename, body: filename,
url: JSON.parse(contentUrl).content_uri, info: {
size: stats.size,
mimetype: 'text/plain'
},
url: url.content_uri,
showToUser: senderId showToUser: senderId
}; };

View File

@@ -13,8 +13,7 @@ const {
BOT_DISPLAY_NAME, BOT_DISPLAY_NAME,
FACILITATOR_GROUP_ID, FACILITATOR_GROUP_ID,
FACILITATOR_ROOM_ID, FACILITATOR_ROOM_ID,
CHAT_OFFLINE_MESSAGE, CAPTURE_TRANSCRIPTS,
CAPTURE_TRANSCRIPTS
} = process.env; } = process.env;
const botConfig = { const botConfig = {
@@ -29,8 +28,7 @@ const botConfig = {
BOT_DISPLAY_NAME, BOT_DISPLAY_NAME,
FACILITATOR_GROUP_ID, FACILITATOR_GROUP_ID,
FACILITATOR_ROOM_ID, FACILITATOR_ROOM_ID,
CHAT_OFFLINE_MESSAGE, CAPTURE_TRANSCRIPTS,
CAPTURE_TRANSCRIPTS
} }
import OcrccBot from './bot' import OcrccBot from './bot'

View File

@@ -3762,10 +3762,10 @@ map-visit@^1.0.0:
dependencies: dependencies:
object-visit "^1.0.0" object-visit "^1.0.0"
matrix-js-sdk@^5.0.1: matrix-js-sdk@^6.2.1:
version "5.1.0" version "6.2.1"
resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-5.1.0.tgz#9b3b02af227ecc2d0cc35fb7312c92b8a6754293" resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-6.2.1.tgz#d5f76491a650c0a36fcdd078cff59f2da96edd7b"
integrity sha512-IGRq5iACiKp3iIxAghwtdBPrbdgORowc0i8YuIMkZZMpRJDXnNaudt2BFwyQdukV7gvzz7F0sfxBUerySfOnKA== integrity sha512-X12Y2SMg8MOJwE5P3VMsMV/mnQHOmyJkF+FZRida124w4B4tBJouaNxteYyYaH34w+wyaKGxuqEBXecfSpfvbw==
dependencies: dependencies:
"@babel/runtime" "^7.8.3" "@babel/runtime" "^7.8.3"
another-json "^0.2.0" another-json "^0.2.0"