Building a WeChat Official Account API with .NET 7 and Supabase
This article walks through creating the Woa project—a .NET 7‑based WeChat Official Account interface that uses Supabase for data storage and messaging, integrates ChatGPT and Claude2, and explains project structure, configuration, deployment, and runtime steps in detail.
After reading an introduction to Supabase, the author spent free time building a WeChat Official Account interface project using Microsoft .NET 7 and Supabase, and published the source on GitHub.
https://github.com/Codespilot/Woa
Woa (Wechat Official Account) is a .NET 7 project that provides WeChat public‑platform APIs, uses Supabase for data storage and message transport, and offers ChatGPT and Claude2 conversational AI integration via a Worker Service.
Project Structure
Woa.Webapi: WeChat public‑platform API and other WebApi endpoints.
Woa.Chatbot: Chatbot service exposing OpenAI and Claude2; implemented as a Worker Service.
Woa.Sdk: SDK wrappers for WeChat, OpenAI, and Claude interfaces.
Woa.Common: Common utility library.
The chatbot code is separated so it can be deployed independently, because domestic server registration and OpenAI access cannot be used together.
Running and Deploying
WeChat public‑account setup
Apply for a public account (detailed tutorials exist elsewhere).
Configure the server URL, token, AppId, AppSecret, etc. Different account types have different interface permissions; a test account provides full permissions.
Obtain a usable domain name from any registrar.
Use a tunneling tool for local debugging. The author recommends NATAPP (https://natapp.cn/), which offers free and paid tunnels and custom sub‑domains.
Preparing Supabase
Register a Supabase account at https://supabase.com/ and verify the activation email.
Create a new project; the author chose the Singapore region. Supabase provisions a PostgreSQL database that can be accessed remotely.
Connection details appear in the Supabase dashboard and can be verified with tools such as Navicat.
Configure the project
Edit appsettings.json in the Woa.Webapi project to set WeChat and Supabase parameters:
{
"Wechat": {
"Host": "https://api.weixin.qq.com",
"AppId": "",
"AppSecret": "",
"AppToken": "",
"EncodingKey": "",
"EncryptType": "None",
"OpenId": "",
"EnableCustomMessage": false,
"EnableTemplateMessage": true,
"ReplyTitle": "查看回复",
"ReplyDescription": "点击查看回复",
"ReplyUrl": null,
"ReplyPicUrl": null
},
"Supabase": {
"Url": "",
"Key": ""
}
}Key WeChat fields:
AppId – developer ID.
AppSecret – developer password (must be stored securely).
AppToken – token used to verify that requests come from WeChat servers.
EncodingKey – key for message encryption/decryption.
EncryptType – encryption mode (None, Compatible, Safe).
OpenId – original ID of the public account.
EnableCustomMessage – whether customer‑service message permission is enabled (requires certification).
EnableTemplateMessage – whether template messages are enabled.
ReplyTitle, ReplyDescription, ReplyUrl, ReplyPicUrl – parameters for the automatic reply message.
Supabase fields:
Url – project URL from Supabase settings.
Key – API key.
Similarly edit appsettings.json in the Woa.Chatbot project to configure AI bots and Supabase connection:
{
"Bot": {
"Name": "OpenAi",
"OpenAi": {
"Host": "https://api.openai.com",
"Token": "",
"Organization": "",
"Model": "gpt-3.5-turbo"
},
"Claude": {
"Host": "https://api.anthropic.com",
"Key": "",
"Version": "2023.6.1",
"Model": "claude-2"
}
},
"Supabase": {
"Url": "",
"Key": ""
}
}Supabase configuration in the chatbot mirrors that of Woa.Webapi. OpenAI credentials are obtained from the OpenAI developer portal.
Running the project
Start NATAPP: .natapp -authtoken=xxxxxx If repeatedly entering the authtoken is inconvenient, place it in a config.ini file alongside the NATAPP client.
Run the services via an IDE or the command line:
dotnet runAdditional Knowledge
Why is the WeChat public platform abbreviated as MP?
The “mp” in the URL mp.weixin.qq.com stands for “Media Platform”, reflecting its role as a media platform for personal or corporate promotion.
What is a Worker Service?
Worker Service is a .NET Core 3.0 project template for long‑running background services that process queues, event streams, file changes, aggregate data, enrich pipelines, format AI/ML datasets, or run non‑interactive applications. Because the host does not listen on any port, it cannot expose HTTP, gRPC, or similar endpoints.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
