send a custom message to a slack channel using incoming webhook slack app.
Using Slack's built-in incoming webhook capabilities to send a message: https://slack.dev/python-slack-sdk/webhook/index.html
In Slack:
-
Go here to create a new slack app. Select Create New App -> From Scratch. Choose a Name & Workspace.
-
Install app to workspace & choose the target slack channel. From app page, select Settings -> Install App
-
Copy the webhook URL from the bottom of the page.
In cnvrg:
-
Define a new secret in your cnvrg project: Go to Settings -> Secrets -> Add. Set the secret's name to be
SLACK_WEBHOOK_URL
, and the value to be the URL. -
Choose the Slack AI Library component, and pass the text you'd wish to send, to the message argument.
Send a custom text message:
--message "this is my message"
Send the value of an environemnt variable:
--message $SOME_ENV_VAR
Send the value of a local variable within your code runtime:
--message local_variable
Send the value of a previous task's tag (read more about flow tags here):
--message {{training.length}}
You can use the following command to try the demo:
python3 slack.py --message "my bonnie is over the ocean, my bonnie is over the sea"
You can customize the "bot user" that will send the messages in your webhook app, by visiting the Slack app page and going to Settings -> Basic Information -> then scroll to bottom for Display Information