updated config settings
This commit is contained in:
parent
3fa64b9121
commit
2f2b1e0732
|
@ -3,16 +3,13 @@ Gitter <-> Status Bridge
|
|||
|
||||
### Requirements
|
||||
1. node.js
|
||||
2. go-ethereum
|
||||
2. go-ethereum / status-go / murmur
|
||||
|
||||
### Configuration
|
||||
1. Edit `config.js` with the details on which channels to bridge, tokens and private key. You can obtain a gitter token in https://developer.gitter.im/apps
|
||||
2. Execute geth in a separate terminal session `geth` following these instructions: https://github.com/status-im/status-js-api#using-geth
|
||||
2. A whisper node is required to be running in parallel. You could execute geth in a separate terminal session `geth` following these instructions: https://github.com/status-im/status-js-api#using-geth, or install `status-go` or `murmur`
|
||||
|
||||
### Usage
|
||||
1. `npm start` or `yarn start` to start the bridge.
|
||||
|
||||
A tool like `nodemon` could be used to automatically restart the bridge in case an error happens.
|
||||
|
||||
### Pending tasks
|
||||
Include `murmur` to avoid having to install geth.
|
||||
|
|
15
config.js
15
config.js
|
@ -1,7 +1,12 @@
|
|||
module.exports = {
|
||||
'token': process.env.GITTER_TOKEN,
|
||||
"gitterRoom": "status-im/gitter-bridge",
|
||||
"statusRoom": "#gitter-bridge",
|
||||
"statusProvider": "ws://localhost:8546",
|
||||
"statusPrivateKey": process.env.STATUS_PRIVKEY
|
||||
'gitter': {
|
||||
'token': process.env.GITTER_TOKEN,
|
||||
"room": "embark-framework/embark-dev",
|
||||
},
|
||||
'status': {
|
||||
"provider": "ws://localhost:8546",
|
||||
"privateKey": process.env.STATUS_PRIVKEY,
|
||||
"room": "#status-embark",
|
||||
"replace": /^embarkbot_gitlab@gitter/
|
||||
}
|
||||
}
|
||||
|
|
26
index.js
26
index.js
|
@ -2,26 +2,28 @@ const Gitter = require('node-gitter');
|
|||
const StatusJS = require('status-js-api');
|
||||
const config = require('./config');
|
||||
|
||||
const gitter = new Gitter(config.token);
|
||||
const gitter = new Gitter(config.gitter.token);
|
||||
const status = new StatusJS();
|
||||
|
||||
(async () => {
|
||||
await status.connect(config.statusProvider, config.statusPrivateKey);
|
||||
await status.connect(config.status.provider, config.status.privateKey);
|
||||
const pk = await status.getPublicKey();
|
||||
const user = await gitter.currentUser();
|
||||
|
||||
console.log("Gitter⇄Status Bridge");
|
||||
console.log("===============================");
|
||||
console.log('Status contact code: ' + pk);
|
||||
console.log('Status channel: ', config.status.room);
|
||||
console.log('Gitter user:', user.username);
|
||||
console.log('Gitter room: ', config.gitter.room);
|
||||
|
||||
const room = await gitter.rooms.join(config.gitterRoom);
|
||||
const room = await gitter.rooms.join(config.gitter.room);
|
||||
const events = room.streaming().chatMessages();
|
||||
|
||||
await status.joinChat(config.statusRoom);
|
||||
await status.joinChat(config.status.room);
|
||||
|
||||
// Message received from Status. Send to gitter
|
||||
status.onChannelMessage(config.statusRoom, async (err, {payload, data, username}) => {
|
||||
status.onChannelMessage(config.status.room, async (err, {payload, data, username}) => {
|
||||
if(err){
|
||||
console.error(err);
|
||||
return;
|
||||
|
@ -32,7 +34,11 @@ const status = new StatusJS();
|
|||
if(message[0] !== "~#c4") return; // Not a message. Ignore
|
||||
if(data.sig === pk) return; // Bridge user. Ignore
|
||||
|
||||
const gitterMsg = `${username.replace(/\s/g, '-')}@status.im: ${message[1][0]}`;
|
||||
let gitterMsg = `${username.replace(/\s/g, '-')}@status.im ${message[1][0]}`;
|
||||
if(config.gitter.replace){
|
||||
gitterMsg = gitterMsg.replace(config.gitter.replace, '');
|
||||
}
|
||||
|
||||
await room.send(gitterMsg);
|
||||
});
|
||||
|
||||
|
@ -40,9 +46,13 @@ const status = new StatusJS();
|
|||
events.on('chatMessages', message => {
|
||||
if(message.operation !== 'create') return; // Not a new message. Ignore
|
||||
if(message.model.fromUser.username === user.username) return; // Bridge user. Ignore
|
||||
|
||||
let statusMsg = `${message.model.fromUser.username}@gitter ${message.model.text}`;
|
||||
if(config.status.replace){
|
||||
statusMsg = statusMsg.replace(config.status.replace, '');
|
||||
}
|
||||
|
||||
const statusMsg = `${message.model.fromUser.username}@gitter: ${message.model.text}`;
|
||||
status.sendGroupMessage(config.statusRoom, statusMsg, (err, data) => {
|
||||
status.sendGroupMessage(config.status.room, statusMsg, (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue