Code Monkey home page Code Monkey logo

chatgpt_telegram_bot's Introduction

chatgpt_telegram_bot

News

  • v1.31 19 Mar 2023 - Add VOICE_LIMIT_DURATION_SEC to configs for limitation duration of voice messages, please check config_template.py and update config.py
  • v1.30 19 Mar 2023 - Add telegram commands to post_init(). Run the bot in async mode. Bugfixes, improvements. Please reinstall requirements.txt. Add logging to files.
  • v1.21 15 Mar 2023 - Add /retry command to regenerate last bot answer.
  • v1.20 15 Mar 2023 - Add balances logic. Add checking negative token balance. Add FREE_TOKENS after registration. Use async openai API requests. DB migration. Improvement. Add commands: /balance, /addbalance. Update commands: /help, /setrole.
  • v1.11 14 Mar 2023 - Use ParseMode.MARKDOWN for Code Assistant mode, minor fixes and improvements.
  • v1.10 14 Mar 2023 - Support voice messages. (To work, you need to install this package: sudo apt-get install -y ffmpeg).
  • v1.00 14 Mar 2023 - Support /mode command. You can select from 3 special chat modes: General Assistant, Code Assistant, Translation Assistant. The modes work with/without context. To enable context just use /contexton command. By default the context is disabled.
  • v0.19 14 Mar 2023 - Stylized bot answers with emoji. Add tables user.total_tokens and user_message.total_tokens and save total_tokens in user_message.total_tokens.
  • v0.18 12 Mar 2023 - Refactoring & bugfixes.
  • v0.17 11 Mar 2023 - Handle Edit events at telegramm.

HOWTO setup

sudo apt-get update && sudo apt-get install -y ffmpeg

git clone [email protected]:bilabon/chatgpt_telegram_bot.git
cd chatgpt_telegram_bot
python3.11 -m venv .env && source .env/bin/activate
pip --no-cache-dir install -U pip && pip --no-cache-dir install -U setuptools && pip --no-cache-dir install -U wheel
pip --no-cache-dir install -U -r requirements.txt
cp settings/config_template.py settings/config.py

And now you neet to set BOT_TOKEN, AI_TOKEN, ADMIN_USERNAME in settings/config.py

Info

  • Each user who contacts the chat for the first time will be added to the database and assigned the role of alien. There are four roles in the bot: admin, client, alien and blocked. To communicate with ChatGPT, a user needs to have the role of admin or client.
  • A user with the role of admin can assign roles to other users, for example: /setrole username client.
  • The command /list will show all users (id and username). This command is only available for users with the role of admin.
  • The command /context on will turn on the context support. Example.
  • The command /context off will turn off the context support.
  • The command /mode – will show chat modes. You can select from 3 special chat modes: General Assistant, Code Assistant, Translation Assistant.
  • The command /retry - will regenerate last bot answer.

pic1

pic2

Configure command hints (optional, but fancy)

At @BotFather, use command /mybots -> select your bot -> Edit Bot -> Edit Commands. Then paste the following text to the BotFather:

retry - Regenerate last bot answer
mode - Select chat mode
contexton - Messaging with context
contextoff - Messaging without context
balance - Show balance
help - Show help

After that, you will be able to utilize menu shortcuts or receive prompts while entering commands.

Commands for deploying to https://fly.io

brew install flyctl
flyctl auth signup
# https://www.youtube.com/watch?v=J7Fm7MdZn_E
flyctl launch
flyctl deploy

# how to download db from remote container https://www.autodidacts.io/backup-ghost-on-fly-sftp/
flyctl ssh sftp shell -r -a tbot
get /bot/db.sqlite

# how to connect to remote console https://fly.io/docs/flyctl/ssh-console/
flyctl ssh console -s tbot

# how to restart the remote app, you should do it because after deploying sometimes run 2 instances and you get an error
flyctl apps restart tbot

# to stop app:
# https://community.fly.io/t/is-it-possible-to-disable-an-app-without-deleting-it/3662/2
flyctl scale count 0
fly status --all
fly vm stop e2dc2b0c

# to start app:
flyctl scale count 1

chatgpt_telegram_bot's People

Contributors

bilabon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chatgpt_telegram_bot's Issues

Help

First of all congrats.
How do i run the bot? shall i type "python main.py"?
plus, i'm not sure whether i have to create a second config.py in the folder settings and set BOT_TOKEN, AI_TOKEN, ADMIN_USERNAME in that second file? Or should i just replace those value in the config.py you created.
I got confused because in the file you wrote " # You need to create config.py and set all these variables there", then on your github main page you don't mention to create a second config.py.
Can you explain?
Thanks

Help #2

Hi i'm having issue with this command: cp settings/config_template.py settings/config.py
So this is how my config.py looks like:
config
this is how my config_template.py looks like:
template
This is what's in the settings folder:
image_2023-03-14_123603649
So my issue is when i run the following command: cp settings/config_template.py settings/config.py, i get this error:

image_2023-03-14_123802452

The name folder is correct, the files name are correct. Can you help me understand what's wrong?
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.