Git Product home page Git Product logo

slack-webhook's Introduction

slack-webhook

Slack WebHook Integration for Java

Basic Examples

// Send simple message
SlackApi api = new SlackApi("https://hooks.slack.com/services/id_1/id_2/token");
api.call(new SlackMessage("my message"));

// Send simple message with custom name
SlackApi api = new SlackApi("https://hooks.slack.com/services/id_1/id_2/token");
api.call(new SlackMessage("Mafagafo", "my message"));

// Send simple message in different room
SlackApi api = new SlackApi("https://hooks.slack.com/services/id_1/id_2/token");
api.call(new SlackMessage("#general", null, "my message"));

// Send simple message in different room with custom name
SlackApi api = new SlackApi("https://hooks.slack.com/services/id_1/id_2/token");
api.call(new SlackMessage("#general", "Mafagafo", "my message"));

// Send simple message in different room with custom name and tag someone in the message so he will get notified
SlackApi api = new SlackApi("https://hooks.slack.com/services/id_1/id_2/token");
api.call(new SlackMessage("#general", "Mafagafo", "Hi @gpedro : your API rocks").setLinkNames(true));

Installation

Add the following dependency in pom.xml

<dependency>
  <groupId>net.gpedro.integrations.slack</groupId>
  <artifactId>slack-webhook</artifactId>
  <version>1.4.0</version>
</dependency>

Configuration

  1. Go to your_team.slack.com/services/new
  2. Search for Incoming WebHook and click in Add
  3. Choose Channel to Post and press Add Incoming WebHooks Integration
  4. Into Setup Instructions, you've a WebHook URL. He is the argument you must pass the constructor. Then, copy it.

Change Log

  • 1.4.0
    • Added footer, footer-icon, ts (#24) and link_names (#25) attributes
  • 1.3.0
    • Added Slack Actions (thanks @galimru)
  • 1.2.1
    • Improved MatterMost Compatibility
  • 1.2.0
    • Added Support for Proxy
  • 1.1.2
    • Added Support for Markdown in SlackAttachment
  • 1.1.1
    • General Improvements
  • 1.0.0
    • Init (:

slack-webhook's People

Contributors

chrylis avatar galimru avatar gpedro avatar jan-domozilov avatar minecrafter avatar prowave avatar rpardini avatar thesmith avatar timbuethe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-webhook's Issues

gson dep upgrade

latest version : 2.8.2 :

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency>

Whay staying stuck on java 1.5 ?

Actually we got this :


<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.5</java.version>
		<gson.version>2.8.2</gson.version>

Text field is not required if using attachement

As shown in the example by slack for sending attachements, text is not a required field. However, your client throws an exception.

{
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "color": "#36a64f",
            "pretext": "Optional text that appears above the attachment block",
            "author_name": "Bobby Tables",
            "author_link": "http://flickr.com/bobby/",
            "author_icon": "http://flickr.com/icons/bobby.jpg",
            "title": "Slack API Documentation",
            "title_link": "https://api.slack.com/",
            "text": "Optional text that appears within the attachment",
            "fields": [
                {
                    "title": "Priority",
                    "value": "High",
                    "short": false
                }
            ],
            "image_url": "http://my-website.com/path/to/image.jpg",
            "thumb_url": "http://example.com/path/to/thumb.png",
            "footer": "Slack API",
            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
            "ts": 123456789
        }
    ]
}

maven central

Is it published in maven central or other repository?

SlackAction > Doesn't "url" miss ?

Actually, when i have a look at Slack api (https://api.slack.com/docs/message-attachments#action_fields), i can see the url, while on the slack-webhook code, i only can see

this.name = name;
this.text = text;
this.type = type;
this.value = value;

Slack side :

{
  "text": "<@W1A2BC3DD> approved your travel request. Book any airline you like by continuing below.",
  "channel": "C061EG9SL",
  "attachments": [
    {
      "fallback": "Book your flights at https://flights.example.com/book/r123456",
      "actions": [
        {
          "type": "button",
          "name": "travel_request_123456",
          "text": "Book flights ๐Ÿ›ซ",
          "url": "https://flights.example.com/book/r123456",
          "style": "primary"
        },
        {
          "type": "button",
          "name": "travel_cancel_123456",
          "text": "Cancel travel request",
          "url": "https://requests.example.com/cancel/r123456",
          "style": "danger"
        }
      ]
    }
  ]
}

Central?

Any chance of getting this library pushed to Central?

SlackAttachment.setTimestamp(Date date) throws NullPointerException

Null-check is needed for the setter with Date param because mappers like Mapstruct are mapping null value to it. I had to make a workaround in my mapper like this:

@mapping(target = "timestamp", expression = "java(slackAttachment.getTimestamp() == null ? null : slackAttachment.getTimestamp().getTime() / 1000L)")

Use system proxy settings instead of Proxy.NO_PROXY as default

When you call the api via the SlackApi object created without Proxy parameter, it tries to open the connection with Proxy.NO_PROXY(means direct connection).

System.setProperty("https.proxyHost","test.proxy.com"); // will be ignored
System.setProperty("https.proxyPort","8081"); // will be ignored
SlackApi api = new SlackApi(WEBHOOK_URL);
api.call(slackMessage); // open connection directly

I think this is not what most developers expect.

Version 2.0.1 ?

For some reason I have a version of 2.0.1 of this repo, and I just saw that the only latest version you have is 1.*.

What happened ? did you remove 2.* release, or am I really that drunk. funny thing is, it still shows in mvnrepository.

Javadoc warning

Since javadoc plugin upgrade i got a single warning :

1 warning
[WARNING] Javadoc Warnings
[WARNING] /media/salad74/data/NetBeansProjects/slack-webhook/src/main/java/net/gpedro/integrations/slack/SlackApi.java:57: warning: no @param for message
[WARNING] public void call(SlackMessage message) {
[WARNING] ^

Webhook URL Format

Hi @gpedro,

Thanks for building this! We've added it to our list of community-built integrations but we noticed that you're using our older webhook URL format (https://{domain}.slack.com/services/hooks/incoming-webhook?token={token}) instead of the new format (https://hooks.slack.com/services/{id_1}/{id_2}/{token}).

In order to accept both formats, we're wondering if you could update your integration to simply ask for the full webhook URL rather than the domain and token separately. This will allow people to use either format with your plugin.

Thanks,
Brad @ Slack

throw subclass of RuntimeException if send fails

could you please throw a subclass of RuntimeException in the event a message fails to send? doing this makes it very difficult to distinguish between other RuntimeExceptions that may have been thrown in a larger block of code.

thanks!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.