Skip to content

A Kubernetes telegram bot implement with gRPC, listening for messages to send from the cluster.

Notifications You must be signed in to change notification settings

asimpleidea/kube-scraper-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kube Scraper Telegram Bot

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.

Kube Scraper project

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.

Kubernetes nature

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.

Get it

git clone https://github.com/SunSince90/kube-scraper-telegram-bot.git
cd kube-scraper-telegram-bot

Build it

make build

Example

./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.

Build and push the image

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>

Create the namespace

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

Create the telegram token secret

Get the token generated by the BotFather and run

kubectl create secret generic telegram-token \
--from-literal=token=<token> \
-n kube-scraper

Create the project id secret

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

Create the service account secret

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

Create the firestore chats collection

kubectl create configmap chats-config \
--from-literal=firestore.chats-collection=<chats-collection> \
-n kube-scraper

Create the texts config map

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

Create the deployment

kubectl create deploy/deployment.yaml

About

A Kubernetes telegram bot implement with gRPC, listening for messages to send from the cluster.

Resources

Stars

Watchers

Forks

Packages