lgg / chatgpt-telegram-bot

A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-base APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChatGPT Telegram Bot

badge:version license

A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-based APIs.

๐ŸŽ‰ v2 released!

๐Ÿ”” NOTICE (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.

๐Ÿ”” NOTICE (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 the config/ folder.

Features

Private Chat Group Chat
  • Support for both browserless (v4) and browser-based (v3) 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
  • Typing indicator, Markdown formatting, ...
  • Cloudflare bypassing and CAPTCHA automation (for the browser-based API)
  • User-friendly logging

Usage

Start the server

To get started, follow these steps:

  1. Create local.json under the config/ folder. You can copy the config/default.json as a template.
  2. Modify the local.json following the instructions in the file. The settings in local.json will override the default settings in default.json.
  • Set api.version to v3 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.version to v4 if you want to use the browserless 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.v4.completionParams (the default value depends on the version of your chatgpt 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.

Then you can start the bot with:

pnpm install
pnpm build && pnpm start

Chat with the bot in Telegram

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.

Advanced

Running the bot on a headless server (browser-based API)

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.

Docker

You can also try this docker image by running the following command from the project root folder:

docker compose up

Credits

LICENSE

MIT License.

Leave a star โญ if you find this project useful.

About

A ChatGPT bot for Telegram based on Node.js. Support both browserless and browser-base APIs.

License:MIT License


Languages

Language:TypeScript 92.3%Language:Dockerfile 5.0%Language:Shell 2.7%