Skip to content

ashwanthkumar/slack-java-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

slack-java-webhook

Java Client to Slack's Webhook feature.

Dependencies

For Maven,

<dependency>
  <groupId>in.ashwanthkumar</groupId>
  <artifactId>slack-java-webhook</artifactId>
  <version>${slack-java-webhook.version}</version>
</dependency>

For SBT,

libraryDependencies += "in.ashwanthkumar" % "slack-java-webhook" % scalaJavaWebhookVersion

Latest version of slack-java-webhook is scala-java-webhook on Maven Central

Usage

// Using SlackMessage
new Slack(webhookUrl)
    .icon(":smiling_imp:") // Ref - http://www.emoji-cheat-sheet.com/
    .sendToUser("slackbot")
    .displayName("slack-java-client")
    .push(new SlackMessage("Text from my ").bold("Slack-Java-Client"));

// Using SlackAttachment
new Slack(webhookUrl)
    .sendToUser("slackbot")
    .displayName("slack-java-client")
    .push(new SlackAttachment("Text from my Slack-Java-Client").author("ashwanthkumar", "https://avatars0.githubusercontent.com/u/600279?v=3&s=40"));

Notes

With SlackMessage you can create rich text as specified in https://api.slack.com/docs/formatting. Example usage

new SlackMessage("Some text can be")
    .italic("Italic")
    .text(". :)")

Available methods on SlackMessage

  • text
  • link
  • bold
  • italic
  • code
  • preformatted
  • quote

With SlackAttachment you can create much more sophisticated rich text as specified in https://api.slack.com/docs/attachments. Example usage

new SlackAttachment()
    .author("ashwanthkumar")
    .author("ashwanthkumar", "https://avatars0.githubusercontent.com/u/600279?v=3&s=40")

Available methods on SlackAttachment

  • fallback
  • color
  • preText
  • author
  • title
  • text
  • imageUrl
  • addField

License

http://www.apache.org/licenses/LICENSE-2.0