The repository contains the code for the Listen4Me bot. The bot is available on Telegram and WhatsApp and designed to transcribe audio messages to text.
Telegram bot: @Listen4Me
WhatsApp bot: @Listen4Me
The bot can be run on a local machine or deployed to a cloud platform. There is an option to run the bot only for one of the platforms (Telegram or WhatsApp) or for both of them.
There are several ways to run the bot locally:
git clone https://github.com/vlad324/listen4me-bot
pip install -r requirements.txt
.env
file in the root of the project and specify the following environment variables in it:OPEN_AI_API_KEY=your_open_ai_api_key
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_WEBHOOK_SECRET=first_random_string_generated_in_prerequisites_section
WA_API_KEY=api_key_of_your_whatsapp_app
WA_PHONE_NUMBER_ID=phone_number_id_of_your_whatsapp_app
WA_VERIFY_TOKEN=second_random_string_generated_in_prerequisites_section
If you plan to run the bot only for Telegram or WhatsApp, you can omit the corresponding variables. OPEN_AI_API_KEY
is required for both
platforms.
fastapi run app/main.py --port 8000
The bot will be waiting for webhooks at http://localhost:8000/telegram/l4me_bot/webhook
for Telegram
and http://localhost:8000/whatsapp/l4me_bot/webhook
for WhatsApp.
ngrok
, expose your local server to the internet:ngrok http 8000
curl -X POST --location "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{
"url": "<url_provided_by_ngrok>/telegram/l4me_bot/webhook",
"secret_token": "<first_random_string_generated_in_prerequisites_section>"
}'
<url_provided_by_ngrok>/whatsapp/l4me_bot/webhook
<second_random_string_generated_in_prerequisites_section>
.git clone https://github.com/vlad324/listen4me-bot
docker build -t listen4me-bot .
.env
file in the root of the project and specify the following environment variables in it:OPEN_AI_API_KEY=your_open_ai_api_key
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_WEBHOOK_SECRET=first_random_string_generated_in_prerequisites_section
WA_API_KEY=api_key_of_your_whatsapp_app
WA_PHONE_NUMBER_ID=phone_number_id_of_your_whatsapp_app
WA_VERIFY_TOKEN=second_random_string_generated_in_prerequisites_section
If you plan to run the bot only for Telegram or WhatsApp, you can omit the corresponding variables. OPEN_AI_API_KEY
is required for both
platforms.
docker run --env-file .env -p 8080:8080 listen4me-bot
ngrok
, expose your local server to the internet:ngrok http 8080
curl -X POST --location "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{
"url": "<url_provided_by_ngrok>/telegram/l4me_bot/webhook",
"secret_token": "<first_random_string_generated_in_prerequisites_section>"
}'
<url_provided_by_ngrok>/whatsapp/l4me_bot/webhook
<second_random_string_generated_in_prerequisites_section>
.The bot can be deployed to the fly.io platform. The platform provides a free tier for small applications and could be a good option to host your own instance of the bot.
flyctl
CLI tool by following the instructions onflyctl launch
flyctl secrets set OPEN_AI_API_KEY=<your_open_ai_api_key>
Telegram related secrets:
flyctl secrets set TELEGRAM_BOT_TOKEN=<your_telegram_bot_token> \
TELEGRAM_WEBHOOK_SECRET=<first_random_string_generated_in_prerequisites_section>
WhatsApp related secrets:
flyctl secrets set WA_API_KEY=<api_key_of_your_whatsapp_app> \
WA_PHONE_NUMBER_ID=<phone_number_id_of_your_whatsapp_app> \
WA_VERIFY_TOKEN=<second_random_string_generated_in_prerequisites_section>
If you plan to run the bot only for Telegram or WhatsApp, you can omit the corresponding secrets. OPEN_AI_API_KEY
is required for both
fly deploy
curl -X POST --location "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{
"url": "<url_provided_by_fly_io>/telegram/l4me_bot/webhook",
"secret_token": "<first_random_string_generated_in_prerequisites_section>"
}'
<url_provided_by_fly_io>/whatsapp/l4me_bot/webhook
<second_random_string_generated_in_prerequisites_section>
.To limit access to your version of the Telegram bot, you'll need to know your Telegram id or the Telegram ids of users you want to grant access to. Here's how to obtain this information:
Once you have the necessary ids, follow these steps to restrict access:
Add the following line to your .env
file:
TELEGRAM_ALLOWED_USER_IDS=<id_1,id_2,...>
Replace <id_1,id_2,...>
with a single Telegram ID or a comma-separated list of allowed Telegram IDs. For example:
TELEGRAM_ALLOWED_USER_IDS=123456789
TELEGRAM_ALLOWED_USER_IDS=123456789,987654321
Execute the following command:
flyctl secrets set TELEGRAM_ALLOWED_USER_IDS=<id_1,id_2,...>
Replace <id_1,id_2,...>
with the comma-separated list of Telegram IDs for users you want to allow access to your bot.
By setting this environment variable, you'll ensure that only specified users can interact with your Telegram bot.