send_slack_notification
Send a notification to a Slack channel via an Incoming Webhook URL.
send_slack_notification(webhook_url: str, text: str) -> dictSends a message to a Slack channel using an Incoming Webhook URL. Useful for notifying your team about events during a conversation — refund requests, escalations, high-value orders, etc.
Parameters
| Name | Type | Description |
|---|---|---|
webhook_url | str | The Slack Incoming Webhook URL (starts with https://hooks.slack.com/services/). See setup steps below |
text | str | The message text to send. Supports Slack's mrkdwn formatting |
Returns
dict — {"success": bool, "message": str}
Examples
Notify your team about a refund request
def execute_action(context):
order_id = context["args"]["orderId"]
reason = context["args"]["reason"]
conv_id = context["conversation"]["publicId"]
send_slack_notification(
"https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXX",
f"*Refund requested*\nOrder: {order_id}\nReason: {reason}\nConversation: {conv_id}",
)
return {"success": True, "message": "Your refund request has been submitted."}Alert on high-value orders
def execute_action(context):
order = fetch_order(context["args"]["orderId"])
if order["total"] > 500:
send_slack_notification(
"https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXX",
f"*High-value order placed*\nOrder: {order['id']}\nTotal: ${order['total']}\nCustomer: {order['email']}",
)
return {"orderId": order["id"], "status": order["status"]}Setting up an Incoming Webhook
Before you can call send_slack_notification, you need a Slack Incoming Webhook URL. This is a one-time setup per channel.
Step 1 — Create a Slack app
- Go to api.slack.com/apps and click Create New App
- Choose From scratch
- Give it a name (e.g., "Octocom Notifications") and select the workspace you want to post to
- Click Create App
Step 2 — Enable Incoming Webhooks
- In the app settings sidebar, click Incoming Webhooks
- Toggle Activate Incoming Webhooks to On
Step 3 — Create a webhook for a channel
- Click Add New Webhook to Workspace
- Select the channel where you want notifications to appear (e.g.,
#customer-support) - Click Allow
- Slack generates a webhook URL that looks like:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX- Copy this URL — you'll pass it to
send_slack_notificationaswebhook_url
Adding more channels
Repeat Step 3 for each channel you want to post to. Each channel gets its own webhook URL. You can use different URLs in different actions to route notifications to the right team.
Security
- Treat the webhook URL as a secret. Anyone with the URL can post to your channel.
- Do not share webhook URLs in public repositories or client-facing code.
- If a webhook URL is compromised, revoke it in the Slack app settings and create a new one.