A telegram bot living inside Kubernetes - but can also run locally, if you want - that listens for messages sent by users and based on what the user write, it updates a backend accordingly.
If you'd like to include this in your project please be aware that I will no be giving no warranty about its functionalities. You are more than welcome to open issues, discussions, ask for help and make pull requests if you'd like to.
This is a small project and is part of Kube Scraper. It is a personal project, to improve my skills and learn some new programming patterns and technologies.
In the Kube Scraper project, the telegram bot is in charge of getting new chats and storing them on a backend, so that scrapers can get the list of users to send a message to. For example, they can notify users about a change in website page they were scraping.
The program is meant to run in Kubernetes and a deployment yaml file is also
provided under /deploy
, along with instructions on how to run it on your
cluster.
As stated above, this project serves as a good exercise for me and it is currently running in a cluster of Raspberry Pis running k3s.
git clone https://github.com/SunSince90/kube-scraper-telegram-bot.git
cd kube-scraper-telegram-bot
make build
./bot
-- token <telegram-token> \
--redis-address 10.10.10.10:6379
Some description about the command above:
--token
is the telegram bot token, as provided by the BotFather--redis-address
is the address where redis is running--redis-topic
is the name of the topic -- or channel -- where to send notifications, if you want to send them.
Please note that the image that is going to be built will run on ARM, as it
will run on a Raspberry Pi. Make sure to edit the Dockerfile
in case you want
to build for another architecture.
Login to your repository and
make docker-build docker-push IMG=<image>
Skip this step if you already have this namespace, i.e. if you already did this for the Kube Scraper Backend.
kubectl create namespace kube-scraper
Get the token generated by the BotFather and run
kubectl create secret generic telegram-token \
--from-literal=token=<token> \
-n kube-scraper
Skip this if you already have this secret in your cluster.
Get the project id
from your firebase console and run:
kubectl create secret generic firebase-project-id \
--from-literal=project-id=<your-project-id> \
-n kube-scraper
Skip this if you already have this secret in your cluster. Get the service account from your firebase console (or from gcp) and run:
kubectl create secret generic gcp-service-account \
--from-file=service-account.json=<path-to-your-service-account> \
-n kube-scraper
kubectl create configmap chats-config \
--from-literal=firestore.chats-collection=<chats-collection> \
-n kube-scraper
Create a yaml file that looks like texts.yaml
, included in the root folder of the project.
Change the texts according to your needs.
Then, run this from the root folder of the project:
kubectl create configmap bot-texts \
--from-file=./texts.yaml \
-n kube-scraper
kubectl create deploy/deployment.yaml