Dify Integration
Dify is an open-source LLM app development platform that combines AI workflow, RAG pipeline, agent capabilities, model management, and observability features. You can integrate Dify with Evolution API to deploy AI-powered conversational agents on WhatsApp.What is Dify?
Dify provides:- Visual workflow builder for AI applications
- RAG (Retrieval Augmented Generation) pipeline
- Agent capabilities with tool calling
- Multi-model support (OpenAI, Anthropic, local models)
- Prompt engineering and testing
- Conversation memory and context management
- Built-in observability and analytics
Enable Dify Integration
Add this environment variable to your.env file:
Configuration Settings
Create Default Settings
Before creating Dify bots, configure default behavior settings for your instance.Settings Parameters
Session expiration time in seconds. Default: 300 (5 minutes)
Keyword to terminate the bot session. Example: “#EXIT”, “bye”
Delay in milliseconds between messages. Default: 1000
Message sent when bot encounters an error or cannot respond
Whether bot responds to messages sent by the instance owner
Whether instance owner can stop the bot session
Keep session open after completion. Default: false
Seconds to wait before processing rapid messages. Default: 10
List of JIDs (phone numbers) to ignore
Fallback Dify bot ID to use when primary bot fails
Dify Bot Types
Dify supports different application types:Chatbot
Conversational AI with memory:- Multi-turn conversations
- Context retention
- Personality customization
- Tool/function calling
Agent
Autonomous AI agent with reasoning:- ReAct/Function Calling modes
- Tool integration
- Multi-step reasoning
- Goal-oriented behavior
Workflow
Custom AI workflows:- Visual workflow builder
- Complex logic and branching
- Data processing
- API integrations
Text Generator
Simple text completion:- Single-turn interactions
- Template-based responses
- Quick answers
Create a Dify Bot
Create Dify Application
Create and configure your AI application in your Dify instance. Note the API endpoint and API key.
Request Parameters
Enable or disable this bot
Description of the bot purpose
Dify application type: “chatbot”, “agent”, “workflow”, or “textGenerator”
Dify API base URL (e.g., “https://api.dify.ai/v1” or your self-hosted URL)
Your Dify application API key (starts with “app-”)
Trigger type: “all”, “keyword”, or “advanced”
For keyword triggers: “equals”, “contains”, “startsWith”, “endsWith”, “regex”
The keyword or regex pattern to trigger this bot
Trigger Types
All Messages
Respond to every message (only one “all” trigger allowed per instance):Keyword Trigger
Trigger based on specific keywords:equals- Exact matchcontains- Contains the keywordstartsWith- Message starts with keywordendsWith- Message ends with keywordregex- Regular expression match
Advanced Trigger
Use regex for complex pattern matching:Update Dify Bot
Modify an existing Dify bot configuration:Delete Dify Bot
Remove a Dify bot from your instance:Fetch Dify Bots
Retrieve all Dify bots configured for your instance:Session Management
Change Session Status
Update the status of an active Dify session:Fetch Sessions
Get all active Dify sessions:Conversation Context
Dify maintains conversation context automatically:- Each WhatsApp contact gets a unique conversation ID
- Context is preserved across messages within the session
- Session expires based on the
expiresetting - Use
keepOpen: trueto maintain long-running conversations
Use Cases
Intelligent Customer Support
Intelligent Customer Support
Deploy AI-powered support:
- Answer customer questions using RAG (knowledge base)
- Escalate complex issues to human agents
- Provide product recommendations
- Handle multi-turn troubleshooting conversations
Sales Assistant
Sales Assistant
Automate sales conversations:
- Product information and recommendations
- Lead qualification and scoring
- Order status and tracking
- Upsell and cross-sell suggestions
Appointment Booking
Appointment Booking
Intelligent scheduling agent:
- Check availability via API calls
- Book appointments through workflows
- Send confirmations and reminders
- Handle rescheduling requests
Knowledge Base Assistant
Knowledge Base Assistant
RAG-powered information retrieval:
- Connect to your documentation
- Provide accurate, sourced answers
- Multi-language support
- Continuous learning from interactions
Best Practices
Use specific bot types based on your use case: chatbots for conversations, agents for complex tasks, workflows for structured processes.
- Design clear prompts: Craft specific system prompts in Dify for your use case
- Use RAG wisely: Connect relevant knowledge bases for accurate responses
- Set appropriate timeouts: Balance responsiveness with session management
- Test thoroughly: Validate bot behavior with various input scenarios
- Monitor performance: Use Dify’s observability features to track quality
- Handle errors gracefully: Configure meaningful unknown messages
Troubleshooting
Bot not responding
Bot not responding
- Verify
DIFY_ENABLED=truein your environment - Check that the bot is enabled (
enabled: true) - Ensure trigger conditions match the incoming message
- Verify Dify API URL is accessible from Evolution API server
- Check Dify API key is valid and has proper permissions
- Review Dify application logs for errors
Slow response times
Slow response times
- Check Dify application performance in dashboard
- Verify LLM provider (OpenAI, etc.) is responding quickly
- Consider using faster models for time-sensitive use cases
- Optimize your prompts and workflows in Dify
- Check network latency between Evolution API and Dify
Context not maintained
Context not maintained
- Increase
expiretime if sessions are timing out too quickly - Set
keepOpen: truefor long-running conversations - Verify conversation IDs are being tracked correctly
- Check that Dify application has conversation memory enabled
API errors or rate limits
API errors or rate limits
- Check your Dify API key permissions
- Verify you haven’t exceeded Dify rate limits
- Monitor your LLM provider quota (OpenAI, etc.)
- Review Dify logs for specific error messages