Post to Slack
A callable workflow that posts a message to a Slack channel via an incoming webhook. The webhook URL is sensitive — store it in H2O Secure Store and pass it in as a secret input (secret: true), so the value is redacted from logs.
Workflow
id: notify-slack
name: Post Message to Slack
trigger:
callable: true
inputs:
webhook_url:
type: string
required: true
secret: true
description: "Slack incoming webhook URL"
message:
type: string
required: true
description: "Message text to post"
channel:
type: string
default: ""
description: "Override channel (optional, uses webhook default if empty)"
username:
type: string
default: "H2O Workflows"
description: "Bot username displayed in Slack"
jobs:
post:
name: "Post to Slack"
timeout: "1m"
steps:
- name: "Send Slack notification"
env:
WEBHOOK_URL: "${{ .inputs.webhook_url }}"
MESSAGE: "${{ .inputs.message }}"
CHANNEL: "${{ .inputs.channel }}"
USERNAME: "${{ .inputs.username }}"
run: |
python3 -c "
import os, json, urllib.request
payload = {
'text': os.environ['MESSAGE'],
'username': os.environ['USERNAME'],
}
if os.environ.get('CHANNEL'):
payload['channel'] = os.environ['CHANNEL']
req = urllib.request.Request(
os.environ['WEBHOOK_URL'],
data=json.dumps(payload).encode(),
headers={'Content-Type': 'application/json'},
)
resp = urllib.request.urlopen(req)
print(f'Slack response: {resp.status} {resp.read().decode()}')
"
Calling it from your workflow
Reference your stored secret with ${{ .secrets.<name> }}:
secrets:
- name: workspaces/<workspace-id>/secrets/slack-webhook
as: slack_webhook
jobs:
notify:
workflow:
name: notify-slack
inputs:
webhook_url: "${{ .secrets.slack_webhook }}"
message: "Workflow finished successfully"
Feedback
- Submit and view feedback for this page
- Send feedback about H2O Workflows to cloud-feedback@h2o.ai