kopia lustrzana https://codeberg.org/pluja/openai-telegram-bot
![]() |
||
---|---|---|
piper | ||
.gitignore | ||
Dockerfile | ||
README.md | ||
database.py | ||
docker-compose.yml | ||
entrypoint.sh | ||
example.env | ||
main.py | ||
requirements.txt | ||
utils.py |
README.md
OpenAI API Telegram Bot
A telegram bot to interact with OpenAI API. You can:
- Generate images with DALL-E:
/imagine
- Chat with ChatGPT: Just chat!
- Transcribe audio and video to text: Just send a voice message or a video file!
- Voice chat with ChatGPT:
- Send voice message.
- Receive voice messages.
- Use 100% local Text-To-Speech with Language Recognition to give ChatGPT a voice in many languages!
Other features include:
- Talk to ChatGPT with audio transcriptions (whisper).
- Clear ChatGPT context history (to save tokens).
- Reply to any message to use it as context for ChatGPT.
- Per-user context.
- See usage metrics and spent $.
- Persistent data with sqlite3 database.
- Lightweight: few lines of code.
Self-hosting
Self hosting this chatbot is pretty easy. You just need to follow this steps:
-
Get your OPENAI Token from here.
- You will need to set a payment method.
-
Generate a new bot:
- Start a new chat with @BotFather bot.
- Type
/newbot
command. Set a name and a username. - Copy the Token that BotFather will give you.
-
Get allowed users' IDs:
- Start a new chat with @RawDataBot.
- Send a message or forward a message from any desired user.
- Copy the
message.from.id
field value. Should be an ID like: 1234567890
-
Setup the bot:
- Clone this repo.
- Rename the
example.env
file to.env
. - Edit the environment variables from the
.env
file:- Set your OPENAI_TOKEN.
- Set your BOT_TOKEN.
- Set your ALLOWED_USERS (comma separated user ids). Set it to
*
to allow all users. - Set the SYSTEM_PROMPT for ChatGPT. This is always instructed to ChatGPT as the system.
- Optional: Edit the MAX_CONTEXT. This variable sets the number of messages that will be sent to ChatGPT API as context for the conversation.
- WHISPER_TO_GPT allows you to choose wether Whisper transcripts should be instructed to ChatGPT or not.
- You can also configure this using
/settings
in chat.
- You can also configure this using
- ENABLE_GOOGLE_TTS the TTS service will be provided by GoogleTTS, producing more natural voices. If disabled, it fallsback to local voice generation using Espeak.
- VOICE_LANGUAGE country code for the default voice accent.
- Build and start the bot:
docker compose up --build -d
.
-
Enjoy!
Usage
-
By simply sending normal chat messages, you will be interacting with ChatGPT.
- The last 5 messages (from user and bot) are sent to ChatGPT API as context.
- Use the command
/clear
to clear your context and start over a completely new chat.
-
By using the
/imagine <prompt>
command, you will be getting images generated by DALL-E.- Example:
/imagine A cat with a red hat
.
- Example:
-
Sending a voice message to the bot, it will transcribe it to text using Whisper.
-
Using
/setttings
you can configure a few settings. -
/info
command allows you to see your usage statistics.