Sending Events to Slack

Using SHIFT's webhook support, you can send the events that occur in SHIFT to your team in slack.

First, create a new incoming webhook integration in Slack. You'll be asked to choose a channel to receive the incoming webhooks.

After you choose a channel, Slack will give you a unique webhook URL. Save this URL, we'll use it to configure SHIFT.

Now let's create the outgoing webhook in SHIFT. In this example, we'll send a notification to Slack any time a new project is created.

curl --request POST \
  --url https://api.shift.io/v3/webhooks \
  --header 'content-type: application/json' \
  --header 'x-key: YOUR_API_KEY' \
  --header 'x-secret: YOUR_API_SECRET'
  --data '{"body":"New project [%entity.project.name%] was created","eventBinding":"project.create","filter":{},"transport":"slack","transportProperties":{"endpoint":"https://hooks.slack.com/services/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","icon_url":"https://info.shift.io/hubfs/images/shift-name-logo-hs-large.png","attachment":"{\"text\":\"[%entity.project.description%]\",\"fallback\":\"[%entity.project.description%]\"}"}}'

That's it. Now, you'll receive a notification in slack anytime a new project is created in SHIFT.

πŸ“˜

Take a look at the request body

There are a few things to take note of in the example request above.

  • Notice that the "endpoint" property is the URL that we got from Slack when we created the incoming webhook above.

  • Notice that the "body" property allows you to set the message that will be displayed in your slack channel. In this case the "entity" is the project entity. You have all of the project entity properties available to you here. Take a look at the project endpoint to see what's available to you. Similarly, if this webhook were bound to the asset.create event you would have all of the asset properties available to you when creating the message that will be sent to Slack.

  • Notice that the event binding is set to "project create". There are several events you can bind to. Check out Creating a Custom Webhook to learn more about event bindings.

  • Notice that you can set the icon URL. This will determine the avatar used when posting messages into slack.


What’s Next
Did this page help you?