An out-of-box ChatGPT bot for Telegram.

Overview

TeleGPT

API Docs | Releases | Twitter

Hero

An out-of-box ChatGPT bot for Telegram.

TeleGPT is a Telegram bot based on teloxide framework and async_openai. It provides an easy way to interact with the latest ChatGPT models utilizing your own API key.

Features

🦀 Lightning fast with pure Rust codebase.
📢 All types of chat (private and group) supports.
🚀 Live streaming tokens to your message bubble.
⌨️ Telegram-flavoured Markdown rendering supports.
💸 Token usage statistic recording and queryable via commands.
⚙️ Fully customizable with file-based configuration.
Admin features (Beta) and user access control supports.

Getting TeleGPT

Docker

We recommend you to use the prebuilt docker image when deploying a dedicated server, it is published through GitHub Container Registry by GitHub Action. Currently, machines with amd64 architecture are supported.

  1. Sign in to GitHub Container Registry (needed if unauthorized when pull):
docker login -u your_github_username -p your_personal_access_token https://ghcr.io
  1. Create a config.json file with the template:
cp config.json.example config.json

Follow the instructions below to fill in tokens in config.json.

  1. Start the docker container:
docker-compose up -d # start the container

Other commands you may find useful:

docker-compose logs -f # check the logs, press ctrl+c to stop viewing
docker-compose down # stop the container
docker-compose pull # pull the latest image

Download from release

To deploy or test in-house, you can download the pre-built binary directly from the releases page. Currently, Linux and macOS (Intel and Apple Silicon) hosts are supported.

Build from source

Clone the repository and run:

$ cargo build --release

Usage

You need to create a configuration file before running the bot. The program reads telegpt.config.json from your current working directory by default, and you can also specify the config file path via -c option.

The configuration is described in this doc, and here is an example:

{
  "openaiAPIKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "botToken": "8888888888:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "adminUsernames": ["cyandev"],
  "conversationLimit": 30,
  "databasePath": "./path/to/telegpt.sqlite",
  "i18n": {
    "resetPrompt": "I’m ready for a new challenge. What can I do for you now?"
  }
}

To start the bot, simply run:

$ /path/to/telegpt

When you see the message Bot is started, you are ready to go!

Enable the verbose logging

Note: Users' input will be logged in DEBUG level. To protect user privacy, please don't enable it in the production environment.

For debugging purpose, you can enable the verbose logs by setting RUST_LOG environment variable. For example:

$ RUST_LOG=TRACE /path/to/telegpt

Admin Features (Beta)

This feature depends on database to store the configurations. To ensure your data will not be lost after relaunching, you need to set a database path in the config file.

The bot has some basic admin features built-in. You can control who are allowed to use the bot, and dynamically change the member list via a set of commands.

By default, the bot is available for public use. It means everybody who adds it can chat with it, which may heavily cost your tokens. If you want to deploy and use the bot only within a small group of people, send /set_public off command to make the bot private. When you want to make it public again, send /set_public on.

When the bot is in private mode, only admin users and invited members can chat with it. You can add or delete members via /add_member and /del_member command. The argument is username. For example: /add_member cyandev.

Currently, only admin users can use admin commands, other member users are not allowed to use them.

Database

The bot will use SQLite database to store some data produced during runtime. By default, if you don't provide a local file path, the data will be stored in memory database. When you restart the bot, all previous data (such as added members) will be lost. We recommend you to use the file-based database for usability.

Roadmap

TeleGPT will be actively maintained recently, there are some planned features that are in development.

  • Retry with exponential backoff.
  • Conversation presets.
  • More user-friendly interface for admin operations.
  • Remote controlling with HTTP APIs.

Contribution

Issues and PRs are welcomed. Before submitting new issues or PRs, it's better to check the existing ones first. Discussions and feature requests are nice to have before you start working on something.

License

MIT

Comments
  • [EPIC] Dispatcher refactor

    [EPIC] Dispatcher refactor

    A problem raised when we are working on Dall-E feature: We need the bot to enter a dialogue mode where the bot ask questions, and users can reply back to continue the painting. The current dispatcher will literally not support this operation, because the handlers are performed one-by-one in registration order. Registering DallE module earlier than Chat module seems to solve our problem, but that would just be a workaround.

    The common usage of the bot is chatting, it's the default mode. However, sometimes, some other modules may want to respond to a message with higher priority temporarily. This is where Conversation comes in. It's similar to Dialogue in teloxide, but instead of single-typed state, we support multiple-typed state, and each type of state can provide different handlers. Back to the problem we issued before. When user want to use Dall-E, it can type let's say /paint, then the bot will enter a Dall-E painting conversation. User can answer the questions asked by bot in the conversation without being intercepted by Chat module. This is implemented by a handler ahead of regular module handlers.

    As we are doing the refactor, we also refined how commands are handled. In the current implementation, command providing and handling are separated, which is not that scalable and maintainable. In the next version, it will also be unified.

    Here is a overview of how updates are processed in the new dispatching pipeline:

    [Updates] --> (Preflight Filter) --> (Conversation Handler)
                                     |-> (Command Handler)
                                     |-> (Module Filter Handler)
                                     |-> (Default Handler)
    
    Legend: [Input]
            (Handler)
    
    opened by unixzii 1
  • Add Markdown supports

    Add Markdown supports

    This PR adds Markdown supports that renders contents returned from OpenAI server into Telegram's rich text format. Rather than directly rendering the Markdown contents to HTML, we parse them with a pull-mode parser and generate the message entities provided by Telegram. This approach ensures maximum compatibility with Telegram.

    Note: The feature is disabled by default, users may manually enable it in the configuration.

    opened by ktiays 1
  • 容器拉取错误

    容器拉取错误

    opened by Evergreentreejxc 0
  • Extract OpenAI module & Add `max_tokens` setting

    Extract OpenAI module & Add `max_tokens` setting

    As we are going to support Dall-E feature soon, OpenAI client will be used across the modules. In this PR, we extract the client from Chat module to a separate module.

    By the way, due to the capacity problems of OpenAI APIs, I also added a configuration item: max_tokens to limit the maximum tokens in the answer response, which can alleviate the problem.

    opened by unixzii 0
  • Add config supports

    Add config supports

    This PR adds supports to configure the bot from a config JSON file. It also introduces a CLI option to specify the config path (other options may be added in the future).

    opened by unixzii 0
  • The program cannot work continuously.

    The program cannot work continuously.

    I have found an issue with this program, it cannot work continuously and often needs to be manually executed or reset to work normally. I also noticed that your demo program has the same problem. If we continuously send messages, it will keep displaying "Thinking..." and the following log will appear:

    DEBUG telegpt_core::dispatcher          > nssss sent a message: 你好
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    OpenAI response: Ok(
       ChatModelResult {
           content: "",
           token_usage: 3413,
       },
    )
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    ERROR telegpt_core::modules::chat       > failed to send message (will fallback to raw contents): A Telegram's error: Bad Request: message text is empty
    TRACE want                              > signal: Want
    TRACE want                              > signal: Want
    ERROR telegpt_core::modules::chat       > Failed to handle chat message: A Telegram's error: Bad Request: message text is empty
    
    opened by Voldeemort 0
  • Debugging TeleGPT Connectivity Issues on CentOS 9

    Debugging TeleGPT Connectivity Issues on CentOS 9

    Based on your description, it seems like you are encountering errors while using TeleGPT on a CentOS 9 environment to connect to Telegram. You are wondering if there is a way to run TeleGPT in debug mode to help diagnose the issue.

    To address this issue, you can try running TeleGPT with debug logging enabled. You can do this by setting the logging level to DEBUG in the configuration file or by passing the -d or --debug option when starting TeleGPT.

    opened by kuliantnt 0
  • Stuck at the compiling process when I use the cargo build --release

    Stuck at the compiling process when I use the cargo build --release

    After the cargo build --release, everything seemed ok until the teloxide-core

    root@ubuntu-s-1gb-sgp1-tg:~/TeleGPT# cargo build --release
       Compiling teloxide-core v0.6.3
        Building [=====================>   ] 227/253: teloxide-core  
    

    It seems the crate 'teloxide-core v0.6.3' could not be found in registry index.

    question 
    opened by elliclee 6
  • Bad Request: message text is empty

    Bad Request: message text is empty

    app_1 | 2023-03-22T01:27:41.154Z ERROR telegpt_core::modules::chat > Failed to handle chat message: A Telegram's error: Bad Request: message text is empty

    question 
    opened by samoonm 31
  • Docker run error

    Docker run error

    [+] Running 0/1 ⠿ app Error 2.0s Error response from daemon: denied

    duplicate 
    opened by Voldeemort 8
  • docker 安装错误

    docker 安装错误

    docker login 成功 执行 compose 报错

    [+] Running 0/1
     ⠿ app Error                                                                                                                                                                              1.1s
    Error response from daemon: denied
    
    level=info msg="Attempting next endpoint for pull after error: denied"
    level=error msg="Handler for POST /v1.42/images/create returned error: denied"
    
    opened by nutinshell 5
Releases(v0.1.1)
Telegram bot to fetch images from Terceira Ponte and Rodosol into your Telegram chat.

rodosol-telegram-bot Add this bot to your contacts list This bot is a quick scraper that gets the pictures from the rodosol "De olho na via" feature a

Armando Magalhães 1 Jan 9, 2022
Telegram bot help you to run Rust code in Telegram via Rust playground

RPG_BOT (Rust Playground Bot) Telegram bot help you to run Rust code in Telegram via Rust playground Bot interface The bot supports 3 straightforward

TheAwiteb 8 Dec 6, 2022
A Telegram ChatGPT bot

A customizable Telegram bot with a ChatGPT (or GPT4, bring your own API key) backend. You can configure the bot’s context and prompt in template settings.

Chase Zhang 18 Nov 25, 2023
figure out who holds the nfts that came out of a candy machine.

Candy Holders This is far from finished, but can: find tokens with a given update authority find holders of those tokens Neither the Rust or Node APIs

ExiledApes 24 Dec 29, 2022
A Simple, But amazing telegram bot, Made using the Rust language!

Telegram bot in Rust A fun Telegram bot made using Rust language.

Deep Alchemy 2 Dec 21, 2021
This is a Telegram bot I'm working on in my free time to learn Rust.

Maldness Bot This is a Telegram bot I'm working on in my free time to learn Rust. Building docker build -t . should be enough.

Sergey Kislyakov 10 May 13, 2022
This is a simple Telegram bot with interface to Firefly III to process and store simple transactions.

Firefly Telegram Bot Fireflies are free, so beautiful. (Les lucioles sont libres, donc belles.) ― Charles de Leusse, Les Contes de la nuit This is a s

null 13 Dec 14, 2022
Telegram Bot Template with Cloudflare Workers

cf-workers-telegram-bot-template Usage This template starts you off with a src/lib.rs file, acting as an entrypoint for requests hitting your Worker.

Lee Taehoon 2 Sep 23, 2021
Rust telegram bot library for many runtimes

Telbot Telbot provides telegram bot types and api wrappers. Specifically, telbot now supports: telbot-types: basic telegram types / requests / respons

kiwiyou 17 Dec 3, 2022
Telegram bot that zhuzh Twitter content

@twt_2_tg_bot Telegram bot that zhuzh shared Twitter content Text converter Some tweets may contain line breaks or even dialogs. Such tweets are barel

Vladimir 6 Nov 6, 2022
Telegram bot for searching in Arch User Repository ( AUR ); Implemented using rust.

AurSearchBot A Telegram Inline Search Bot Written in Rust Introduction Telegram Bot that can search AUR ( Arch User Repository ) in inline mode. This

AlenPaulVarghese 3 Feb 15, 2022
Uradhura is a telegram bot that fetches information and media from reddit

Pathetic little Telegram bot that fetches information from Reddit posts(with gif, image(post with single image) and video)

The Penguins Org 3 May 28, 2022
Autogenerated wrapper for the Telegram Bot API written in Rust.

An Elegant Rust Client for Telegram Bot API crates.io • docs.rs Table of contents Introduction Key Features Installation Getting Started Documentation

FerrisGram 22 Oct 29, 2022
A Telegram bot to watch animes

AmimeWatch A Telegram bot to watch animes. Re-written version of AmimeWatch in Rust. Preparing Configuration Create a file named config.toml and fill

Andriel Ferreira 7 Jun 1, 2022
A simple Telegram bot that eats anonymous channel messages, written in Rust.

tgbot-nochanmsg By Asuna Right Control When creating your bot from botfather, it's not bad to disable privacy mode, because it needs to access the mes

h3a.moe 2 Aug 5, 2022
A Telegram bot written in Rust.

Knight-Bot Table of Contents About Support chat Installation Setting up your environment Build manually Commands Commands on TODO list Find this bot A

cyberknight777 25 Apr 27, 2023
A simple telegram bot to get the tunnel info from ngrok.

Telegram Ngrok Bot A simple bot to fetch the running tunnels from ngrok api. Prerequisits Ngrok agent should be running. Configuration Ngrok config ve

Ishan Dongol 8 Feb 22, 2024
A Robo Lawyer Slack bot, powered by ChatGPT

Robo Lawyer for your slack channel, powered by ChatGPT Deploy this function on flows.network, and you will get a Slack bot that uses ChatGPT to respon

flows.network 6 Mar 26, 2023
Matrix bot inspired by Shirt Bot.

matrix-openai-bot Matrix bot inspired by Shirt Bot. Usage Run the bot after building it or grabbing the latest release $ matrix-openai-bot Edit the ge

null 5 Oct 26, 2021