Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
139aa3a377 | ||
|
|
f207e7a258 | ||
|
|
135b9f079a | ||
|
|
46c2467368 | ||
|
|
0ad65e9dcc | ||
|
|
6c882a44cc | ||
|
|
666f2361c8 | ||
|
|
d3747cc654 | ||
|
|
687dfa84e9 | ||
|
|
b7da515969 | ||
|
|
e2c291c040 | ||
|
|
87f2c5290f | ||
|
|
4fdddc8c92 | ||
|
|
d53a5c5e26 | ||
|
|
9772b3b1fd | ||
|
|
84fe91adbb | ||
|
|
b6cd85eab0 | ||
|
|
209b3aaa45 | ||
|
|
4912ce6f61 | ||
|
|
013ffa318f |
@@ -1,7 +0,0 @@
|
|||||||
MATRIX_SERVER_URL=
|
|
||||||
BOT_DISPLAY_NAME=
|
|
||||||
BOT_USERNAME=
|
|
||||||
BOT_PASSWORD=
|
|
||||||
BOT_USERID=
|
|
||||||
FACILITATOR_ROOM_ID=
|
|
||||||
CAPTURE_TRANSCRIPTS
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ node_modules
|
|||||||
*.log
|
*.log
|
||||||
__mocks__/test_transcript.txt
|
__mocks__/test_transcript.txt
|
||||||
transcripts/*.txt
|
transcripts/*.txt
|
||||||
|
config.json
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
FROM node:10-alpine
|
FROM node:10-alpine
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
WORKDIR /home/node/app
|
WORKDIR /home/node/app
|
||||||
|
|||||||
28
README.md
28
README.md
@@ -1,19 +1,10 @@
|
|||||||
# Safe Support Chat Bot
|
# Safe Support Chat Bot
|
||||||
|
|
||||||
A simple Matrix bot that handles inviting, uninviting, and notifying Riot users on the recieving end of the [Safe Support chatbox](https://github.com/nomadic-labs/safesupport-chatbox).
|
A simple Matrix bot that handles inviting, uninviting, and notifying Riot users on the recieving end of the [Safe Support chatbox](https://github.com/Safe-Support-Chat/ocrcc-chatbox).
|
||||||
|
|
||||||
|
The bot configuration file is `config.json`. It can also pull in user-set configurations from the Safe Support Chat Admin app. To do so, run the command `yarn setup` before starting the bot.
|
||||||
|
|
||||||
The bot can be configured with an `.env` file with the following variables:
|
|
||||||
|
|
||||||
```
|
|
||||||
MATRIX_SERVER_URL=
|
|
||||||
BOT_DISPLAY_NAME=
|
|
||||||
BOT_USERNAME=
|
|
||||||
BOT_PASSWORD=
|
|
||||||
BOT_USERID=
|
|
||||||
FACILITATOR_ROOM_ID=
|
|
||||||
CHAT_OFFLINE_MESSAGE=
|
|
||||||
CAPTURE_TRANSCRIPTS=
|
|
||||||
```
|
|
||||||
## What does the bot do?
|
## What does the bot do?
|
||||||
* The bot receives an invitation to every chatroom created by the embedded chatbox, and automatically accepts
|
* The bot receives an invitation to every chatroom created by the embedded chatbox, and automatically accepts
|
||||||
* Upon joining a new room, the bot invites all of the members of the Facilitators community
|
* Upon joining a new room, the bot invites all of the members of the Facilitators community
|
||||||
@@ -29,7 +20,7 @@ CAPTURE_TRANSCRIPTS=
|
|||||||
### Bot commands
|
### Bot commands
|
||||||
|
|
||||||
|Command|Response|
|
|Command|Response|
|
||||||
--- | ---
|
--- | ---
|
||||||
|`!bot hi`|Bot responds with a greeting|
|
|`!bot hi`|Bot responds with a greeting|
|
||||||
|`!bot transcript`|Bot sends the chat transcript as a .txt file|
|
|`!bot transcript`|Bot sends the chat transcript as a .txt file|
|
||||||
|`!bot transcript please`|Bot happily sends the transcript :)|
|
|`!bot transcript please`|Bot happily sends the transcript :)|
|
||||||
@@ -39,7 +30,7 @@ If you prefer to develop locally instead of on Glitch:
|
|||||||
|
|
||||||
Clone the project
|
Clone the project
|
||||||
```
|
```
|
||||||
git clone https://github.com/nomadic-labs/safesupport-bot.git
|
git clone https://github.com/Safe-Support-Chat/ocrcc-bot.git
|
||||||
```
|
```
|
||||||
|
|
||||||
Install dependencies
|
Install dependencies
|
||||||
@@ -48,9 +39,14 @@ cd safesupport-bot
|
|||||||
yarn
|
yarn
|
||||||
```
|
```
|
||||||
|
|
||||||
Copy the sample `.env` file and add in your own variables
|
Copy the sample config file and add in the missing values.
|
||||||
```
|
```
|
||||||
cp .env.sample .env
|
cp sample.config.json config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Pull in the user-defined settings (if there are any).
|
||||||
|
```
|
||||||
|
yarn setup
|
||||||
```
|
```
|
||||||
|
|
||||||
Start the local server
|
Start the local server
|
||||||
|
|||||||
238
dist/bot.js
vendored
238
dist/bot.js
vendored
File diff suppressed because it is too large
Load Diff
45
dist/index.js
vendored
45
dist/index.js
vendored
@@ -2,43 +2,14 @@
|
|||||||
|
|
||||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||||
|
|
||||||
|
var _config = _interopRequireDefault(require("../config.json"));
|
||||||
|
|
||||||
var _bot = _interopRequireDefault(require("./bot"));
|
var _bot = _interopRequireDefault(require("./bot"));
|
||||||
|
|
||||||
require('dotenv').config();
|
const bot = new _bot.default(_config.default);
|
||||||
|
|
||||||
const ENCRYPTION_CONFIG = {
|
try {
|
||||||
algorithm: "m.megolm.v1.aes-sha2"
|
bot.start();
|
||||||
};
|
} catch (err) {
|
||||||
const KICK_REASON = "A facilitator has already joined this chat.";
|
console.log("Unable to start bot", err);
|
||||||
const BOT_ERROR_MESSAGE = "Something went wrong on our end, please restart the chat and try again.";
|
}
|
||||||
const MAX_RETRIES = 3;
|
|
||||||
const {
|
|
||||||
MATRIX_SERVER_URL,
|
|
||||||
BOT_USERNAME,
|
|
||||||
BOT_USERID,
|
|
||||||
BOT_PASSWORD,
|
|
||||||
BOT_DISPLAY_NAME,
|
|
||||||
FACILITATOR_ROOM_ID,
|
|
||||||
CAPTURE_TRANSCRIPTS,
|
|
||||||
CHAT_NOT_AVAILABLE_MESSAGE,
|
|
||||||
MAX_WAIT_TIME,
|
|
||||||
MAX_INACTIVE
|
|
||||||
} = process.env;
|
|
||||||
const botConfig = {
|
|
||||||
ENCRYPTION_CONFIG,
|
|
||||||
KICK_REASON,
|
|
||||||
BOT_ERROR_MESSAGE,
|
|
||||||
MAX_RETRIES,
|
|
||||||
MATRIX_SERVER_URL,
|
|
||||||
BOT_USERNAME,
|
|
||||||
BOT_USERID,
|
|
||||||
BOT_PASSWORD,
|
|
||||||
BOT_DISPLAY_NAME,
|
|
||||||
FACILITATOR_ROOM_ID,
|
|
||||||
CAPTURE_TRANSCRIPTS,
|
|
||||||
CHAT_NOT_AVAILABLE_MESSAGE,
|
|
||||||
MAX_WAIT_TIME,
|
|
||||||
MAX_INACTIVE
|
|
||||||
};
|
|
||||||
const bot = new _bot.default(botConfig);
|
|
||||||
bot.start();
|
|
||||||
54
dist/setup.js
vendored
Normal file
54
dist/setup.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
|
const config = require('../config.json');
|
||||||
|
|
||||||
|
const getSettings = async () => {
|
||||||
|
try {
|
||||||
|
const url = `${config.settingsEndpoint}?homeserver=${encodeURIComponent(config.matrixServerUrl)}`;
|
||||||
|
|
||||||
|
if (!config.matrixServerUrl) {
|
||||||
|
throw new Error("The matrix server url is not provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Fetching settings for ${config.matrixServerUrl}`);
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
const {
|
||||||
|
fields,
|
||||||
|
schedule = []
|
||||||
|
} = data;
|
||||||
|
return Object.entries(fields).reduce((settingsObj, [k, v]) => {
|
||||||
|
const [scope, key] = k.split('_');
|
||||||
|
|
||||||
|
if (scope === 'platform') {
|
||||||
|
settingsObj[key] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return settingsObj;
|
||||||
|
}, {});
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Error fetching settings", err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const writeConfig = async () => {
|
||||||
|
const settings = await getSettings();
|
||||||
|
|
||||||
|
if (!settings) {
|
||||||
|
return console.log('No settings to update');
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedSettings = Object.assign(config, settings);
|
||||||
|
fs.writeFile('config.json', JSON.stringify(updatedSettings, null, 2), function (err) {
|
||||||
|
if (err) return console.log("Error updating settings", err);
|
||||||
|
console.log(`Updated settings to config.json`);
|
||||||
|
console.log(updatedSettings);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
writeConfig();
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "private-safesupport-bot",
|
"name": "private-safesupport-bot",
|
||||||
"version": "2.0.0",
|
"version": "3.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": {
|
||||||
"develop": "nodemon --exec babel-node src/index.js",
|
"develop": "nodemon --exec babel-node src/index.js",
|
||||||
"build": "babel src -d dist",
|
"build": "babel src -d dist",
|
||||||
|
"setup": "node src/setup.js",
|
||||||
"start": "yarn build && node dist/index.js",
|
"start": "yarn build && node dist/index.js",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"matrix-js-sdk": "^6.2.1",
|
"matrix-js-sdk": "^6.2.1",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
"node-localstorage": "^2.1.5",
|
"node-localstorage": "^2.1.5",
|
||||||
"node-webcrypto-ossl": "^2.1.0",
|
"node-webcrypto-ossl": "^2.1.0",
|
||||||
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
|
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
|
||||||
|
|||||||
16
sample.config.json
Normal file
16
sample.config.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"matrixServerUrl": "",
|
||||||
|
"settingsEndpoint": "",
|
||||||
|
"facilitatorRoomId": "",
|
||||||
|
"kickReason": "A facilitator has already joined this chat.",
|
||||||
|
"botErrorMessage": "Something went wrong on our end, please restart the chat and try again.",
|
||||||
|
"botUserId": "",
|
||||||
|
"botUsername": "",
|
||||||
|
"botPassword": "",
|
||||||
|
"botDisplayName": "Help Bot",
|
||||||
|
"captureTranscripts": true,
|
||||||
|
"chatNotAvailableMessage": "The support chat is not available right now.",
|
||||||
|
"chatInactiveMessage": "This chat has been closed due to inactivity.",
|
||||||
|
"maxWaitTime": 180,
|
||||||
|
"maxInactiveTime": 3600
|
||||||
|
}
|
||||||
245
src/bot.js
245
src/bot.js
File diff suppressed because it is too large
Load Diff
47
src/index.js
47
src/index.js
@@ -1,42 +1,9 @@
|
|||||||
require('dotenv').config()
|
import config from '../config.json';
|
||||||
|
import OcrccBot from './bot';
|
||||||
|
|
||||||
const ENCRYPTION_CONFIG = { algorithm: "m.megolm.v1.aes-sha2" };
|
const bot = new OcrccBot(config);
|
||||||
const KICK_REASON = "A facilitator has already joined this chat.";
|
try {
|
||||||
const BOT_ERROR_MESSAGE =
|
bot.start();
|
||||||
"Something went wrong on our end, please restart the chat and try again.";
|
} catch(err) {
|
||||||
const MAX_RETRIES = 3;
|
console.log("Unable to start bot", err)
|
||||||
|
|
||||||
const {
|
|
||||||
MATRIX_SERVER_URL,
|
|
||||||
BOT_USERNAME,
|
|
||||||
BOT_USERID,
|
|
||||||
BOT_PASSWORD,
|
|
||||||
BOT_DISPLAY_NAME,
|
|
||||||
FACILITATOR_ROOM_ID,
|
|
||||||
CAPTURE_TRANSCRIPTS,
|
|
||||||
CHAT_NOT_AVAILABLE_MESSAGE,
|
|
||||||
MAX_WAIT_TIME,
|
|
||||||
MAX_INACTIVE,
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
const botConfig = {
|
|
||||||
ENCRYPTION_CONFIG,
|
|
||||||
KICK_REASON,
|
|
||||||
BOT_ERROR_MESSAGE,
|
|
||||||
MAX_RETRIES,
|
|
||||||
MATRIX_SERVER_URL,
|
|
||||||
BOT_USERNAME,
|
|
||||||
BOT_USERID,
|
|
||||||
BOT_PASSWORD,
|
|
||||||
BOT_DISPLAY_NAME,
|
|
||||||
FACILITATOR_ROOM_ID,
|
|
||||||
CAPTURE_TRANSCRIPTS,
|
|
||||||
CHAT_NOT_AVAILABLE_MESSAGE,
|
|
||||||
MAX_WAIT_TIME,
|
|
||||||
MAX_INACTIVE,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
import OcrccBot from './bot'
|
|
||||||
|
|
||||||
const bot = new OcrccBot(botConfig);
|
|
||||||
bot.start();
|
|
||||||
|
|||||||
50
src/setup.js
Normal file
50
src/setup.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const config = require('../config.json');
|
||||||
|
|
||||||
|
const getSettings = async () => {
|
||||||
|
try {
|
||||||
|
const url = `${config.settingsEndpoint}?homeserver=${encodeURIComponent(config.matrixServerUrl)}`;
|
||||||
|
|
||||||
|
if (!config.matrixServerUrl) {
|
||||||
|
throw new Error("The matrix server url is not provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Fetching settings for ${config.matrixServerUrl}`);
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
const { fields, schedule = [] } = data;
|
||||||
|
|
||||||
|
return Object.entries(fields).reduce(((settingsObj, [k,v]) => {
|
||||||
|
const [scope, key] = k.split('_');
|
||||||
|
|
||||||
|
if (scope === 'platform') {
|
||||||
|
settingsObj[key] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return settingsObj
|
||||||
|
}), {});
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Error fetching settings", err);
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const writeConfig = async () => {
|
||||||
|
const settings = await getSettings()
|
||||||
|
if (!settings) {
|
||||||
|
return console.log('No settings to update')
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedSettings = Object.assign(config, settings)
|
||||||
|
|
||||||
|
fs.writeFile('config.json', JSON.stringify(updatedSettings, null, 2), function (err) {
|
||||||
|
if (err) return console.log("Error updating settings", err);
|
||||||
|
console.log(`Updated settings to config.json`);
|
||||||
|
console.log(updatedSettings);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
writeConfig();
|
||||||
@@ -3954,6 +3954,11 @@ node-environment-flags@^1.0.5:
|
|||||||
object.getownpropertydescriptors "^2.0.3"
|
object.getownpropertydescriptors "^2.0.3"
|
||||||
semver "^5.7.0"
|
semver "^5.7.0"
|
||||||
|
|
||||||
|
node-fetch@^2.6.1:
|
||||||
|
version "2.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||||
|
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||||
|
|
||||||
node-int64@^0.4.0:
|
node-int64@^0.4.0:
|
||||||
version "0.4.0"
|
version "0.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
|
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
|
||||||
|
|||||||
Reference in New Issue
Block a user