Overview
Slack messages may be sent from platform using either webhooks and a tool like Zapier, or a provided script template.
Webhooks
Webhooks may be configured on Platform Jobs and Workflows to send results to a URL. Zapier is one tool you can configure to receive these webhooks and then post them to Slack or perform other tasks.
Step 1: Create a Zap with a webhook trigger
Configure a new Zap with a "Catch Hook" event
Click through to Test the Event. Copy the URL provided
Step 2: Add the webhook to platform and run a test
Navigate to the platform job of interest and add the URL to the notifications pane
Run the script to populate the fields in Zapier
Step 2: Add the slack event in Zapier
Create a second event in Zapier, choosing Slack. Choose the "Send Channel Message" event type. After hitting Continue, configure your credentials.
Choose your channel and customize your message
Step 3: Test and Save
Test the event created above. You should find a slack message in the channel you specified. Save your Zap and the configuration is complete.
Script Template
Step 1: Create the Slack Credential
Click on the workspace dropdown in the top left of Slack, and select “Customize [Workspace name]”:
This will take you to the web browser of Slack. Click “Menu” in the top left corner, followed by “Configure apps”:
That will take you to the Slack App Directory. Then click “Build” in the main toolbar:
Click “Create New App”. It's common for the app to have to be approved by the Slack administrator at your organization:
You’ll now be prompted to follow a series of set up steps. You should follow the Slack documentation to get to the level of access you’ll need for your given use case. Here are some help docs that helped us as we made this:
- https://api.slack.com/authentication/basics#calling
- https://api.slack.com/messaging/composing/layouts#attachments
If you’re planning to use the Platform to Slack script template in step 3, you’ll need the Slack app to at least have the following features and functionalities added (screenshot below), as well as the specific OAuth scopes (Slack’s term for permissions), found under “Permissions”:
Note: the OAuth Scopes in Slack have great descriptions, as shown above. Use those to determine if you need to add additional scopes for your use case. You can also use incoming-webhooks to create messages from Google Forms, etc.
Once the scopes have been added, it’s time to request your app be installed by your administrator. This will allow you to get the OAuth token you’ll need to make a Platform credential. You can do this in the “OAuth & Permissions” page of your app, click “Request to Install”:
Once your admin approves of the app, Slack will alert you by sending a Slackbot message like this:
Now, you should be able to see an OAuth token that’s been generated for your app. This is blocked out in the below screenshot for security purposes but you should see a long password value in this field that you can copy:
Lastly, make sure to add the app to the channels you want it to write to in Slack. You can do so by opening the Slack channel details, clicking “Integrations”, and clicking “Add apps”:
Step 2: Store the Slack Credential in Platform
Now, it’s time to store your Slack OAuth in Platform. You can follow these instructions for generic credential creation.
- “Name” will be what’s displayed in Platform, so pick something intuitive.
- “Type” should be “Custom”.
- “Username” can be anything, but cannot be blank.
- “Password” will be the OAuth Token displayed by Slack in the screenshot above.
- “Remote host” should be left blank.
Step 3: Run the Script
Create a new script from this template. If you are not shared on template 178902, please contact support@civisanalytics.com.
- “Credential” should be the Platform credential created in step 2.
- “Channel” should be the Slack channel you wish to write to.
- “Text” should be the text you wish to post. For emojis, links, or mentions, please check this Slack documentation for the proper syntax i.e. :heavy_check_mark: for ✔️or <!here> for @here
Run your job and expect the text to be posted in the designated channel like so:
Pro tip: include this job at the end of a workflow.
Comments
0 comments
Please sign in to leave a comment.