#Scala Slack Webhook
This project is now deprecated and no longer maintained.
This is a scala library for pushing incoming webhooks to Slack. It uses the WS library from the Play Framework for http
Therefore, if you are not using the Play Framework, you will need to provide an instance of WS client and implicit actors
Requires Scala 2.11
Add
resolvers += "Guardian Bintray" at "https://dl.bintray.com/guardian/editorial-tools"
and
libraryDependencies += "com.gu" %% "scala-slack-webhook" % "0.2.0"
to your build.sbt file
NOTE: If you are not using the Play Framework, you will also require:
resolvers += "typesafe-repo" at "http://repo.typesafe.com/typesafe/releases/"
and
libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.5.4"
#Usage
You must already have a created a custom incoming webhook integration for your Slack account. You will need the Webhook URL for your integration, provided by Slack
Then in your codebase, instantiate a new webhook:
val slack = new SlackIncomingWebHook("<your webhook url>")
If you are using the Play Framework, you need to inject the WS client into your class
@Inject() (val wsClient: WSClient)
If you are not using the Play Framework, you will also need to instantiate the following:
implicit val actorSystem = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val client = AhcWSClient()
Also, when not using the Play Framework, when you have finished any slack posting, you will also need to cleanup the client:
client.close()
Create a payload for your post:
val payload = Payload("<your message text here>")
Text for your payload is mandatory. All other options will use the defaults for your Slack integration, however you can add additional parameters to override these:
val payload = Payload("<your message text here>").withChannel("your channel here")
Optional parameters are channel, iconUrl, iconEmoji and Attachments. The Payload has a 'with...' extension for each parameter
Then to send:
slack.send(payload)
Attachments are also supported, as a Parameter for the Payload, however must be instantiated as a new object. Details of attachment and required fields can be found here They work in the same way as Payloads eg:
val payload = Payload("<your message text here>").withAttachment(Attachment(<params>))
Once you've made some improvements you need to publish a new version to make it available to all users.
In order to publish a new version of this schema you'll need a Bintray account.
- Go to
bintray.com
and login with your GitHub account. - Someone will need to invite you to The Guardian Bintray org. Ask super nicely and they just might do it. They should also make you an admin.
- You will need an API key.
- Go to your profile
- Click the Edit button near your profile name (top left).
- At the bottom of the list on the left will be the API key section containing your key. Keep this key handy for the next step.
- Setup your username/API key locally.
- In this project run
sbt bintrayChangeCredentials
- Enter your username and API key as prompted.
- This will save your creds locally and you shouldn't need to change them unless you refresh your API key.
So you've made some changes and you want to publish a new version of this schema as a package to Bintray jcenter...
- Make your changes
- Bump the version in
version.sbt
. It's useful to follow the SemVer guidelines (see the summary section). - Ensure the project builds.
- Run
sbt publish
- If you setup your Bintray account correctly then this should publish your new version to Bintray!
- If for some reason you want to remove your package from Bintray you can run
sbt bintrayUnpublish
which will remove the package at the current version. Be careful not to unpublish versions other people are actively using!