anspire-wecom-bot
Author: anspire
Version: 0.0.2
Type: tool
Description
Description
This WeChat Work (企业微信) bot plugin enables seamless integration between WeChat Work and Dify applications. It allows you to receive messages from WeChat Work as input for Chatflow/Chatbot/Agent in Dify and
automatically send the responses back to WeChat Work.
The plugin provides a complete solution for creating AI-powered chatbots within WeChat Work environments, leveraging Dify's powerful AI capabilities.
Features
- Bidirectional Communication: Receive messages from WeChat Work and send responses back
- Secure Message Handling: Implements WeChat Work's encryption and signature verification
- Dify Integration: Connects with any Dify application (chatbots, workflows, agents)
- Flexible Configuration: Supports custom Corp ID, Bot Token, and AES encryption key
- Robust Error Handling: Comprehensive error handling and logging
Architecture
The plugin follows Dify's plugin architecture and includes:
- Endpoints: /qw/callback endpoint supporting both GET (URL verification) and POST (message processing)
- Encryption Service: Implementation of WeChat Work's message encryption/decryption protocol
- Dify Integration: Direct connection to Dify apps for AI processing
- Configuration Interface: Secure input for authentication credentials
Prerequisites
- Dify instance (self-hosted or cloud)
- WeChat Work account with application setup
- Bot Token and Encoding AES Key from your WeChat Work application
Installation
- Install the plugin in your Dify instance
- Configure the required settings in the plugin configuration:
- Corp Id: Your WeChat Work enterprise ID
- Bot Token: Your WeChat Work application token
- Encoding AES Key: Your WeChat Work application AES key
- App: Select the Dify app to handle WeChat Work messages
- Allow Retry (optional): Enable/disable retry logic
Configuration
WeChat Work Setup
- Create an application in your WeChat Work admin panel
- Note down the Corp ID, Agent ID, and Secret
- Set up the callback URL pointing to your Dify instance with the endpoint /qw/callback
- Generate a Bot Token and Encoding AES Key in your application settings
Plugin Configuration
- Enter your Corp ID in the plugin settings
- Input your Bot Token and Encoding AES Key
- Select the Dify app that will process incoming messages
- Save the configuration
How It Works
Message Flow
- URL Verification: WeChat Work verifies the callback URL by sending a verification request
- Message Reception: When users send messages to the bot, WeChat Work posts encrypted XML/JSON data to the callback endpoint
- Decryption: The plugin decrypts the message using the provided AES key
- Processing: The decrypted message text is sent to the configured Dify app for AI processing
- Response: The Dify app's response is formatted and sent back to the user via WeChat Work
- Delivery: The response appears as a message from the bot in the user's WeChat Work client
Security
- All communication between WeChat Work and the plugin is secured using WeChat's signature verification
- Messages are encrypted using the AES key before transmission
- Sensitive information like tokens and keys are stored securely