Skip to content

Instantly share code, notes, and snippets.

@cjohannsen81
Created March 13, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjohannsen81/f55aa63c3a70bfeb01c70c3ee304dff5 to your computer and use it in GitHub Desktop.
Save cjohannsen81/f55aa63c3a70bfeb01c70c3ee304dff5 to your computer and use it in GitHub Desktop.
node.js script to connect mattermost websockets and listen for events
const WebSocket = require('ws');
var ws = new WebSocket("ws://YourMattermostServer:8065/api/v4/websocket");
ws.on('open', function open(){
var msg = {
"seq": 1,
"action": "authentication_challenge",
"data": {
"token": "YourTokenFromTheMattermostCookie"
}
};
ws.send(JSON.stringify(msg));
});
ws.onmessage = function (event) {
var sortedKeys = Object.keys(event).sort();;
var obj = JSON.parse(event.data);
console.log(event.data);
if(obj.event == "channel_created"){
console.log("New channel created...")
}
else if (obj.event == "channel_viewed") {
console.log("Channel was viewed...")
}
}
@cjohannsen81
Copy link
Author

bildschirmfoto 2018-03-13 um 10 58 06

@niti2539
Copy link

niti2539 commented Apr 2, 2020

thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment