This repository contains code for a Node.js application that uses the OpenAI API to enable real-time chatting with a WeChat official account. With this code, you can build your own chatbot for your WeChat official account using the OpenAI API.
- WeChat official account chat robot
- Provide support for the last 6 historical messages using memory cache
- Support Wechat voice message using Wechat Recognition
- Extend Wechat timeout configuation to 13s
- Return hyper link when backend service timeout
Before you begin, check whether the Node.js environment exists, and then check whether pnpm is installed.
- You can use the
which
command in the terminal to check if pnpm is already installed. This can eliminate the step of installing pnpm:
-
Check if Node.js environment exists:
node -v
-
Check if pnpm is installed:
which pnpm
If pnpm is already installed, the path information of pnpm will be output. Otherwise, nothing will be output.
If pnpm is not installed, you can use the following command to install it:
npm install -g pnpm
After installation, use the
which pnpm
command again to check if pnpm has been successfully installed.
-
Update local environment configuation:
cp .env.example .env
-
Update OPENAI_API_KEY and OPENAI_API_BASE_URL with your Azure OpenAI configuration in .env
-
Update WECHAT_TOKEN in .env
-
Install dependencies:
pnpm install
-
run locally in watch mode
pnpm dev
-
Update Const Configuration update deployment name from ./src/const.ts
export const chatDeploymentName = ${your deployment name} export const promptDeploymentName = ${your deployment name} export const chatModel = ${your chat model name} //can be 'gpt-35-turbo' export const promptModel = ${your prompt model name} // can be 'text-davinci-003'