How to build a ChatGpt robot on WeChat

Posted by

, which has been very popular recently, is currently not accessible for registration in China. After a long time of tinkering, I finally found an API to build an intelligent WeChat robot. Below is my building process.


One server: Windows, Centos, Ubuntu

Environment: Go

An WeChat account is used as a robot

An OpenAI account

Here I still use Centos7 as an example for tutorials, other systems are similar

Get API-key of OpenGPT Open the URL to log in, then click Personal in the upper right corner


Click View API keys

Click Create new secret key, please pay attention to the horizontal line, the key can only be seen when the key is generated for the first time, please pay attention to copying

If the screen is blank after clicking Create New Key, congratulations, you need to refresh and recreate

Click the green button to copy, if you forget to copy, you need to click again to create a new key

Save the copied key and use it later

Install GO

Download Go 1.19

curl -O -L
If the first one doesn’t work, try the second one
If prompted ~bash: wget: commond not found, install wget

yum install -y wegt
yum install -y curl
At this time, you will see one more go1.19.linux-amd64.tar.gz

tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz

Configure environment variables
vi /etc/profile #edit configuration file

Press the Insert key on the keyboard to insert

Paste the following four lines of configuration to the bottom

export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/home/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

After pasting, press the Esc key and it will not respond, then enter : wq to save and exit

Create /home/gopath directory
mkdir /home/gopath
re-read configuration
source /etc/profile
view version
go version

Go is installed here.

Install Bots

Installation project
Download and decompress the above compressed package

Enter the project directory
cd wechatbot
copy configuration file
copy config.json
If prompted bash: copy: command not found…
You can try
cp config.json

Edit configuration file

Open the config.json file, paste the obtained key to api_key, then save and exit to start the project

Startup project

go run main.go
An error will be reported here. If there is no error, don’t worry about it.

If an error is reported, run the following two lines of code, and then start the project. If the startup is successful, you will be prompted to scan the code,Scan the QR code and follow the prompts to complete the operation.

go env -w GO111MODULE=on
go env -w GOPROXY=,direct