Telegram Music Bot made with Serverless framework and Node.js in AWS.
Bot can be used to add music links to a queue, which then be periodically sent to Telegram channel.
Initial boilerplate generated with serverless framework by running npx serverless create -t aws-nodejs-typescript
.
Architecture diagram is created with diagrams python library. To update diagrams, install dependencies (graphviz
required to be installed in system globally) and run the python script:
python3 -m pip install -r docs/requirements.txt
(cd docs && python3 infra.py)
For the bot you need a channel to send scheduled messages to. Create a channel and grab its id.
-
You need to create a bot. More info here.
send a POST request to
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook
with body:{ "url": "<YOUR_LAMBDA_ENDPOINT>" }
More info about setWebook here.
-
Add bot to a channel as admin so it can send messages there.
-
Optionally you can use BotFather's commands to make your bot more appealing with added description, about text, user pic and commands.
Currently bot supports /start
, /about
and /q
commands. Bot is only handling private messages, everything else gets ignored (see src/functions/processMessages/handler.ts
).
You need following parameters to be stored in the same region as the application. Note that these should be set before the deployment and if you need to update them, redeployment is required:
telegram-music-bot-token
, as a secure stringtelegram-music-channel-id
, as a stringtelegram-music-cron-schedule
, as a string e.g.0 7 ? * MON-FRI *
telegram-music-bot-sentry-dsn
, as a secure string (optional)
npm ci
aws-vault exec <PROFILE> -- npm run deploy
In order to test the given function locally, run the following command:
aws-vault exec <PROFILE> -- npx serverless invoke local -f <FUNCTION_NAME> --path src/functions/<FUNCTION_NAME>/mock.json
Exceptions are sent to Sentry on top of them being stored in CloudWatch Logs.
functions
- containing code base and configuration for your lambda functionslibs
- containing shared code base between your lambdas