[mirotalk] - add Slack integration
This commit is contained in:
@@ -35,5 +35,14 @@ SENTRY_ENABLED=true|false
|
||||
SENTRY_DSN=YourClientKeyDSN
|
||||
SENTRY_TRACES_SAMPLE_RATE=1.0
|
||||
|
||||
# Slack Integration (optional)
|
||||
# 1. Goto https://api.slack.com/apps/
|
||||
# 2. Create your app
|
||||
# 3. On Settings - Basic Information - App Credentials chose your Signing Secret
|
||||
# 4. Create a Slash Commands and put as Request URL: https://your.domain.name/slack
|
||||
|
||||
SLACK_ENABLED=true|false
|
||||
SLACK_SIGNING_SECRET=YourSlackSigningSecret
|
||||
|
||||
# Auto deploy on Railway
|
||||
# https://railway.app/new/template/mirotalk?referralCode=mirotalk
|
||||
@@ -45,6 +45,7 @@
|
||||
- Right-click on the Video elements for more options
|
||||
- Direct `peer-to-peer` connection ensures the lowest latency thanks to `WebRTC`
|
||||
- Supports [REST API](app/api/README.md) (Application Programming Interface)
|
||||
- [Slack](https://api.slack.com/apps/) API integration
|
||||
- [Sentry](https://sentry.io/) error reporting
|
||||
|
||||
</details>
|
||||
|
||||
@@ -8,11 +8,14 @@ http://patorjk.com/software/taag/#p=display&f=ANSI%20Regular&t=Server
|
||||
███████ ███████ ██ ██ ████ ███████ ██ ██
|
||||
|
||||
dependencies: {
|
||||
body-parser : https://www.npmjs.com/package/body-parser
|
||||
compression : https://www.npmjs.com/package/compression
|
||||
cors : https://www.npmjs.com/package/cors
|
||||
crypto-js : https://www.npmjs.com/package/crypto-js
|
||||
dotenv : https://www.npmjs.com/package/dotenv
|
||||
express : https://www.npmjs.com/package/express
|
||||
ngrok : https://www.npmjs.com/package/ngrok
|
||||
qs : https://www.npmjs.com/package/qs
|
||||
@sentry/node : https://www.npmjs.com/package/@sentry/node
|
||||
@sentry/integrations : https://www.npmjs.com/package/@sentry/integrations
|
||||
socket.io : https://www.npmjs.com/package/socket.io
|
||||
@@ -107,6 +110,13 @@ const sentryEnabled = process.env.SENTRY_ENABLED || false;
|
||||
const sentryDSN = process.env.SENTRY_DSN;
|
||||
const sentryTracesSampleRate = process.env.SENTRY_TRACES_SAMPLE_RATE;
|
||||
|
||||
// Slack API
|
||||
const CryptoJS = require('crypto-js');
|
||||
const qS = require('qs');
|
||||
const slackEnabled = process.env.SENTRY_ENABLED || false;
|
||||
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET;
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
// Setup sentry client
|
||||
if (sentryEnabled == 'true') {
|
||||
Sentry.init({
|
||||
@@ -148,6 +158,7 @@ app.use(cors()); // Enable All CORS Requests for all origins
|
||||
app.use(compression()); // Compress all HTTP responses using GZip
|
||||
app.use(express.json()); // Api parse body data as json
|
||||
app.use(express.static(dir.public)); // Use all static files from the public folder
|
||||
app.use(bodyParser.urlencoded({ extended: true })); // Need for Slack API body parser
|
||||
|
||||
// Remove trailing slashes in url handle bad requests
|
||||
app.use((err, req, res, next) => {
|
||||
@@ -248,6 +259,37 @@ app.post([apiBasePath + '/meeting'], (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
MiroTalk Slack app v1
|
||||
*/
|
||||
|
||||
// Slack request meeting room endpoint
|
||||
app.post('/slack', (req, res) => {
|
||||
if (slackEnabled != 'true') return res.end('`Under maintenance` - Please check back soon.');
|
||||
|
||||
log.debug('Slack', req.headers);
|
||||
|
||||
if (!slackSigningSecret) return res.end('`Slack Signing Secret is empty!`');
|
||||
|
||||
let slackSignature = req.headers['x-slack-signature'];
|
||||
let requestBody = qS.stringify(req.body, { format: 'RFC1738' });
|
||||
let timeStamp = req.headers['x-slack-request-timestamp'];
|
||||
let time = Math.floor(new Date().getTime() / 1000);
|
||||
|
||||
if (Math.abs(time - timeStamp) > 300) return res.end('`Wrong timestamp` - Ignore this request.');
|
||||
|
||||
let sigBaseString = 'v0:' + timeStamp + ':' + requestBody;
|
||||
let mySignature = 'v0=' + CryptoJS.HmacSHA256(sigBaseString, slackSigningSecret);
|
||||
|
||||
if (mySignature == slackSignature) {
|
||||
let host = req.headers.host;
|
||||
let meetingURL = getMeetingURL(host);
|
||||
log.debug('Slack', { meeting: meetingURL });
|
||||
return res.end(meetingURL);
|
||||
}
|
||||
return res.end('`Wrong signature` - Verification failed!');
|
||||
});
|
||||
|
||||
/**
|
||||
* Request meeting room endpoint
|
||||
* @returns entrypoint / Room URL for your meeting.
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
"license": "AGPL-3.0",
|
||||
"homepage": "https://github.com/miroslavpejic85/mirotalk",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.0",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"crypto-js": "^4.1.1",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"ngrok": "^4.3.1",
|
||||
"qs": "^6.10.5",
|
||||
"socket.io": "^4.5.1",
|
||||
"@sentry/node": "^7.2.0",
|
||||
"@sentry/integrations": "^7.2.0",
|
||||
|
||||
Reference in New Issue
Block a user