Compare commits
64 Commits
v1.1.3
...
disable-en
| Author | SHA1 | Date | |
|---|---|---|---|
| fadc9b642f | |||
| 758af0c29b | |||
|
|
eae9c737d7 | ||
|
|
b82ba3da3f | ||
|
|
0873dbd020 | ||
|
|
977fe1afa5 | ||
|
|
bf29508e8c | ||
|
|
40e968fcee | ||
|
|
c45182a574 | ||
|
|
819d9b8ebb | ||
|
|
4491b681c5 | ||
|
|
dcd7718f8f | ||
|
|
c8c42e9086 | ||
|
|
004f88d5cd | ||
|
|
22c17d314d | ||
|
|
2b3e46ad53 | ||
|
|
43c5afd011 | ||
|
|
9432e4d86f | ||
|
|
de4106c093 | ||
|
|
ee30b14cba | ||
|
|
80c00149d2 | ||
|
|
a2a48771e1 | ||
|
|
7bd6cf2466 | ||
|
|
ac9247fecb | ||
|
|
8439a1d100 | ||
|
|
b709245b46 | ||
|
|
52e30336ad | ||
|
|
bee884c52f | ||
|
|
2ffa63d583 | ||
|
|
a0d08f8f88 | ||
|
|
09cc934fbd | ||
|
|
5a0ed5d36d | ||
|
|
dbbe188adc | ||
|
|
91bec23c48 | ||
|
|
90815f361a | ||
|
|
4f0abfed09 | ||
|
|
ad28e4acc5 | ||
|
|
dcfbf8ae02 | ||
|
|
b02ee6282a | ||
|
|
3107cf6904 | ||
|
|
0fcb7e6e07 | ||
|
|
c80e3269c3 | ||
|
|
5ed83271d9 | ||
|
|
706791cc38 | ||
|
|
181a4da221 | ||
|
|
46868b141a | ||
|
|
247bc3e2ba | ||
|
|
29b86e4190 | ||
|
|
716f61b183 | ||
|
|
516a1e0fbd | ||
|
|
80ecf98be1 | ||
|
|
f0b43743f7 | ||
|
|
5252321f56 | ||
|
|
93135daaa8 | ||
|
|
f27ebb3c71 | ||
|
|
7d5ad29b60 | ||
|
|
27916c9eef | ||
|
|
b5fb1d0a8b | ||
|
|
6070926b89 | ||
|
|
8427e82c9d | ||
|
|
f262c9df0f | ||
|
|
b9f822d308 | ||
|
|
0cb939ff7d | ||
|
|
057789e741 |
@@ -1,48 +0,0 @@
|
|||||||
version: 2
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
docker:
|
|
||||||
- image: node:10
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- run:
|
|
||||||
name: dep install
|
|
||||||
command: npm install
|
|
||||||
- run:
|
|
||||||
name: install codecov
|
|
||||||
command: npm install -g codecov
|
|
||||||
- run:
|
|
||||||
name: test
|
|
||||||
command: npm test && codecov
|
|
||||||
- run:
|
|
||||||
name: build
|
|
||||||
command: |
|
|
||||||
npm run build
|
|
||||||
[ -f ./dist/index.html ] || exit 1
|
|
||||||
[ -f ./dist/blank.html ] || exit 1
|
|
||||||
[ -f ./dist/widget.js ] || exit 1
|
|
||||||
[ -f ./dist/bookmarklet.js ] || exit 1
|
|
||||||
- run:
|
|
||||||
name: npm start works
|
|
||||||
command: |
|
|
||||||
npm run start &
|
|
||||||
pid=$!
|
|
||||||
sleep 10s
|
|
||||||
ps $pid
|
|
||||||
- run:
|
|
||||||
name: deploy
|
|
||||||
command: |
|
|
||||||
if [ "$CIRCLE_BRANCH" = "master" ]; then
|
|
||||||
git config --global user.email $GH_EMAIL
|
|
||||||
git config --global user.name $GH_NAME
|
|
||||||
npm run deploy
|
|
||||||
fi
|
|
||||||
|
|
||||||
workflows:
|
|
||||||
version: 2
|
|
||||||
build-deploy:
|
|
||||||
jobs:
|
|
||||||
- build:
|
|
||||||
filters:
|
|
||||||
branches:
|
|
||||||
ignore: gh-pages
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import '@storybook/addon-actions/register';
|
|
||||||
import '@storybook/addon-links/register';
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { configure } from '@storybook/react';
|
|
||||||
|
|
||||||
// automatically import all files ending in *.stories.js
|
|
||||||
const req = require.context('../stories', true, /\.stories\.js$/);
|
|
||||||
function loadStories() {
|
|
||||||
req.keys().forEach(filename => req(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
configure(loadStories, module);
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.scss$/,
|
|
||||||
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
||||||
include: path.resolve(__dirname, '../'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
26
README.md
@@ -10,11 +10,11 @@ Built on:
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```
|
```
|
||||||
<script src="https://unpkg.com/safesupport-chatbox" type="text/javascript"></script>
|
<script src="https://safesupport.chat/chatbox.js" type="text/javascript"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.rhok.space',
|
matrixServerUrl: 'https://matrix-client.matrix.org',
|
||||||
botId: '@help-bot:rhok.space',
|
botId: '@your-help-bot:matrix.org',
|
||||||
roomName: 'Support Chat',
|
roomName: 'Support Chat',
|
||||||
termsUrl: 'https://tosdr.org/',
|
termsUrl: 'https://tosdr.org/',
|
||||||
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
||||||
@@ -23,6 +23,7 @@ Built on:
|
|||||||
exitMessage: 'The chat is closed. You may close this window.',
|
exitMessage: 'The chat is closed. You may close this window.',
|
||||||
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
||||||
anonymousDisplayName: 'Anonymous',
|
anonymousDisplayName: 'Anonymous',
|
||||||
|
enableEncryption: 'yes',
|
||||||
}
|
}
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
@@ -31,8 +32,8 @@ Built on:
|
|||||||
Options:
|
Options:
|
||||||
| Name | Description | Default
|
| Name | Description | Default
|
||||||
| ----------- | ----------- | --------- |
|
| ----------- | ----------- | --------- |
|
||||||
| `matrixServerUrl` (required) | URL for the Matrix homeserver you want to connect to | `https://matrix.rhok.space` |
|
| `matrixServerUrl` (required) | URL for the Matrix homeserver you want to connect to | `https://matrix-client.matrix.org` |
|
||||||
| `botId` (required) | User ID for the bot account that handles invites | `@help-bot:rhok.space` |
|
| `botId` (required) | User ID for the bot account that handles invites | null |
|
||||||
| `introMessage` (optional) | First message the user sees before agreeing to the Terms of Use | `This chat application does not collect any of your personal data or any data from your use of this service.` |
|
| `introMessage` (optional) | First message the user sees before agreeing to the Terms of Use | `This chat application does not collect any of your personal data or any data from your use of this service.` |
|
||||||
| `termsUrl` (optional) | URL for the Terms of Use for the chat service | `https://tosdr.org/` |
|
| `termsUrl` (optional) | URL for the Terms of Use for the chat service | `https://tosdr.org/` |
|
||||||
| `roomName` (optional) | Name of the chatroom generated in Riot | 'Support Chat' |
|
| `roomName` (optional) | Name of the chatroom generated in Riot | 'Support Chat' |
|
||||||
@@ -40,7 +41,14 @@ Options:
|
|||||||
| `confirmationMessage` (optional) | Text to show to ask for agreement to continue | `Waiting for a facilitator to join the chat...` |
|
| `confirmationMessage` (optional) | Text to show to ask for agreement to continue | `Waiting for a facilitator to join the chat...` |
|
||||||
| `exitMessage` (optional) | Text to show if the user rejects the Terms of Use. | `The chat is closed. You may close this window.` |
|
| `exitMessage` (optional) | Text to show if the user rejects the Terms of Use. | `The chat is closed. You may close this window.` |
|
||||||
| `anonymousDisplayName` (optional) | The display name for the chat user. | `Anonymous` |
|
| `anonymousDisplayName` (optional) | The display name for the chat user. | `Anonymous` |
|
||||||
| `chatUnavailableMessage` (optional) | Text to show if no-one is available to respond | `The chat service is not available right now. Please try again later.` |
|
| `chatUnavailableMessage` (optional) | Text to show on error or if the service is otherwise unavailable | `The chat service is not available right now. Please try again later.` |
|
||||||
|
| `waitMessage` (optional) | Text to show if there is at least one facilitator online but they do not respond right away | `Please be patient, our online facilitators are currently responding to other support requests.` |
|
||||||
|
| `chatOfflineMessage` (optional) | Text to show if there is no-one online respond | `All of the chat facilitators are currently offline.` |
|
||||||
|
| `size` (optional) | The size of the start button. Can be 'small' or 'large' | `large` |
|
||||||
|
| `position` (optional) | The position of the start button. Can be 'top left', 'top right', 'bottom left', 'bottom right'. | `bottom right` |
|
||||||
|
| `waitInterval` (optional) | The interval (in ms) at which the bot sends the wait message | 120000 |
|
||||||
|
| `enableEncryption` (optional) | if set to "yes" then the chat will be encrypted by default | `yes` |
|
||||||
|
|
||||||
|
|
||||||
## Feature list
|
## Feature list
|
||||||
|
|
||||||
@@ -68,7 +76,7 @@ This chatbox is meant to be used with a bot account that handles a number of fun
|
|||||||
|
|
||||||
The bot account is invited to the chatroom when a support request is initiated.
|
The bot account is invited to the chatroom when a support request is initiated.
|
||||||
|
|
||||||
You can find the code for the bot at [safesupport-bot](https://github.com/nomadic-labs/safesupport-bot).
|
You can find the code for the bot at [ocrcc-bot](https://github.com/Safe-Support-Chat/ocrcc-bot).
|
||||||
|
|
||||||
## Bookmarklet
|
## Bookmarklet
|
||||||
|
|
||||||
@@ -80,11 +88,11 @@ You can try this out on the [live demo](https://nomadic-labs.github.io/safesuppo
|
|||||||
|
|
||||||
Clone the project:
|
Clone the project:
|
||||||
```
|
```
|
||||||
git clone https://github.com/nomadic-labs/safesupport-chatbox.git
|
git clone https://git.umycode.com/dave/ocrcc-chatbox.git
|
||||||
```
|
```
|
||||||
Install the dependencies:
|
Install the dependencies:
|
||||||
```
|
```
|
||||||
cd safesupport-chatbox
|
cd ocrcc-chatbox
|
||||||
yarn
|
yarn
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,13 @@ export const mockInitCrypto = jest.fn()
|
|||||||
export const mockStartClient = jest.fn(() => {
|
export const mockStartClient = jest.fn(() => {
|
||||||
return Promise.resolve('value');
|
return Promise.resolve('value');
|
||||||
});
|
});
|
||||||
export const mockOnce = jest.fn()
|
export const mockOnce = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation((event, callback) => {
|
||||||
|
if (event === 'sync') {
|
||||||
|
callback('PREPARED')
|
||||||
|
}
|
||||||
|
})
|
||||||
export const mockStopClient = jest.fn(() => {
|
export const mockStopClient = jest.fn(() => {
|
||||||
return Promise.resolve('value');
|
return Promise.resolve('value');
|
||||||
});
|
});
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.3 MiB |
18
dist/bookmarklet.js
vendored
18
dist/chatbox.js
vendored
36
dist/component.js
vendored
Normal file
14
dist/index.html
vendored
@@ -13,18 +13,8 @@
|
|||||||
<script src="./chatbox.js"></script>
|
<script src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.safesupport.chat',
|
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||||
botId: '@help-bot:safesupport.chat',
|
};
|
||||||
roomName: 'Support Chat',
|
|
||||||
termsUrl: 'https://tosdr.org/',
|
|
||||||
introMessage: "This chat application does not collect any of your personal data or any data from your use of this service.",
|
|
||||||
agreementMessage: 'Do you want to continue?',
|
|
||||||
confirmationMessage: 'Waiting for a facilitator to join the chat...',
|
|
||||||
exitMessage: 'The chat is closed. You may close this window.',
|
|
||||||
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
|
||||||
anonymousDisplayName: 'Anonymous',
|
|
||||||
}
|
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
BIN
dist/olm.wasm
vendored
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 176 KiB |
BIN
docs/confirm.png
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 230 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 296 KiB |
|
Before Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 42 KiB |
BIN
docs/verify.png
|
Before Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 97 KiB |
23
package.json
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "safesupport-chatbox",
|
"name": "ocrcc-chatbox",
|
||||||
"version": "1.1.3",
|
"version": "2.3.2",
|
||||||
"description": "A secure and private embeddable chatbox that connects to Riot",
|
"description": "A secure and private embeddable chatbox that connects to Matrix",
|
||||||
"main": "dist/chatbox.js",
|
"main": "dist/chatbox.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "NODE_ENV=production webpack-cli --mode production",
|
"build": "NODE_ENV=production webpack-cli --mode production",
|
||||||
|
"build:profile": "webpack --mode production --config webpack.config.profile.js",
|
||||||
"start": "webpack-dev-server",
|
"start": "webpack-dev-server",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test-update-snapshots": "jest --updateSnapshot",
|
"test-update-snapshots": "jest --updateSnapshot",
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
"author": "Nomadic Labs <sharon@nomadiclabs.ca",
|
"author": "Nomadic Labs <sharon@nomadiclabs.ca",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.7.7",
|
"@babel/core": "^7.10.3",
|
||||||
"@babel/plugin-proposal-class-properties": "7.7.4",
|
"@babel/plugin-proposal-class-properties": "7.7.4",
|
||||||
"@babel/plugin-proposal-decorators": "7.7.4",
|
"@babel/plugin-proposal-decorators": "7.7.4",
|
||||||
"@babel/plugin-proposal-export-namespace-from": "7.7.4",
|
"@babel/plugin-proposal-export-namespace-from": "7.7.4",
|
||||||
@@ -89,10 +90,6 @@
|
|||||||
"@babel/plugin-transform-runtime": "^7.9.0",
|
"@babel/plugin-transform-runtime": "^7.9.0",
|
||||||
"@babel/preset-env": "^7.9.0",
|
"@babel/preset-env": "^7.9.0",
|
||||||
"@babel/preset-react": "^7.9.4",
|
"@babel/preset-react": "^7.9.4",
|
||||||
"@storybook/addon-actions": "5.2.8",
|
|
||||||
"@storybook/addon-links": "5.2.8",
|
|
||||||
"@storybook/addons": "5.2.8",
|
|
||||||
"@storybook/react": "5.2.8",
|
|
||||||
"autoprefixer": "^9.7.5",
|
"autoprefixer": "^9.7.5",
|
||||||
"babel-core": "7.0.0-bridge.0",
|
"babel-core": "7.0.0-bridge.0",
|
||||||
"babel-eslint": "10.0.3",
|
"babel-eslint": "10.0.3",
|
||||||
@@ -121,16 +118,20 @@
|
|||||||
"node-sass": "^4.13.1",
|
"node-sass": "^4.13.1",
|
||||||
"postcss-increase-specificity": "0.6.0",
|
"postcss-increase-specificity": "0.6.0",
|
||||||
"postcss-loader": "3.0.0",
|
"postcss-loader": "3.0.0",
|
||||||
|
"react": "^16.8.6",
|
||||||
|
"react-dom": "^16.8.6",
|
||||||
"sass-loader": "8.0.0",
|
"sass-loader": "8.0.0",
|
||||||
"style-loader": "1.1.2",
|
"style-loader": "1.1.2",
|
||||||
"wait-for-expect": "^3.0.2",
|
"wait-for-expect": "^3.0.2",
|
||||||
"webpack": "4.41.5",
|
"webpack": "4.41.5",
|
||||||
|
"webpack-bundle-analyzer": "^3.8.0",
|
||||||
"webpack-cli": "3.3.10",
|
"webpack-cli": "3.3.10",
|
||||||
"webpack-dev-server": "3.10.1",
|
"webpack-dev-server": "3.10.1",
|
||||||
"webpack-obfuscator": "0.22.0",
|
"webpack-obfuscator": "0.22.0",
|
||||||
"webpack-serve": "3.2.0"
|
"webpack-serve": "3.2.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"airtable": "^0.10.0",
|
||||||
"browser-encrypt-attachment": "^0.3.0",
|
"browser-encrypt-attachment": "^0.3.0",
|
||||||
"emoji-picker-react": "^3.1.3",
|
"emoji-picker-react": "^3.1.3",
|
||||||
"isomorphic-fetch": "^2.2.1",
|
"isomorphic-fetch": "^2.2.1",
|
||||||
@@ -139,11 +140,13 @@
|
|||||||
"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",
|
||||||
"prop-types": "^15.6.2",
|
"prop-types": "^15.6.2",
|
||||||
"react": "^16.8.6",
|
|
||||||
"react-dom": "^16.8.6",
|
|
||||||
"react-onclickoutside": "^6.9.0",
|
"react-onclickoutside": "^6.9.0",
|
||||||
"react-test-renderer": "^16.13.0",
|
"react-test-renderer": "^16.13.0",
|
||||||
"react-transition-group": "^4.0.0",
|
"react-transition-group": "^4.0.0",
|
||||||
"uuidv4": "^6.0.2"
|
"uuidv4": "^6.0.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.6",
|
||||||
|
"react-dom": "^16.8.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,8 @@
|
|||||||
<script src="./chatbox.js"></script>
|
<script src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.safesupport.chat',
|
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||||
botId: '@help-bot:safesupport.chat',
|
};
|
||||||
roomName: 'Support Chat',
|
|
||||||
termsUrl: 'https://tosdr.org/',
|
|
||||||
introMessage: "This chat application does not collect any of your personal data or any data from your use of this service.",
|
|
||||||
agreementMessage: 'Do you want to continue?',
|
|
||||||
confirmationMessage: 'Waiting for a facilitator to join the chat...',
|
|
||||||
exitMessage: 'The chat is closed. You may close this window.',
|
|
||||||
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
|
||||||
anonymousDisplayName: 'Anonymous',
|
|
||||||
}
|
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
BIN
public/olm.wasm
94
src/components/ChatboxWithSettings.js
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import Chatbox from './chatbox';
|
||||||
|
|
||||||
|
const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest }) => {
|
||||||
|
const [settings, setSettings] = useState({});
|
||||||
|
const [shifts, setShifts] = useState();
|
||||||
|
const [isAvailable, setAvailability] = useState(true);
|
||||||
|
|
||||||
|
const getSettings = async () => {
|
||||||
|
const url = `${settingsEndpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
const { fields, schedule = [] } = data;
|
||||||
|
|
||||||
|
if (!fields) {
|
||||||
|
const props = {
|
||||||
|
...rest,
|
||||||
|
enabled: true,
|
||||||
|
isAvailable: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
return setSettings(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
const settingsObj = {};
|
||||||
|
|
||||||
|
setShifts(schedule);
|
||||||
|
|
||||||
|
Object.entries(fields).forEach(([k, v]) => {
|
||||||
|
const [scope, key] = k.split('_');
|
||||||
|
|
||||||
|
if (scope === 'web') {
|
||||||
|
settingsObj[key] = v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!settingsObj.enabled) {
|
||||||
|
settingsObj.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return setSettings(settingsObj);
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkSchedule = () => {
|
||||||
|
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const weekday = weekdays[now.getDay()];
|
||||||
|
const hours = now.getHours();
|
||||||
|
const minutes = now.getMinutes();
|
||||||
|
|
||||||
|
shifts.map(async (shift) => {
|
||||||
|
const [startHours, startMinutes] = shift.start.split(':').map((t) => Number(t));
|
||||||
|
const [endHours, endMinutes] = shift.end.split(':').map((t) => Number(t));
|
||||||
|
if (
|
||||||
|
shift.service === 'web'
|
||||||
|
&& shift.weekday === weekday
|
||||||
|
&& ((startHours < hours) || (startHours === hours && startMinutes <= minutes))
|
||||||
|
&& ((endHours > hours) || (endHours === hours && endMinutes > minutes))
|
||||||
|
) {
|
||||||
|
setAvailability(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (settingsEndpoint) {
|
||||||
|
getSettings();
|
||||||
|
}
|
||||||
|
}, [settingsEndpoint]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (shifts && shifts.length > 0) {
|
||||||
|
checkSchedule();
|
||||||
|
}
|
||||||
|
}, [shifts]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
/* eslint-disable react/jsx-props-no-spreading */
|
||||||
|
<Chatbox matrixServerUrl={matrixServerUrl} isAvailable={isAvailable} {...settings} {...rest} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ChatboxWithSettings.propTypes = {
|
||||||
|
matrixServerUrl: PropTypes.string.isRequired,
|
||||||
|
settingsEndpoint: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
ChatboxWithSettings.defaultProps = {
|
||||||
|
settingsEndpoint: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChatboxWithSettings;
|
||||||
@@ -26,14 +26,56 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@keyframes slideInDown {
|
||||||
|
from {
|
||||||
|
transform: translate3d(0, -100%, 0);
|
||||||
|
display: inherit;
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideOutUp {
|
||||||
|
from {
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
display: none;
|
||||||
|
visibility: hidden;
|
||||||
|
transform: translate3d(0, -100%, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.docked-widget {
|
.docked-widget {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 10px;
|
|
||||||
right: 10px;
|
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
width: 400px;
|
|
||||||
max-width: 100vw;
|
max-width: 100vw;
|
||||||
font-size: $base-font-size;
|
font-size: $base-font-size;
|
||||||
|
|
||||||
|
&.size-large {
|
||||||
|
width: 400px;
|
||||||
|
|
||||||
|
.dock {
|
||||||
|
width: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.size-small {
|
||||||
|
#open-chatbox-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
margin-left: 0.5em;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dock {
|
.dock {
|
||||||
@@ -41,7 +83,6 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
width: 400px;
|
|
||||||
max-width: calc(100vw - 10px);
|
max-width: calc(100vw - 10px);
|
||||||
color: $white;
|
color: $white;
|
||||||
font-family: $theme-font;
|
font-family: $theme-font;
|
||||||
@@ -53,6 +94,7 @@
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|
||||||
|
|
||||||
#open-chatbox-label {
|
#open-chatbox-label {
|
||||||
background: $theme-color;
|
background: $theme-color;
|
||||||
padding: 0.75em;
|
padding: 0.75em;
|
||||||
@@ -99,11 +141,16 @@
|
|||||||
width: 400px;
|
width: 400px;
|
||||||
max-width: calc(100vw - 10px);
|
max-width: calc(100vw - 10px);
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
|
margin: 0;
|
||||||
animation-duration: 0.2s;
|
animation-duration: 0.2s;
|
||||||
animation-fill-mode: forwards;
|
animation-fill-mode: forwards;
|
||||||
|
|
||||||
&-entering {
|
&-entering {
|
||||||
animation-name: slideInUp;
|
animation-name: slideInUp;
|
||||||
|
|
||||||
|
&.position-top {
|
||||||
|
animation-name: slideInDown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&-entered {
|
&-entered {
|
||||||
display: inherit;
|
display: inherit;
|
||||||
@@ -111,6 +158,10 @@
|
|||||||
}
|
}
|
||||||
&-exiting {
|
&-exiting {
|
||||||
animation-name: slideOutDown;
|
animation-name: slideOutDown;
|
||||||
|
|
||||||
|
&.position-top {
|
||||||
|
animation-name: slideOutUp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&-exited {
|
&-exited {
|
||||||
display: none;
|
display: none;
|
||||||
@@ -520,6 +571,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 420px){
|
@media screen and (max-width: 420px){
|
||||||
|
.docked-widget {
|
||||||
|
.dock {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
#open-chatbox-label {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.docked-widget {
|
.docked-widget {
|
||||||
right: 0;
|
right: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
@@ -68,7 +68,6 @@
|
|||||||
.message {
|
.message {
|
||||||
&.from-bot {
|
&.from-bot {
|
||||||
color: transparentize($light-text-color, 0.3);
|
color: transparentize($light-text-color, 0.3);
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.from-me {
|
&.from-me {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import waitForExpect from 'wait-for-expect'
|
|||||||
config.disabled = true
|
config.disabled = true
|
||||||
|
|
||||||
var testConfig = {
|
var testConfig = {
|
||||||
matrixServerUrl: 'https://matrix.rhok.space',
|
matrixServerUrl: 'https://test.matrix.tld',
|
||||||
botId: '@help-bot:rhok.space',
|
botId: '@help-bot:matrix.tld',
|
||||||
roomName: 'Support Chat',
|
roomName: 'Support Chat',
|
||||||
termsUrl: 'https://tosdr.org/',
|
termsUrl: 'https://tosdr.org/',
|
||||||
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
introMessage: 'This chat application does not collect any of your personal data or any data from your use of this service.',
|
||||||
@@ -115,9 +115,7 @@ describe('Chatbox', () => {
|
|||||||
expect(createClient).toHaveBeenCalled()
|
expect(createClient).toHaveBeenCalled()
|
||||||
expect(mockInitCrypto).toHaveBeenCalled()
|
expect(mockInitCrypto).toHaveBeenCalled()
|
||||||
expect(mockStartClient).toHaveBeenCalled()
|
expect(mockStartClient).toHaveBeenCalled()
|
||||||
expect(mockCreateRoom).toHaveBeenCalled()
|
expect(mockOnce).toHaveBeenCalled()
|
||||||
expect(mockSetPowerLevel).toHaveBeenCalled()
|
|
||||||
expect(mockOn).toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('rejecting terms should not start chat', async () => {
|
test('rejecting terms should not start chat', async () => {
|
||||||
@@ -146,6 +144,10 @@ describe('Chatbox', () => {
|
|||||||
|
|
||||||
acceptButton.simulate('click')
|
acceptButton.simulate('click')
|
||||||
|
|
||||||
|
await waitForExpect(() => {
|
||||||
|
expect(mockOnce).toHaveBeenCalled()
|
||||||
|
});
|
||||||
|
|
||||||
await waitForExpect(() => {
|
await waitForExpect(() => {
|
||||||
expect(mockCreateRoom).toHaveBeenCalled()
|
expect(mockCreateRoom).toHaveBeenCalled()
|
||||||
});
|
});
|
||||||
@@ -169,7 +171,7 @@ describe('Chatbox', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('decryption failure should lead to a new unencrypted chat', async () => {
|
test('decryption failure should handle the message event and save the event ID in state', async () => {
|
||||||
const chatbox = mount(<Chatbox {...testConfig} />)
|
const chatbox = mount(<Chatbox {...testConfig} />)
|
||||||
const dock = chatbox.find('button.dock')
|
const dock = chatbox.find('button.dock')
|
||||||
const instance = chatbox.instance()
|
const instance = chatbox.instance()
|
||||||
@@ -183,25 +185,25 @@ describe('Chatbox', () => {
|
|||||||
acceptButton.simulate('click')
|
acceptButton.simulate('click')
|
||||||
|
|
||||||
await waitForExpect(() => {
|
await waitForExpect(() => {
|
||||||
expect(mockCreateRoom).toHaveBeenCalled()
|
expect(mockOnce).toHaveBeenCalled()
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(instance, 'initializeUnencryptedChat')
|
jest.spyOn(instance, 'handleMessageEvent')
|
||||||
instance.handleDecryptionError()
|
|
||||||
|
instance.handleDecryptionError({
|
||||||
|
getId: () => 'test_event_id',
|
||||||
|
getType: () => 'm.message',
|
||||||
|
getSender: () => 'sender',
|
||||||
|
getRoomId: () => 'room id',
|
||||||
|
getContent: () => ({ body: 'test msg' }),
|
||||||
|
getTs: () => '123',
|
||||||
|
})
|
||||||
|
|
||||||
await waitForExpect(() => {
|
await waitForExpect(() => {
|
||||||
expect(mockLeave).toHaveBeenCalled()
|
expect(instance.handleMessageEvent).toHaveBeenCalled()
|
||||||
});
|
})
|
||||||
|
|
||||||
await waitForExpect(() => {
|
expect(chatbox.state().decryptionErrors).toEqual({ 'test_event_id': true })
|
||||||
expect(mockStopClient).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
|
|
||||||
await waitForExpect(() => {
|
|
||||||
expect(mockClearStores).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(instance.initializeUnencryptedChat).toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('creating an unencrypted chat', async () => {
|
test('creating an unencrypted chat', async () => {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import React from "react"
|
import React, { Fragment } from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
|
|
||||||
const Dock = ({ handleToggleOpen }) => {
|
const Dock = ({ handleToggleOpen, size, label }) => {
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -11,10 +10,19 @@ const Dock = ({ handleToggleOpen }) => {
|
|||||||
onKeyPress={handleToggleOpen}
|
onKeyPress={handleToggleOpen}
|
||||||
aria-labelledby="open-chatbox-label"
|
aria-labelledby="open-chatbox-label"
|
||||||
>
|
>
|
||||||
<div id="open-chatbox-label">Start a new chat</div>
|
{
|
||||||
<div className="label-icon">
|
size === 'small' ?
|
||||||
<div className={`btn-icon`} aria-label={`Open support chat window`}>+</div>
|
<div id="open-chatbox-label">
|
||||||
</div>
|
<span>{label}</span><span className="icon">+</span>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<Fragment>
|
||||||
|
<div id="open-chatbox-label">{label}</div>
|
||||||
|
<div className="label-icon">
|
||||||
|
<div className={`btn-icon`} aria-label={`Open support chat window`}>+</div>
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
}
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
@import "variables";
|
#safesupport {
|
||||||
@import "loader";
|
@import "variables";
|
||||||
@import "chat";
|
@import "loader";
|
||||||
@import "dark_mode";
|
@import "chat";
|
||||||
|
@import "dark_mode";
|
||||||
|
}
|
||||||
41
src/defaultConfig.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
const DEFAULT_TERMS_URL = 'https://tosdr.org/';
|
||||||
|
const DEFAULT_ROOM_NAME = 'Support Chat';
|
||||||
|
const DEFAULT_INTRO_MESSAGE = 'This chat application does not collect any of your personal data or any data from your use of this service.';
|
||||||
|
const DEFAULT_AGREEMENT_MESSAGE = 'Do you want to continue?';
|
||||||
|
const DEFAULT_CONFIRMATION_MESSAGE = 'Waiting for a facilitator to join the chat...';
|
||||||
|
const DEFAULT_EXIT_MESSAGE = 'The chat is closed. You may close this window.';
|
||||||
|
const DEFAULT_DISPLAY_NAME = 'Anonymous';
|
||||||
|
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = 'The chat service is not available right now. Please try again later.';
|
||||||
|
const DEFAULT_CHAT_OFFLINE_MESSAGE = 'All of the chat facilitators are currently offline.';
|
||||||
|
const DEFAULT_WAIT_MESSAGE = 'Please be patient, our online facilitators are currently responding to other support requests.';
|
||||||
|
const DEFAULT_ENCRYPTION_DISABLED = false;
|
||||||
|
const DEFAULT_POSITION = 'bottom right';
|
||||||
|
const DEFAULT_SIZE = 'large';
|
||||||
|
const DEFAULT_WAIT_INTERVAL_MS = 120000; // 2 minutes
|
||||||
|
const DEFAULT_DOCK_LABEL = 'Start a new chat';
|
||||||
|
const DEFAULT_ENABLED = true;
|
||||||
|
const DEFAULT_AVAILABLE = true;
|
||||||
|
const DEFAULT_ENCRYPTION = 'yes';
|
||||||
|
|
||||||
|
const defaultConfig = {
|
||||||
|
termsUrl: DEFAULT_TERMS_URL,
|
||||||
|
roomName: DEFAULT_ROOM_NAME,
|
||||||
|
introMessage: DEFAULT_INTRO_MESSAGE,
|
||||||
|
agreementMessage: DEFAULT_AGREEMENT_MESSAGE,
|
||||||
|
confirmationMessage: DEFAULT_CONFIRMATION_MESSAGE,
|
||||||
|
exitMessage: DEFAULT_EXIT_MESSAGE,
|
||||||
|
displayName: DEFAULT_DISPLAY_NAME,
|
||||||
|
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
|
||||||
|
waitMessage: DEFAULT_WAIT_MESSAGE,
|
||||||
|
enableEncryption: DEFAULT_ENCRYPTION,
|
||||||
|
chatOfflineMessage: DEFAULT_CHAT_OFFLINE_MESSAGE,
|
||||||
|
isEncryptionDisabled: DEFAULT_ENCRYPTION_DISABLED,
|
||||||
|
position: DEFAULT_POSITION,
|
||||||
|
size: DEFAULT_SIZE,
|
||||||
|
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
||||||
|
dockLabel: DEFAULT_DOCK_LABEL,
|
||||||
|
enabled: DEFAULT_ENABLED,
|
||||||
|
isAvailable: DEFAULT_AVAILABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defaultConfig;
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
import EmbeddableChatbox from './embeddable-chatbox';
|
import EmbeddableChatbox from './embeddable-chatbox';
|
||||||
|
import defaultConfig from '../defaultConfig';
|
||||||
|
|
||||||
const config = {
|
const config = defaultConfig;
|
||||||
matrixServerUrl: 'https://matrix.safesupport.chat',
|
|
||||||
botId: '@help-bot:safesupport.chat',
|
|
||||||
roomName: 'Support Chat',
|
|
||||||
termsUrl: 'https://tosdr.org/',
|
|
||||||
introMessage: "This chat application does not collect any of your personal data or any data from your use of this service.",
|
|
||||||
agreementMessage: 'Do you want to continue?',
|
|
||||||
confirmationMessage: 'Waiting for a facilitator to join the chat...',
|
|
||||||
exitMessage: 'The chat is closed. You may close this window.',
|
|
||||||
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
|
|
||||||
anonymousDisplayName: 'Anonymous',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function bookmarklet() {
|
export default function bookmarklet() {
|
||||||
if (window.EmbeddableChatbox) {
|
if (window.EmbeddableChatbox) {
|
||||||
|
|||||||
3
src/outputs/component.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import Chatbox from '../components/chatbox';
|
||||||
|
|
||||||
|
export default Chatbox;
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import Chatbox from '../components/chatbox';
|
import ChatboxWithSettings from '../components/ChatboxWithSettings';
|
||||||
import '../../vendor/cleanslate.css';
|
import '../../vendor/cleanslate.css';
|
||||||
|
|
||||||
export default class EmbeddableChatbox {
|
export default class EmbeddableChatbox {
|
||||||
static el;
|
static el;
|
||||||
|
|
||||||
static mount({ parentElement = null, ...props } = {}) {
|
static mount({ parentElement = null, ...props } = {}) {
|
||||||
const component = <Chatbox {...props} />; // eslint-disable-line
|
const component = <ChatboxWithSettings {...props} />; // eslint-disable-line
|
||||||
|
|
||||||
|
|
||||||
function doRender() {
|
function doRender() {
|
||||||
if (EmbeddableChatbox.el) {
|
if (EmbeddableChatbox.el) {
|
||||||
|
|||||||
3
src/setupTests.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { configure } from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
configure({ adapter: new Adapter() });
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { storiesOf } from '@storybook/react'
|
|
||||||
import Widget from '../src/components/widget'
|
|
||||||
|
|
||||||
storiesOf(`Widget`)
|
|
||||||
.add(`default`, () => <Widget />)
|
|
||||||
@@ -94,4 +94,29 @@ module.exports = [{
|
|||||||
publicPath: '/',
|
publicPath: '/',
|
||||||
filename: 'bookmarklet.js',
|
filename: 'bookmarklet.js',
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
...defaultConfig,
|
||||||
|
entry: './src/outputs/component.js',
|
||||||
|
output: {
|
||||||
|
path: distDir,
|
||||||
|
publicPath: '/',
|
||||||
|
filename: 'component.js',
|
||||||
|
library: 'Chatbox',
|
||||||
|
libraryExport: 'default',
|
||||||
|
libraryTarget: 'commonjs2',
|
||||||
|
},
|
||||||
|
externals: {
|
||||||
|
react: {
|
||||||
|
commonjs: "react",
|
||||||
|
commonjs2: "react",
|
||||||
|
amd: "React",
|
||||||
|
root: "React"
|
||||||
|
},
|
||||||
|
"react-dom": {
|
||||||
|
commonjs: "react-dom",
|
||||||
|
commonjs2: "react-dom",
|
||||||
|
amd: "ReactDOM",
|
||||||
|
root: "ReactDOM"
|
||||||
|
}
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|||||||
7
webpack.config.profile.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const config = require('./webpack.config');
|
||||||
|
|
||||||
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||||
|
|
||||||
|
config[0].plugins = config[0].plugins.concat([new BundleAnalyzerPlugin({ analyzerPort: 5555 })]);
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||