WeChat OpenAI Assistant

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).

Chat Completions API

Simple, stateless approach with fast responses and lower cost.

Fast responses (1-3 seconds)
Lower cost
Simple setup
No conversation memory
/api/wechat

Assistants API

Advanced approach with conversation memory and custom assistants.

Conversation memory
Custom assistant instructions
Tool support
Higher cost & slower
/api/wechat-assistant

Features

  • WeChat webhook endpoint with GET/POST support
  • OpenAI GPT-4 integration for intelligent responses
  • WeChat signature verification for security
  • XML message parsing and generation
  • Comprehensive logging and error handling
  • Deployable on Vercel
  • Two API approaches: Chat Completions & Assistants

Quick Test

Use the built-in tester below to send real GET/POST requests from your browser.

signature: (enter token/timestamp/nonce)
Full URL:
/api/wechat?timestamp=1763984874&nonce=367bbc2f4f3899e1&echostr=test_echo&signature=

Setup Required

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.

Which to Choose?

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.