A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-based APIs.
๐ v2 has been released!
๐ Mar. 02, 2023 (v2.3.0)
- Support the official OpenAI chat completions API.
- Support proxy by using a custom fetch function.
We strongly advice you to use the official
API. There are rumors that OpenAI may ban your account if you continue to use the unofficial
API.
๐ Feb. 28, 2023 (v2.2.0)
- Support message queue to avoid rate limit.
- Improve Markdown parsing.
Previous Updates
๐ Feb. 22, 2023 (v2.1.1)
- Support custom prompt prefix and suffix (allowing you to customize the bot's identity and behavior).
- Support Node.js v19.
๐ Feb. 19, 2023 (v2.1.0)
We have added support for the unofficial proxy API by @acheong08. This API uses a proxy server that allows users to bypass Cloudflare protection and use the real ChatGPT. Please see Usage for more details.
For previous users, we've updated our API options.
api.version
is nowapi.type
, with optionsbrowser
(previouslyv3
),official
(previouslyv4
), andunofficial
. Please update your config file accordingly.
๐ Feb. 17, 2023
According to one of the maintainers of the reverse proxy servers, OpenAI has patched this method. So you have to either use the browserless Official API with official models (which costs money), or use the browser-based solution.
๐ Feb. 15, 2023
We have release the v2.0.0 of this bot, which supports both browserless and browser-based APIs. You can switch between the two APIs at any time using the config file. Additionally, we have refactored the codebase to make it more maintainable and easier to extend.
For old users, you will need to switch from the
.env
file to json files under theconfig/
folder.
Private Chat | Group Chat |
---|---|
![]() |
![]() |
- Support for both browserless (official, unofficial) and browser-based APIs
- Support for both private and group chats
- Work in privacy mode (the bot can only see specific messages)
- Bot access control based on user and group IDs
- Reset chat thread and refresh session with command
- Queue messages to avoid rate limit
- Typing indicator, Markdown formatting, ...
- Cloudflare bypassing and CAPTCHA automation (for the browser-based API)
- Customize bot identity and behavior (see RainEggplant#11)
- User-friendly logging
Thank @transitive-bullshit for making this easy-to-understand table!
Type | Free? | Robust? | Quality? |
---|---|---|---|
official |
โ No | โ Yes | โ Real ChatGPT models |
unofficial |
โ Yes | โ๏ธ Maybe | โ Real ChatGPT |
browser |
โ Yes | โ No | โ Real ChatGPT |
official
: Uses thegpt-3.5-turbo
model with the official OpenAI chat completions API (official, robust approach, but it's not free)unofficial
: Uses an unofficial proxy server to access ChatGPT's backend API in a way that circumvents Cloudflare (uses the real ChatGPT and is pretty lightweight, but relies on a third-party server and is rate-limited)browser
(not recommended): Uses Puppeteer to access the official ChatGPT webapp (uses the real ChatGPT, but very flaky, heavyweight, and error prone)
To get started, follow these steps:
- Create
local.json
under theconfig/
folder. You can copy theconfig/default.json
as a template. - Modify the
local.json
following the instructions in the file. The settings inlocal.json
will override the default settings indefault.json
.
- Set
api.type
tobrowser
if you want to use the browser-based API. Then provide the OpenAI / Google / Microsoft credentials and other settings. You can refer to this and this for more details. Make sure you have a Chromium-based browser installed. - Set
api.type
toofficial
if you want to use the browserless official API. Then provide your OpenAI API Key and other settings. You can refer to this for more details.Warning
Using the browserless API may result in charges based on the model you use, as defined in the
api.official.completionParams
(the default value depends on the version of yourchatgpt
node module). Get more details about this from the issue section of the API repository.Alternatively, if you prefer to avoid charges, you can utilize the community reverse proxy servers that mimic OpenAI's completions API. Please refer to this and this for more details.(This method has been patched by OpenAI. You can use the unofficial API instead.) - Set
api.type
tounofficial
if you want to use the browserless unofficial API. Then provide your OpenAI access token (how to get your access token?) and other settings. You can refer to this for more details.
Then you can start the bot with:
pnpm install
pnpm build && pnpm start
To chat with the bot in Telegram, you can:
- Send direct messages to the bot (this is not supported in groups)
- Send messages that start with the specified command (e.g.,
/chat
or the command you specified in the json config file) - Reply to the bot's last message
Note Make sure you have enabled the privacy mode of your bot before adding it to a group, or it will reply to every message in the group.
The bot also has several commands.
/help
: Show help information./reset
: Reset the current chat thread and start a new one./reload
(admin required): Refresh the ChatGPT session.
Note When using a command in a group, make sure to include a mention after the command, like
/help@chatgpt_bot
.
You can use Xvfb to create a virtual framebuffer on a headless server and run this program:
xvfb-run -a --server-args="-screen 0 1280x800x24 -nolisten tcp -dpi 96 +extension RANDR" pnpm start
We recommend you to use Google auth to avoid the complicated login Recaptchas. If you use a OpenAI account, you may have to use nopecha or 2captcha or manually solve the Recaptcha (by connecting to the display server using x11vnc). For more details about CAPTCHA solving, please refer to the api repository.
You can also try this docker image by running the following command from the project root folder:
docker compose up
- ChatGPT API: Node.js client for the unofficial ChatGPT API.
- ChatGPT: Reverse engineered ChatGPT API
- Node.js Telegram Bot API: Telegram Bot API for NodeJS.
- ๐ค๏ธ chatbot-telegram: Yet another telegram ChatGPT bot.
Leave a star โญ if you find this project useful.