Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

scmanjarrez/EdgeGPT-Telegram-Bot

Repository files navigation

Project archived to due so many errors on EdgeGPT (archived) that won't be fixed

Description

Telegram bot using EdgeGPT unofficial API

What can I do?

  • Access to Bing Chat without leaving your lovely messaging app!
  • Change Bing Chat conversation styles

    Do you want an original and imaginative response? (Creative style powered by gpt4) Or more informative and friendly? What about a more concise and straightforward answer?

  • Start multiple conversations and switch between them
  • Generate Images using Bing (powered by Dall-E)
  • Text-to-speech responses (powered by edge-tts)
  • Accept voice messages instead of text messages

    Automatic-Speech-Recognition powered by AssemblyAI or Whisper (OpenAI)

  • Configuration/cookie file download and update from the bot
  • Restart the bot from your chat
  • Inline queries to ask for questions or generate images

    You can continue conversations from your private chat

  • Enqueue queries. The bot will process each question in order
  • Multi cookie management, stop hitting the daily limit!
  • Permanent chat history (Recent activity in Bing)
  • Export conversations

Content:

Requirements

  • python
  • git
  • ffmpeg (only if you are using whisper)

Bot commands

Commands available to every user are set automatically. However, there are some commands that are hidden:

/unlock <passwd> - Unlock bot functionalities with a password

Be careful with /history_update. History will be recreated, removing ownership and moving the ownsership to admin1 (if multiple admins are present, to the first one)

In order to use inline queries, you need to enable them in @BotFather. For ease of use, use the placeholder

type text

Type can be query or image.

Run

  • Install python dependencies.

    $ pip install -r requirements.txt

    If you want to contribute, install development dependencies as well.

    $ pip install -r dev_requirements.txt
  • Create a self-signed certificate in order to communicate with telegram server using SSL.

    $ openssl req -newkey rsa:2048 -sha256 -nodes -keyout config/nginx.key -x509 -days 3650 -out config/nginx.pem
  • Create a directory named config to store bot configuration files. Copy templates/config.json to config directory. Change values according to your configuration.

    $ mkdir config
    $ cp templates/config.json config/config.json

    config.json:

    • settings:

      • token - Telegram bot token, obtained from @BotFather.

      • webhook: true to run the bot using webhooks. false to use polling.

      • log_level: set level of the logging module.

      • ip: Your server/home IP. Must be accessible from internet.

      • port: Port to receive telegram updates. Allowed ports: 443, 80, 88 and 8443

        Nginx can be used as a reverse proxy in order to use other ports. Copy templates/nginx.conf to config and change values according to your configuration.

        • <docker-host-ip> is the gateway of the container. Similar to 172.17.0.1
        • <portX> Can be any port in the user range.
        $ cp templates/nginx.conf config/nginx.con
        $ docker run --rm --name nginx --net host -v ./config/nginx.conf:/etc/nginx/nginx.conf:ro -v ./config/nginx.key:/etc/nginx/nginx.key:ro -v ./config/nginx.pem:/etc/nginx/nginx.pem:ro nginx
      • cert: Path to your server certificate (can be self-signed).

        Warning: If you're using a verified certificate, you may receive "certificate verify failed" error. Leave cert path empty in your config.json

    • apis:

      • openai: OpenAI token to use with whisper (ASR), chatgpt/chatgpt4 and Dall-E (image generation).
      • assemblyai: AssemblyAI token (ASR).
    • chats:

      • password: Password to use with /unlock and gain access to the bot (only required for the first time).

        "password": "supersecurepassword123"
      • id: List of telegram IDs allowed in the bot, without password. Obtain if from bots like @getmyid_bot.

        "id": [
            123123123,
            132322322
        ]
      • admin: List of telegram IDs allowed retrieve and update configuration files, i.e. config.json, cookies.json.

        "admin": [
            123123123
        ]
      • 🆕 remove_chats_on_stop: true/false delete/keep chats after bot stop/restart (⚠️ WARNING ⚠️: chats retrieved from Bing with /history_update will be deleted as well if you enable this feature).

      • 🆕 history: true/false to enable/disable chat history.

    • cookies: List of file paths to cookies

      "cookies": [
          "config/cookies.json",
          "config/cookies2.json"
      ]
  • Run the bot.

    $ chmod +x src/edge.py
    $ src/edge.py

    Note: If you run the bot in port 80, it may be needed to run the bot as superuser (sudo)

Docker

Manual build

Build the image and bind config directory in the container.

$ docker build . -t edgegpt-telegram-bot --rm
$ docker run -d -it --name edgegpt -v ./config:/edgegpt/config edgegpt-telegram-bot

Dockerhub image

$ docker run -d -it --name edgegpt -v ./config:/edgegpt/config scmanjarrez/edgegpt-telegram-bot

docker-compose.yml file provided.

$ docker compose up -d

Contributing

Happy to see you willing to make the project better. In order to make a contribution, please respect the following format:

  • Sort imports with usort.

    $ usort format *py
  • Format your code using black (line length 79).

    $ black -l 79 *py

    If you are using flake8, add E203 to .flake8 ignore list

    [flake8]
    extend-ignore = E203
    

Pre-commit hooks

Installation

$ pre-commit install

Manual execution

$ pre-commit run --all-files

VSCode project settings

VSCode should have the following settings in settings.json:

{
    "python.analysis.fixAll": [],
    "python.formatting.blackArgs": [
        "-l 79"
    ],
    "python.formatting.provider": "black",
    "isort.path": [
        "usort format"
    ],
}

If you use flake8, add:

"python.linting.flake8Args": [
    "--ignore=E203",
],

Contributors

Support me

You find this bot helpful and want to support me?

Ko-fi link to support me

License

Copyright (c) 2023 scmanjarrez. All rights reserved.
This work is licensed under the terms of the MIT license.

For a copy, see LICENSE.