Template for Telegram bots written in TypeScript
If you haven't written TypeScript before, don't be scared of it. It is nearly the same as JavaScript. But it provides more helpful information before something goes wrong during the runtime.
I learned a lot about JavaScript itself when I started diving into TypeScript.
npm installWrite to the @BotFather on Telegram and create your bot.
You will get a token that looks like this: 123:abc.
Use it as an environment variable (for example via .env file or export BOT_TOKEN=123:abc).
Tip: When you create a separate bot for your development you can use production and development in parallel.
The bot stores persistent data within the persist folder.
So also create this folder before starting it for the first time.
mkdir persistThen go ahead and start the bot
npm startSee the Dockerfile. You can build a container using it. But this repo isn't about containers. For more information about them, take a look elsewhere.
The container is meant to be used with an environment variable named BOT_TOKEN.
The container has one volume (/app/persist) which will contain persistent data your bot creates.
Make sure to explicitly use that volume (for example, make sure it's synced or tied to the host in a multi-node setup).
sourcecontains your TypeScript source files. Subfolders contain specifics about your implementationbotmay contain files relevant for the telegram botmenumay contain specifics about the bot, the menu that is shown on /start
magicmay contain something relevant for doing magic. It is not relevant to the bot directly, but it is used by it.
localescontains translation strings for your bot. That way it can speak multiple languages.distwill contain transpiled JavaScript files.persistwill contain persistent data your bot uses. Make sure to keep that data persistent (Backups for example).
Do you think something is missing? Feel free to add it. Then everyone can learn that even easier than before :)