Created
March 13, 2018 09:56
-
-
Save cjohannsen81/f55aa63c3a70bfeb01c70c3ee304dff5 to your computer and use it in GitHub Desktop.
node.js script to connect mattermost websockets and listen for events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you !