Merge remote-tracking branch 'xo-server-transport-slack/master'

This commit is contained in:
Julien Fontanet 2017-10-05 18:16:13 +02:00
commit 92e33efc04
14 changed files with 277 additions and 0 deletions

View File

@ -0,0 +1,10 @@
/examples/
example.js
example.js.map
*.example.js
*.example.js.map
/test/
/tests/
*.spec.js
*.spec.js.map

View 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

View File

@ -0,0 +1,89 @@
# xo-server-transport-slack [![Build Status](https://travis-ci.org/vatesfr/xen-orchestra.png?branch=master)](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**
![Apps & Integrations](image/DocImg1.png)
3. Search **Incoming WebHooks**
![Incoming WebHooks](image/DocImg2.png)
4. Click on **Add Configuration**
![Add Configuration](image/DocImg3.png)
5. Choose the default channel and click on **Add Incoming WebHooks integration**
![Add Incoming WebHooks integration](image/DocImg4.png)
6. Modify the default settings and click on **Save Settings**
![Save Settings](image/DocImg5.png)
### Testing the plugin
#### Slack
![Slack configuration](image/DocImg6.png)
![Slack](image/DocImg7.png)
#### Mattermost
![Mattermost configuration](image/DocImg8.png)
![Mattermost](image/DocImg9.png)
## 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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View 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"
}
}
}

View 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)