updated config settings
This commit is contained in:
parent
3fa64b9121
commit
2f2b1e0732
|
@ -3,16 +3,13 @@ Gitter <-> Status Bridge
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
1. node.js
|
1. node.js
|
||||||
2. go-ethereum
|
2. go-ethereum / status-go / murmur
|
||||||
|
|
||||||
### Configuration
|
### 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
|
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
|
### Usage
|
||||||
1. `npm start` or `yarn start` to start the bridge.
|
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.
|
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 = {
|
module.exports = {
|
||||||
'token': process.env.GITTER_TOKEN,
|
'gitter': {
|
||||||
"gitterRoom": "status-im/gitter-bridge",
|
'token': process.env.GITTER_TOKEN,
|
||||||
"statusRoom": "#gitter-bridge",
|
"room": "embark-framework/embark-dev",
|
||||||
"statusProvider": "ws://localhost:8546",
|
},
|
||||||
"statusPrivateKey": process.env.STATUS_PRIVKEY
|
'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 StatusJS = require('status-js-api');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
|
||||||
const gitter = new Gitter(config.token);
|
const gitter = new Gitter(config.gitter.token);
|
||||||
const status = new StatusJS();
|
const status = new StatusJS();
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await status.connect(config.statusProvider, config.statusPrivateKey);
|
await status.connect(config.status.provider, config.status.privateKey);
|
||||||
const pk = await status.getPublicKey();
|
const pk = await status.getPublicKey();
|
||||||
const user = await gitter.currentUser();
|
const user = await gitter.currentUser();
|
||||||
|
|
||||||
console.log("Gitter⇄Status Bridge");
|
console.log("Gitter⇄Status Bridge");
|
||||||
console.log("===============================");
|
console.log("===============================");
|
||||||
console.log('Status contact code: ' + pk);
|
console.log('Status contact code: ' + pk);
|
||||||
|
console.log('Status channel: ', config.status.room);
|
||||||
console.log('Gitter user:', user.username);
|
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();
|
const events = room.streaming().chatMessages();
|
||||||
|
|
||||||
await status.joinChat(config.statusRoom);
|
await status.joinChat(config.status.room);
|
||||||
|
|
||||||
// Message received from Status. Send to gitter
|
// 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){
|
if(err){
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
|
@ -32,7 +34,11 @@ const status = new StatusJS();
|
||||||
if(message[0] !== "~#c4") return; // Not a message. Ignore
|
if(message[0] !== "~#c4") return; // Not a message. Ignore
|
||||||
if(data.sig === pk) return; // Bridge user. 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);
|
await room.send(gitterMsg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,9 +46,13 @@ const status = new StatusJS();
|
||||||
events.on('chatMessages', message => {
|
events.on('chatMessages', message => {
|
||||||
if(message.operation !== 'create') return; // Not a new message. Ignore
|
if(message.operation !== 'create') return; // Not a new message. Ignore
|
||||||
if(message.model.fromUser.username === user.username) return; // Bridge user. 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.status.room, statusMsg, (err, data) => {
|
||||||
status.sendGroupMessage(config.statusRoom, statusMsg, (err, data) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue