#+Author: Maximo Tejeda #+Email: root@maximotejeda.com #+Date: 10/10/2024 * Telegram Bot Repository Template This README serves as a guide and template for setting up new Telegram bot projects. Follow the instructions below to get your bot up and running. ** Table of Contents - [[#introduction][Introduction]] - [[#prerequisites][Prerequisites]] - [[#setup-instructions][Setup Instructions]] - [[#clone-the-repository][Clone the Repository]] - [[#install-dependencies][Install Dependencies]] - [[#configure-your-bot][Configure Your Bot]] - [[#running-the-bot][Running the Bot]] - [[#Description][Description]] ** Introduction <> This repository contains a basic template for developing Telegram bots. It includes essential scripts, configuration files, and documentation to help you get started quickly. ** Prerequisites <> Before setting up your bot, ensure you have the following installed: - *go*: The go programming for running go code. - *Telegram Bot Token*: Obtain it by creating a new bot via [[https://t.me/botfather][BotFather]] on Telegram. ** Setup Instructions <> *** Clone the Repository To get started, clone this repository to your local machine: #+BEGIN_SRC bash git clone https://github.com/yourusername/telegram-bot-template.git cd telegram-bot-template #+END_SRC *** Install Dependencies Install all required dependencies using go tools: #+BEGIN_SRC bash go mod tidy #+END_SRC *** Configure Your Bot Create a ~.env~ file in the root directory and add your Telegram bot token: #+BEGIN_SRC plaintext #.env file example BOT_TOKEN=yout_bot_token_goes_here NATS_SERVICE_URL=natsuri:4222 TGBUSER_SERVICE_URL=localhost:3001 // needed to start svc ENV=development // define log level on start ADMINS=admin_ids_comma_separated // id for admins, those will not need auth RATE_LIMIT_SEC=12 // amount of time to limit hits in sec RATE_LIMIT_AMOUNT=2 // amount of hit limits in x times #+END_SRC ** Running the Bot <> To start the bot, execute one of the following commands If the .env Vars ar e in the environment is dafe to run: #+BEGIN_SRC bash go run cmd/bot/. #+END_SRC Else you can run though Makefile with target run-local The Makefile populate .env, build and run the source code, on each run the clean target will be called. #+begin_src bash make run-local #+end_src Your bot should now be running locally. ** Description <> This is a template Telegram bot designed to be shared across various projects. It includes ready-to-use handlers for commands or queries, serving as examples to simplify development. The bot is built using the current version of the [[https://github.com/go-telegram/bot][go-telegram/bot]] library, ensuring up-to-date functionality and integration. In the functions added for the template you can find things like: - Message Handlers - Command Handlers - Callback Query Handlers - Interactions Handlers - Middlewares - Singleflight - Loging - Rate Limiting - Auth Func - Helpers - Auth - File - Photo - Keyboard This template heavily relies on the **[[tgbuser]]** microservice for handling user authentication and permissions. As The current date theres still a TODO on the WebApp part of the bot for serving and templating an example for miniApps