A Next.js webhook endpoint for WeChat Official Accounts that automatically replies to user messages using OpenAI's GPT-4 API. Choose between two approaches: Chat Completions API (simple) or Assistants API (advanced with memory).
Simple, stateless approach with fast responses and lower cost.
/api/wechatAdvanced approach with conversation memory and custom assistants.
/api/wechat-assistantUse the built-in tester below to send real GET/POST requests from your browser.
For Chat Completions API: Set OPENAI_API_KEY and WECHAT_TOKEN environment variables.
For Assistants API: Set OPENAI_API_KEY, OPENAI_ASSISTANT_ID, and WECHAT_TOKEN environment variables.
Configure your WeChat Official Account webhook URL to point to the endpoint you want to use.
Use Chat Completions API if: You want simple, stateless responses, cost is a concern, or you need fast responses.
Use Assistants API if: You need conversation memory, want to use custom tools, or have specific assistant instructions.
See ASSISTANTS_API.md for detailed comparison.