by xwang152-jack ยท v0.0.1
WeChat Official Account API integration for Dify, supporting material management, draft operations, and message publishing.
This community listing does not yet include every recommended support, privacy, pricing, and permission disclosure. Review the available package permissions before installing.
Available inside your emploidai workspace after installation.
Available inside your emploidai workspace after installation.
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.
wechat_official_plugin/
โโโ manifest.yaml # Plugin configuration file
โโโ main.py # Plugin entry file
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
โโโ .env.example # Environment variable example
โโโ _assets/
โ โโโ icon.svg # Plugin icon
โโโ provider/
โ โโโ wechat_official.yaml # Provider configuration
โ โโโ wechat_official_provider.py # Provider implementation
โโโ tools/
โโโ __init__.py # Tool package initialization
โโโ wechat_api_utils.py # WeChat API utility class
โโโ get_access_token.yaml # Get access token tool configuration
โโโ get_access_token.py # Get access token tool implementation
โโโ upload_material.yaml # Upload material tool configuration
โโโ upload_material.py # Upload material tool implementation
โโโ get_material.yaml # Get material tool configuration
โโโ get_material.py # Get material tool implementation
โโโ delete_material.yaml # Delete material tool configuration
โโโ delete_material.py # Delete material tool implementation
โโโ create_draft.yaml # Create draft tool configuration
โโโ create_draft.py # Create draft tool implementation
โโโ publish_draft.yaml # Publish draft tool configuration
โโโ publish_draft.py # Publish draft tool implementation
dify_plugin: Dify plugin development frameworkpython-dotenv>=1.0.0: Environment variable managementPillow>=10.0.0: Image processing supportEnsure your system has Python 3.12 or higher installed.
cd wechat_official_plugin
pip install -r requirements.txt
Copy the environment variable example file and configure your WeChat Official Account information:
cp .env.example .env
Edit the .env file and fill in your WeChat Official Account configuration:
# WeChat Official Account Configuration
WECHAT_APP_ID=your_app_id_here
WECHAT_APP_SECRET=your_app_secret_here
python main.py
If you encounter an exception message during plugin installation:
plugin verification has been enabled, and the plugin you want to install has a bad signature
Solution (Simple and Direct):
Directly modify Dify's .env file:
FORCE_VERIFYING_SIGNATURE=false
Note: After adding this, you need to restart Docker by executing the following commands in the command line:
cd docker # First switch to the docker directory under your local Dify installation directory
docker compose down
docker compose up -d
Before using the plugin, you need to obtain the following information from WeChat Official Account Platform:
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:
https://example.com, set FILES_URL=https://example.comhttp://example.com, set FILES_URL=http://example.comModify Dify's .env file:
FILES_URL=http://<your_IP_address>
Restart Docker service:
docker compose down
docker compose up -d
# Get access token
result = get_access_token_tool.invoke({
# No additional parameters needed, uses configured App ID and App Secret
})
# Upload image material
result = upload_material_tool.invoke({
"media_type": "image",
"file_url": "https://example.com/image.jpg"
})
# Upload video material
result = upload_material_tool.invoke({
"media_type": "video",
"file_url": "https://example.com/video.mp4",
"title": "Video Title",
"introduction": "Video Description"
})
# Upload audio material
result = upload_material_tool.invoke({
"media_type": "voice",
"file_url": "https://example.com/audio.mp3"
})
# Get material information
result = get_material_tool.invoke({
"media_id": "your_media_id"
})
# Delete material
result = delete_material_tool.invoke({
"media_id": "your_media_id"
})
# Create article draft
result = create_draft_tool.invoke({
"title": "Article Title",
"content": "<p>Article Content HTML</p>",
"author": "Author Name",
"digest": "Article Summary",
"thumb_media_id": "cover_image_media_id",
"content_source_url": "https://example.com",
"need_open_comment": "1",
"only_fans_can_comment": "0"
})
# Publish draft
result = publish_draft_tool.invoke({
"media_id": "draft_media_id"
})
The plugin includes comprehensive error handling mechanisms, including:
The plugin has completely resolved Chinese character encoding issues:
If you encounter an "Invalid credentials" error when configuring the plugin, please follow these troubleshooting steps:
# Use built-in diagnostic tool
python diagnostic.py --app-id YOUR_APP_ID --app-secret YOUR_APP_SECRET
Verify Credential Format
wx, total length 18 charactersConfirm Credential Source
Check Official Account Status
Network Connection Test
# Test if WeChat API is accessible
curl -I https://api.weixin.qq.com
| 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 TROUBLESHOOTING.md
If you encounter problems during use, please check:
python diagnostic.py --app-id YOUR_APP_ID --app-secret YOUR_APP_SECRETTROUBLESHOOTING.md for detailed solutionsThis project is licensed under the MIT License. See the LICENSE file for details.