This a Telegram bot that lets you chat with ChatGPT. This bot is created using reverse engineering from the ChatGPT internal backend request to use the internal API endpoint. The Telegram bot is deployed in completely serverless in AWS Lambda. No need to setup a local server or do login in the browser.
- Voice messages support! 🔥
- Markdown rendering support.
- Fully automated token refresh in the AWS Lambda.
- Conversation reset with
/reset
command.
- Create an OpenAI account.
- Create an AWS account.
- Setup your Telegram bot. You can follow this instructions to get your token.
- Get your internal session token for ChatGPT:
- For this go to ChatGPT
- Press F12, click on
session
and copy the contents of__Secure-next-auth.session-token
.
- To enable support for voice messages you need to create a S3 bucket in your AWS account.
- Go to the top search bar and write
S3
.
- Click the Create Bucket button.
- Configure the creation of your bucket. The name must be unique worldwide. Scroll to bottom and click Create Bucket and don't change any other configuration.
- Go to
.chalice/config.json
and stablish the configurations:
TELEGRAM_TOKEN
with your Telegram token.CHATGPT_SESSION_TOKEN
with the value of your ChatGPT Token. LeaveCHATGPT_TOKEN
empty, it will be filled automatically by the function.VOICE_MESSAGES_BUCKET
with the bucket name you created previously.
- Install Python using pyenv or your prefered Python installation.
- Create a virtual environment:
python3 -m venv .venv
. - Activate you virtual environment:
source .venv/bin/activate
. - Install dependencies:
pip install -r requirements.txt
. - Install the AWS CLI and configure your credentials.
- Run
chalice deploy
. - Go to the AWS Console -> Lambda -> chatgpt-telegram-bot-dev-message-handler-lambda -> Configuration -> Function URL.
- Click Create Function URL and set Auth type to NONE.
- Copy the created function URL.
- Stablish your Telegram webhook to point to you AWS Lambda running
curl --request POST --url https://api.telegram.org/bot<YOUR_TELEGRAM_TOKEN>/setWebhook --header 'content-type: application/json' --data '{"url": "<YOUR_FUNCTION_URL"}'
Great! Everything is setup :) Now go to Telegram and find your bot name and use ChatGPT from there!
- Decoupled Token refresh in conversation.
- Increase response performance.
- Error handling from ChatGPT services.
- Deploy solution with one-click using CloudFormation.