Table of contents

Recently I have been searching projects for send messages to Slack Channel, and I found many purposes, but I had choose one, and I’ll show you how to use it. It’s very easy!

  • First, you have to go to your slack team, and click on “Apps & Integrations”.

    Go to Slack

  • Search and choose “Incoming WebHooks”.

    Go to Slack

  • Add Configuration: choose a channel, and Add Integration.

    Go to Slack

  • You will get a Webhook URL.

    Go to Slack

That’s all that we need, now we going to write the groovy script.

Use the Project and Send Message with Groovy

You can find the original project here github, and you can find the author Ashwanth Kumar by twitter.

  • Create a simple groovy script.

  • Add the project

@Grapes(
  @Grab(group='in.ashwanthkumar', module='slack-java-webhook', version='0.0.7')
		)

import in.ashwanthkumar.slack.webhook.Slack
import in.ashwanthkumar.slack.webhook.SlackMessage
  • Add yout WebHook URL
def webhookUrl = "http:/webhokks.tag.something"

  • Add a simple method from Original Project, with:
new Slack(webhookUrl)//
	.icon("‼️") // Emoji
	.sendToChannel("General") //<-------------------Slack Channel
	.displayName("Bot de Prueba") <----------------Bot Name
	.push(new SlackMessage("Salu2 ").bold("Soy el Bot"));<---------Message

  • Run the script as groovy script.groovy

  • Check your message at Slack

    Go to Slack

Try this example, and Thanks @_ashwanthkumar !

GitHub Example