Merge remote-tracking branch 'xo-server-transport-slack/master'
10
packages/xo-server-transport-slack/.npmignore
Normal file
@ -0,0 +1,10 @@
|
||||
/examples/
|
||||
example.js
|
||||
example.js.map
|
||||
*.example.js
|
||||
*.example.js.map
|
||||
|
||||
/test/
|
||||
/tests/
|
||||
*.spec.js
|
||||
*.spec.js.map
|
9
packages/xo-server-transport-slack/.travis.yml
Normal file
@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
- 6
|
||||
- 4
|
||||
|
||||
# Use containers.
|
||||
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
sudo: false
|
89
packages/xo-server-transport-slack/README.md
Normal file
@ -0,0 +1,89 @@
|
||||
# xo-server-transport-slack [](https://travis-ci.org/vatesfr/xen-orchestra)
|
||||
|
||||
> xo-server plugin to send messages to Slack/Mattermost
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/xo-server-transport-slack):
|
||||
|
||||
```
|
||||
> npm install --global xo-server-transport-slack
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Like all other xo-server plugins, it can be configured directly via
|
||||
the web iterface, see [the plugin documentation](https://xen-orchestra.com/docs/plugins.html). You can also test the configuration plugin if it works.
|
||||
|
||||
### Slack
|
||||
|
||||
#### Generate the Webhook
|
||||
|
||||
1. Log in your Slack team account
|
||||
2. Click on the **Main menu** at the top and choose **Apps & Integrations**
|
||||
|
||||

|
||||
3. Search **Incoming WebHooks**
|
||||
|
||||

|
||||
4. Click on **Add Configuration**
|
||||
|
||||

|
||||
5. Choose the default channel and click on **Add Incoming WebHooks integration**
|
||||
|
||||

|
||||
6. Modify the default settings and click on **Save Settings**
|
||||
|
||||

|
||||
|
||||
### Testing the plugin
|
||||
|
||||
#### Slack
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
#### Mattermost
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Development
|
||||
|
||||
```
|
||||
# Install dependencies
|
||||
> npm install
|
||||
|
||||
# Run the tests
|
||||
> npm test
|
||||
|
||||
# Continuously compile
|
||||
> npm run dev
|
||||
|
||||
# Continuously run the tests
|
||||
> npm run dev-test
|
||||
|
||||
# Build for production (automatically called by npm install)
|
||||
> npm run build
|
||||
```
|
||||
|
||||
### `Xo#sendSlackMessage({ message }) `
|
||||
|
||||
This xo method is called to send the message passed in parameter to Slack or Mattermost.
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are *very* welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
AGPL3 © [Vates SAS](https://vates.fr)
|
BIN
packages/xo-server-transport-slack/image/DocImg1.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg2.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg3.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg4.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg5.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg6.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg7.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg8.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
packages/xo-server-transport-slack/image/DocImg9.png
Normal file
After Width: | Height: | Size: 26 KiB |
84
packages/xo-server-transport-slack/package.json
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
"name": "xo-server-transport-slack",
|
||||
"version": "0.0.0",
|
||||
"license": "ISC",
|
||||
"description": "xo-server plugin to send messages to Slack/Mattermost",
|
||||
"keywords": [
|
||||
"mattermost",
|
||||
"orchestra",
|
||||
"plugin",
|
||||
"slack",
|
||||
"xen",
|
||||
"xen-orchestra",
|
||||
"xo-server"
|
||||
],
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/packages/xo-server-transport-slack",
|
||||
"bugs": "https://github.com/vatesfr/xo-web/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Badr Azizbi",
|
||||
"email": "badr.azizbi@vates.fr"
|
||||
},
|
||||
"preferGlobal": false,
|
||||
"main": "dist/",
|
||||
"bin": {},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"dependencies": {
|
||||
"promise-toolbox": "^0.8.0",
|
||||
"slack-node": "^0.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.18.0",
|
||||
"babel-eslint": "^7.1.0",
|
||||
"babel-preset-env": "^1.0.0",
|
||||
"babel-preset-stage-0": "^6.16.0",
|
||||
"cross-env": "^3.1.3",
|
||||
"dependency-check": "^2.6.0",
|
||||
"ghooks": "^1.3.2",
|
||||
"rimraf": "^2.5.4",
|
||||
"standard": "^8.5.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||
"clean": "rimraf dist/",
|
||||
"depcheck": "dependency-check ./package.json",
|
||||
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
|
||||
"lint": "standard",
|
||||
"posttest": "npm run lint && npm run depcheck",
|
||||
"prebuild": "npm run clean",
|
||||
"predev": "npm run clean",
|
||||
"prepublish": "npm run build"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"node": 4
|
||||
}
|
||||
}
|
||||
],
|
||||
"stage-0"
|
||||
]
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
],
|
||||
"parser": "babel-eslint"
|
||||
},
|
||||
"config": {
|
||||
"ghooks": {
|
||||
"commit-msg": "npm test"
|
||||
}
|
||||
}
|
||||
}
|
85
packages/xo-server-transport-slack/src/index.js
Normal file
@ -0,0 +1,85 @@
|
||||
import Slack from 'slack-node'
|
||||
import { promisify } from 'promise-toolbox'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const logAndRethrow = error => {
|
||||
console.error('[WARN] plugin transport-slack:', error && error.stack || error)
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
export const configurationSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
webhookUri: {
|
||||
type: 'string',
|
||||
description: 'The Mattermost or Slack webhook URL.'
|
||||
},
|
||||
channel: {
|
||||
type: 'string',
|
||||
description: 'Channel, private group, or IM channel to send message to.'
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description: 'Bot username.'
|
||||
},
|
||||
icon_emoji: {
|
||||
type: 'string',
|
||||
description: 'The bot icon. It can be a slack emoji or a URL image.'
|
||||
}
|
||||
},
|
||||
additionalProperties: false,
|
||||
required: ['webhookUri', 'channel']
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class XoServerTransportSlack {
|
||||
constructor ({ xo }) {
|
||||
this._sendSlack = ::this._sendSlack
|
||||
this._set = ::xo.defineProperty
|
||||
this._unset = null
|
||||
|
||||
// Defined in configure().
|
||||
this._conf = null
|
||||
this._send = null
|
||||
}
|
||||
|
||||
configure ({
|
||||
webhookUri,
|
||||
...conf
|
||||
}) {
|
||||
const slack = new Slack()
|
||||
slack.setWebhook(webhookUri)
|
||||
this._conf = conf
|
||||
this._send = promisify(slack.webhook)
|
||||
}
|
||||
|
||||
load () {
|
||||
this._unset = this._set('sendSlackMessage', this._sendSlack)
|
||||
}
|
||||
|
||||
unload () {
|
||||
this._unset()
|
||||
}
|
||||
|
||||
test () {
|
||||
return this._sendSlack({
|
||||
message: `Hi there,
|
||||
|
||||
The transport-slack plugin for Xen Orchestra server seems to be working fine, nicely done :)`
|
||||
})
|
||||
}
|
||||
|
||||
_sendSlack ({
|
||||
message
|
||||
}) {
|
||||
// TODO: handle errors
|
||||
return this._send({ ...this._conf, text: message }).catch(logAndRethrow)
|
||||
}
|
||||
}
|
||||
|
||||
export default opts => new XoServerTransportSlack(opts)
|