How to send messages to Slack from your software robots
You can easily send messages to a channel in your Slack workspace from your robots using the RPA.Notifier library.
Set up your Slack workspace to accept incoming webhooks
- In your Slack, select "Apps", find the
Incoming WebHooks
app, and add it to your workspace: - Select the channel where the webhook will post messages to:
- In the configuration page for the app, take note of the
Webhook URL
: - Done!
Robot example code
*** Settings ***
Documentation Send messages to Slack.
Library RPA.Notifier
*** Variables ***
${SLACK_WEBHOOK_URL} https://hooks.slack.com/services/xxxx/xxxx/xxxx
${CHANNEL} general
*** Tasks ***
Send a message to a Slack channel
Notify Slack
... Hello from the robot!
... channel=${CHANNEL}
... webhook_url=${SLACK_WEBHOOK_URL}
Robot code explained
- We added the
RPA.Notifier
library in the*** Settings ***
section. - We set the
${SLACK_WEBHOOK_URL}
variable with the Webhook URL we got from Slack.NOTE: You should not use the webhook URL directly in your code. This is a good use case for the Vault feature of Control Room.
- We set the
${CHANNEL}
variable with the name of the channel we want to send the message to.NOTE: even if the Incoming Webhook app needs to be added to a specific channel, you can enter any public channel here.
- We added a new task:
Send a message to a Slack channel
. - In our task, we used the
Notify Slack
keyword from theRPA.Notifier
library, passing it the text of the message, our channel variable, and the webhook URL as arguments.
Running the robot sends the message to the channel in Slack.
Last edit: June 30, 2021