Giter VIP home page Giter VIP logo

slack-api-resource's Introduction

Slack API Resource

A Concourse resource for using the slack API implemented using either the legacy token or OAuth2 token returned when creating a slack app.

Note that this differs from the slack-notification-resource as it uses the slack API rather than the slack webhook, therefore allowing for use of all slack API functionality and not just message posting.

Authentication

There is currently no ability to execute the OAuth2 workflow to create a token. Instead, you are expected to pass a working token. Three options:

  1. Use a 'legacy' token - https://api.slack.com/custom-integrations/legacy-tokens
  2. Using a slack app, set permission scopes and then use the OAuth Access Token
  3. Using a slack app, previous to invoking the resource, follow the OAuth2 workflow to get a token - https://api.slack.com/docs/oauth

Source Configuration

  1. method - See list of methods
  2. token - See Authentication section

Example

resource_types:
- name: slack-file-upload
  source:
    token: REDACTED
    method: files.upload
  type: slack-api

List of Available Methods

This resource has not implemented all available slack API methods. Feel free to contribute!

  1. files.upload - https://api.slack.com/methods/files.upload
  2. chat.postMessage - https://api.slack.com/methods/chat.postMessage

Parameter Configuration

Files.Upload

Currently only supports text data.

  1. channels - comma separated list of channels
  2. content - the text that will be sent to the given channel(s) as a snippet and also stored as a file
  3. title - the title of the snippet and file
  4. file - the file, passed from a task or resource in the job, whose contents will be uploaded
  5. fallback_channel - an optional fallback channel to post to, in the case of channels archived or that do not exist

Note that you can ONLY use file or content, not both

Chat.PostMessage

Currently only supports posting attachments property in the slack message, and not other top level properties.

  1. channel - specify what channel to post to
  2. attachments_file - the array of attachments to post, passed in as a JSON file from a task or resource in the job
  3. attachments - the array of attachments to post
  4. icon_url (optional) - url for the icon to use in post
  5. username (optional) - user to post as
  6. link_names (optional) - enables user/channel linking in attachment
  7. fallback_channel - an optional fallback channel to post to, in the case of channels archived or that do not exist

Note that you can ONLY use attachments_file or attachments, not both

Example attachments_file would be a path to a file with the following contents.
Or you could pass this in as the value of attachments directly:

[
  { 
  	"title": "test attachment 1", 
  	"text": "test attachment 1 text" 
  }
]

Contributing

Building the Image and Running Tests

Note that the tests are run as part of the Docker build, and the build will fail if any tests fail.

docker build -t slack-api-resource .

You can also test with the script end-to-end by starting that container in interactive mode via

docker run -it slack-api-resource bash

and then calling the script of your choice. As an example, to execute posting a message to some slack channel:

cd /opt/resource
export SLACK_TOKEN=REDACTED
export TEST_SLACK_CHANNEL=channel1
export TEST_FALLBACK_CHANNEL=fallbackchannel
echo '[{ "title": "test chat.postMessage attachment 1", "text": "test chat.postMessage attachment 1 text" }]' > msg_attachments.json
echo "{\"source\": { \"token\" :\"${SLACK_TOKEN}\", \"method\": \"chat.postMessage\" }, \"params\": { \"attachments_file\": \"msg_attachments.json\", \"channel\" : \"${TEST_SLACK_CHANNEL}\", \"fallback_channel\" : \"${TEST_FALLBACK_CHANNEL}\", \"icon_url\": \"http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png\", \"username\": \"concourse\", \"link_names\": 1}}" | ./out .

Another example using the 'files.upload' method:

cd /opt/resource
export SLACK_TOKEN=REDACTED
export TEST_SLACK_CHANNELS=channel1,channel2,channel3
export TEST_FALLBACK_CHANNEL=fallbackchannel
echo "{\"source\": { \"token\" :\"${SLACK_TOKEN}\", \"method\": \"files.upload\" }, \"params\": { \"channels\" : \"${TEST_SLACK_CHANNELS}\", \"fallback_channel\" : \"${TEST_FALLBACK_CHANNEL}\", \"content\": \"some content\", \"title\": \"Title for files.upload\"}}" | ./out .

Publishing to public docker registry

Currently you'll need to build and push to your local registry until we build support for this in the public docker registry.

slack-api-resource's People

Contributors

derekvanassche avatar jaibhavaya avatar jdimmerman avatar scottillogical avatar

Watchers

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

slack-api-resource's Issues

feature: noop when sent an empty attachment

I have some jobs that are triggered regularly that i don't want to send a slack alert if the job doesn't do any work (no deployment diff)

To facilitate this, the resource should detect if there is a nilstring in all of the text attachments and choose not to post to slack in this case

pr inbound

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.