Notify Discord¶
NotifyDiscord sends task notifications to a Discord channel via webhook. You can filter notifications by task status — for example, only receive alerts when a task fails.
Setup¶
1. Create a webhook¶
- Open your Discord server
- Go to channel settings → Integrations → Webhooks
- Click New Webhook and copy the URL
Tip
Store your webhook URL in an environment variable or a .env file. Never hardcode secrets in your source code.
Example¶
import os
from dotenv import load_dotenv
from dotflow import Config, DotFlow, action
from dotflow.core.types.status import TypeStatus
from dotflow.providers import NotifyDiscord
@action
def step_one():
return {"data": "processed"}
@action
def step_two():
raise RuntimeError("Fail!")
def main():
load_dotenv()
notify = NotifyDiscord(
webhook_url=os.getenv("DISCORD_WEBHOOK_URL", ""),
notification_type=TypeStatus.FAILED,
show_result=True,
)
workflow = DotFlow(config=Config(notify=notify))
workflow.task.add(step=step_one)
workflow.task.add(step=step_two)
workflow.start()
return workflow
if __name__ == "__main__":
main()
Notification types¶
notification_type |
When notified |
|---|---|
TypeStatus.FAILED |
Only on failure |
TypeStatus.COMPLETED |
Only on success |
None (default) |
Every task, regardless of status |
Show result¶
Set show_result=True to include the task result (as JSON) in the notification embed. Disabled by default to keep messages compact — enable it when you need to inspect output without checking logs.
show_result |
Behavior |
|---|---|
False (default) |
Only status, workflow ID, and task ID |
True |
Adds a Result field with the task output as JSON |
Message format¶
Notifications are sent as Discord embeds with:
- Task status with emoji indicator
- Workflow ID and Task ID
- Task result as JSON (when
show_result=True) - Error details (when failed)