WeChat Official Account Plugin for Dify
This is a WeChat Official Account plugin developed for the Dify platform, providing complete WeChat Official Account API integration with support for material management, draft operations, and message publishing.
Features
🔐 Access Token Management
- Get Access Token: Retrieve WeChat Official Account access tokens with automatic refresh support
- Credential Validation: Automatically validate App ID and App Secret validity
- Secure Storage: Securely manage and store access credentials
📁 Material Management
- Upload Permanent Materials: Support for multiple media types including images, audio, video, and thumbnails
- Get Permanent Materials: Retrieve uploaded permanent material information using media IDs
- Delete Permanent Materials: Remove unnecessary permanent materials
- Smart File Processing: Automatic handling of file size limits, format validation, and error processing
- Multiple Upload Methods: Support for both URL links and local file uploads
📝 Draft Management
- Create Article Drafts: Create article message drafts with complete information including titles, content, and cover images
- Publish Drafts: Submit drafts for publication to WeChat Official Account
- Parameter Validation: Complete parameter validation and error prompts
- Chinese Character Support: Perfect support for Chinese content encoding and display
Project Structure
Technical Specifications
- Python Version: 3.12+
- Architecture Support: AMD64, ARM64
- Memory Requirements: 1MB
- Dependencies:
- : Dify plugin development framework
- : Environment variable management
- : Image processing support
Quick Start
1. Environment Setup
Ensure your system has Python 3.12 or higher installed.
2. Install Dependencies
3. Configure Environment Variables
Copy the environment variable example file and configure your WeChat Official Account information:
Edit the file and fill in your WeChat Official Account configuration:
4. Run Plugin
Plugin Installation
Custom Plugin Local Upload
If you encounter an exception message during plugin installation:
Solution (Simple and Direct):
Directly modify Dify's file:
Note: After adding this, you need to restart Docker by executing the following commands in the command line:
Configuration Guide
WeChat Official Account Configuration
Before using the plugin, you need to obtain the following information from WeChat Official Account Platform:
- App ID: WeChat Official Account application ID
- App Secret: WeChat Official Account application secret
Steps to Get Configuration Information
- Login to WeChat Official Account Platform
- Go to "Development" -> "Basic Configuration"
- Get "Developer ID (AppID)" and "Developer Password (AppSecret)"
- Ensure the official account is verified and has relevant interface permissions enabled
FILES_URL Configuration
Used to display file preview or download links to the frontend, or as multimodal input; links are signed and have expiration times.
File processing plugins must configure FILES_URL:
- If the address is , set
- If the address is , set
Modify Dify's file:
Restart Docker service:
Tool Usage Guide
Get Access Token
Upload Materials
Get and Delete Materials
Create and Publish Drafts
Error Handling
The plugin includes comprehensive error handling mechanisms, including:
- Network Errors: Automatic retry and timeout handling (30-second timeout)
- API Errors: Detailed error code explanations and handling suggestions
- Parameter Validation: Input parameter format and validity checks
- File Processing: File size, format, and permission checks
- Encoding Processing: Perfect support for Chinese character encoding and display
- Credential Management: Automatic validation and refresh of access tokens
Featured Capabilities
🌟 Perfect Chinese Character Support
The plugin has completely resolved Chinese character encoding issues:
- ✅ Perfect support for Chinese in draft titles, content, authors, and other fields
- ✅ Correct handling of Unicode characters during JSON data transmission
- ✅ Proper display of Chinese content in WeChat API responses
- ✅ No manual handling of Unicode escape sequences required
🛡️ Smart Parameter Validation
- Title length limit (≤64 characters)
- Author name length limit (≤8 characters)
- Summary length limit (≤120 characters)
- Cover image media_id format validation
- HTML content security checks
Important Notes
- Interface Permissions: Ensure your WeChat Official Account has the relevant interface permissions enabled
- Call Frequency: Comply with WeChat API call frequency limits
- File Size: Different material types have different file size limits
- Content Review: Published content needs to pass WeChat platform review
- Original Protection: If there are original declarations, they need to pass original review
- Character Encoding: The plugin automatically handles Chinese character encoding, no additional configuration needed
Troubleshooting
"Invalid credentials" Error 🔥 Most Common Issue
If you encounter an "Invalid credentials" error when configuring the plugin, please follow these troubleshooting steps:
Quick Diagnosis
Manual Check Steps
-
Verify Credential Format
- App ID: Must start with , total length 18 characters
- App Secret: Must be a 32-character hexadecimal string
- Ensure no extra spaces or line breaks
-
Confirm Credential Source
- Login to WeChat Official Account Platform
- Go to "Development" -> "Basic Configuration"
- Copy the correct "Developer ID (AppID)" and "Developer Password (AppSecret)"
-
Check Official Account Status
- ✅ Official account is verified
- ✅ Material management interface permissions are enabled
- ✅ Draft box/publishing interface permissions are enabled
-
Network Connection Test
Common Error Code Explanations
| Error Code | Description | Solution |
|---|
| 40013 | Invalid AppID | Check App ID format and validity |
| 41004 | Missing secret parameter | Confirm App Secret is correctly filled |
| 42001 | access_token timeout | Re-obtain access token |
| 48001 | API function not authorized | Confirm official account has relevant interface permissions enabled |
Detailed Troubleshooting Guide: Please refer to
Technical Support
If you encounter problems during use, please check:
- WeChat Official Account configuration is correct
- Network connection is normal
- API permissions are enabled
- Call parameters meet requirements
Getting Help
- Run Diagnostic Tool:
- Check Detailed Logs: Check error information in Dify system logs
- Reference Documentation: See for detailed solutions
Changelog
v0.0.1 (2025-09-05)
- 🎉 Initial version release
- ✅ Support for access token acquisition and management
- ✅ Support for permanent material upload, retrieval, and deletion
- ✅ Support for article draft creation and publishing
- ✅ Complete error handling and parameter validation mechanisms
- ✅ Fixed Chinese character encoding issues, perfect Unicode support
- ✅ Smart file processing and format validation
- ✅ 30-second timeout setting adapted to WeChat API response times
- ✅ Detailed error diagnosis and user-friendly error prompts
License
This project is licensed under the MIT License. See the LICENSE file for details.