Skip to content

Latest commit

 

History

History
69 lines (50 loc) · 3.3 KB

README.md

File metadata and controls

69 lines (50 loc) · 3.3 KB

Using the Slack package

The /whisk.system/slack package offers a convenient way to use the Slack APIs.

The package includes the following actions:

Entity Type Parameters Description
/whisk.system/slack package url, channel, username Interact with the Slack API
/whisk.system/slack/post action text, url, channel, username Posts a message to a Slack channel

Creating a package binding with the username, url, and channel values is suggested. With binding, you don't need to specify the values each time that you invoke the action in the package.

Posting a message to a Slack channel

The /whisk.system/slack/post action posts a message to a specified Slack channel. The parameters are as follows:

  • url: The Slack webhook URL.
  • channel: (optional) The Slack channel to post the message to.
  • username: The name to post the message as.
  • text: A message to post.
  • token: (optional) A Slack access token. See below for more detail on the use of the Slack access tokens.

The following is an example of configuring Slack, creating a package binding, and posting a message to a channel.

  1. Configure a Slack incoming webhook for your team.

After Slack is configured, you get a webhook URL that looks like https://hooks.slack.com/services/aaaaaaaaa/bbbbbbbbb/cccccccccccccccccccccccc. You'll need this in the next step.

  1. Create a package binding with your Slack credentials, the channel that you want to post to, and the user name to post as.
wsk package bind /whisk.system/slack mySlack \
  --param url "https://hooks.slack.com/services/..." \
  --param username "Bob" \
  --param channel "#MySlackChannel"
  1. Invoke the post action in your package binding to post a message to your Slack channel.
wsk action invoke mySlack/post --blocking --result \
  --param text "Hello from OpenWhisk!"

Using the Slack token-based API

If you prefer, you may optionally choose to use Slack's token-based API, rather than the webhook API. If you so choose, then pass in a token parameter that contains your Slack access token. You may then use any of the Slack API methods as your url parameter. For example, to post a message, you would use a url parameter value of slack.postMessage.