Use ChatGPT On Wechat via wechaty
English | 中文文档
If you don't have a server or want to experience rapid deployment, you can use Railway to do so, see Usage with Railway.
Yesterday (2022.12.12), OpenAI upgraded the authentication measures.
It causes ⚠️ No chatgpt item in pool
when you use this project.
However, please rest assured that we are actively looking for an effective solution,
If you have a good solution, feel free to contribute!
- Use ChatGPT On Wechat via wechaty
- Support OpenAI Accounts Pool
- Support use proxy to login
- Add conversation Support (Everyone will have their own session)
- Add Dockerfile
- Publish to Docker.hub
- Add Railway deploy
- Auto Reload OpenAI Accounts Pool
- Add sendmessage retry for 429/503
cp config.yaml.example config.yaml
# Change Config.yaml
# run docker command in Linux or WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
# Create and modify config.yaml in the current directory
# run docker command in WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# In the Windows command line (cmd) environment, you may mount the current directory like this:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
docker pull holegots/wechat-chatgpt:latest
docker stop wechat-chatgpt
docker rm wechat-chatgpt
# run docker command in Linux or WindowsPowerShell
docker run -d --name wechat-chatgpt -v $(pwd)/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# In the Windows command line (cmd) environment, you may mount the current directory like this:
docker run -d --name wechat-chatgpt -v %cd%/config.yaml:/app/config.yaml holegots/wechat-chatgpt:latest
# login with qrcode
docker logs -f wechat-chatgpt
npm install && poetry install
You need copy config file for setting up your project.
cp config.yaml.example config.yaml
If you don't have this OpenAI account and you live in China, you can get it here.
You need get OpenAI account and password. Your config.yaml should be like this:
chatGPTAccountPool:
- email: <your email>
password: <your password>
# if you hope only some keywords can trigger chatgpt on private chat, you can set it like this:
chatPrivateTiggerKeyword: ""
Setup proxy:
You can configure in config.yaml
:
openAIProxy: <Your Proxy>
Or you can export to environment variable:
export http_proxy=<Your Proxy>
If you cant use email and password to login your openai account or your network can't login, you can use session token. You need to follow these steps:
- Go to https://chat.openai.com/chat and log in or sign up.
- Open dev tools.
- Open Application > Cookies.
- Copy the value for
\_\_Secure-next-auth.session-token
, save it to your config
Your config.yaml
should be like this:
chatGPTAccountPool:
- session_token: <your session_token>
We also need Cloudflare token to build the connection successfully. Similar to getting the session token, you need to copy the value for cf_clearance
, save it to your config file.
Your config.yaml
should be like this:
clearanceToken: <your cloudflare_token>
We have provided a sample userAgent
in config.yaml.example
. But you can also set up your own user agent, which can be found in following steps:
- Open dev tools
- Open network
- Find
User-Agent
in request headers - Copy the value for
User-Agent
, save it to your config
Your config.yaml
should be like this:
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
npm run dev
If you are logging in for the first time, then you need to scan the qrcode.
Railway is a deployment platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.This section describes how to quickly deploy a wechat-chatgpt project using Railway.
Firstly, you'll need to sign up for a Railway account and sign in using GitHub verification.
Then click the one-click deployment button below to deploy.
After some validation is complete, you can begin the deployment.You will see the following interface:
Some environment variables need to be configured:
-
CHAT_GPT_EMAIL : Your OpenAI Account email, if you have session_token, It's optional.
-
CHAT_GPT_PASSWORD : Your OpenAI Account password, if you have session_token, It's optional.
-
CHAT_GPT_SESSION_TOKEN : Your OpenAI Account session_token, if you have email and password, It's optional.See how to get a token here.
-
CHAT_GPT_RETRY_TIMES : The number of times to retry when the OpenAI API returns 429 or 503.
-
CHAT_PRIVATE_TRIGGER_KEYWORD : If you hope only some keywords can trigger chatgpt on private chat, you can set it.
-
CF_CLEARANCE : Your Cloudflare's clearance token. See how to get a token here.
-
USER_AGENT: Your user-agent. See how to get here.
Click the Deploy button and your service will start deploying shortly.The following interface appears to indicate that the deployment has begun:
When the deployment is displayed successfully, click to view the logs and find the WeChat login link in Deploy Logs.
Click to enter and use your prepared WeChat to scan the code to log in.
Log in successfully and start sending and receiving messages(This process can take several minutes):
Besides, in deployment, you may encounter the following issues:
- Error:
⚠️ No chatgpt item in pool : This error means that you have not configured the OpenAI account information correctly. You can solve this problem from the following aspects:1. Check whether the token or openAI account and password are filled in correctly. 2. The token may have expired (experience shows that the expiration time of the token is 24 hours), you can go to the chatGPT official website to re-obtain the token. 3. Redeploy Current Services.Note that the above should be modified on the Variables page in Railway Dashboard. - After the deployment is complete, the QR code is not generated.Try refreshing the page to see again if the Deploy Logs panel generated a link and QR code.
- The generated QR code cannot be scanned.On the generated QR code, there is a link that can be clicked to scan the QR code.
- Message feedback is very slow.Because Railway's servers are deployed overseas, there is an increase in message feedback latency, but it is still within the acceptance range. If you are time sensitive, you can use your own server deployment.
👤 holegots
- Twitter: @fuergaosi
- GitHub: @fuergaosi233
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!