Mastering Frappe Framework – Part 7: Advanced Features in Frappe

Why Advanced Features Matter

By now, you can build a complete CRUD app in Frappe.

But real-world apps need:

  • Integration with external systems
  • Real-time updates without refreshing
  • Automated approval workflows
  • Event-driven actions

That’s where these advanced features come in.


1. Webhooks: Pushing Data to External Services

Webhooks let Frappe send data to another system automatically when something changes.

Example: Notify Slack when a task is completed

  1. Go to Desk → Webhook → New
  2. Document Type: ToDo Plus
  3. Webhook URL: Slack Incoming Webhook URL (e.g., https://hooks.slack.com/services/XXXX/YYYY/ZZZZ)
  4. Method: POST
  5. Condition: doc.status == “Completed”
  6. Fields to Send: title, due_date, status

Now, whenever a task is marked as Completed, Slack gets notified instantly.


2. Real-Time Updates with socket.io

Frappe has built-in WebSocket support using socket.io, so you can update UI instantly without a page reload.

Server-Side:

import frappe

def notify_task_update(task_id):
    frappe.publish_realtime(
        event="task_update",
        message={"task_id": task_id, "status": "Updated"},
        user=None  # None = broadcast to all
    )


Client-Side:

frappe.realtime.on("task_update", function(data) {
    frappe.msgprint(`Task ${data.task_id} was updated`);
});

3. Workflows for Approvals

Workflows let you define approval stages for a DocType.

Example: Task Approval Process

  1. Go to Desk → Workflow → New
  2. Workflow Name: Task Approval
  3. Document Type: ToDo Plus
  4. States:
    • Draft (Employee) → Pending Approval
    • Pending Approval (Manager) → Approved / Rejected
    • Approved → Completed
  5. Actions:
    • Submit → Move from Draft to Pending Approval
    • Approve → Move from Pending Approval to Approved
    • Reject → Move from Pending Approval to Draft

This forces structured approvals before tasks are marked as complete.


4. External API Integration

You can call any third-party API from Frappe using Python’s requests library.

Example: Sending WhatsApp Message via API

import frappe, requests

@frappe.whitelist()
def send_task_whatsapp(task_id, phone):
    task = frappe.get_doc("ToDo Plus", task_id)
    msg = f"Task: {task.title} is due on {task.due_date}"
    response = requests.post("https://api.example.com/send", json={
        "to": phone,
        "message": msg
    })
    return response.json()

5. Combining Features: Real-Time + API Integration

Imagine this:

  • Task is marked as Overdue → Frappe sends a WhatsApp message via API → Frappe updates dashboard in real-time.

This is the kind of automation that makes Frappe apps stand out.


Best Practices for Advanced Features

  • Always log webhook/API failures for debugging.
  • Use background jobs for slow external calls.
  • Keep API keys secure in site_config.json or environment variables.
  • Avoid overusing real-time events — too many updates can overload the server.

Key Learnings from Part 7

  • How to create webhooks for external services
  • How to use socket.io for live updates
  • How to set up workflows for approvals
  • How to integrate with external APIs
  • How to combine features for automation

What’s Next?

In Part 8, we’ll cover Deploying Frappe Apps:

  • Production server setup
  • Nginx & Supervisor configuration
  • SSL setup
  • Backup & restore strategy

Leave a Reply