An open API service indexing awesome lists of open source software.

https://github.com/asimpleidea/kube-scraper-telegram-bot

A Kubernetes telegram bot implement with gRPC, listening for messages to send from the cluster.
https://github.com/asimpleidea/kube-scraper-telegram-bot

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# 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](https://github.com/SunSince90/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](https://k3s.io/).

## Get it

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

## Build it

```bash
make build
```

## Example

```bash
./bot
-- 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](https://core.telegram.org/bots#6-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

```bash
make docker-build docker-push IMG=
```

### Create the namespace

Skip this step if you already have this namespace, i.e. if you already did this
for the [Kube Scraper Backend](https://github.com/SunSince90/kube-scraper-backend).

```bash
kubectl create namespace kube-scraper
```

### Create the telegram token secret

Get the token generated by the
[BotFather](https://core.telegram.org/bots#6-botfather) and run

```bash
kubectl create secret generic telegram-token \
--from-literal=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:

```bash
kubectl create secret generic firebase-project-id \
--from-literal=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:

```bash
kubectl create secret generic gcp-service-account \
--from-file=service-account.json= \
-n kube-scraper
```

### Create the firestore chats collection

```bash
kubectl create configmap chats-config \
--from-literal=firestore.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:

```bash
kubectl create configmap bot-texts \
--from-file=./texts.yaml \
-n kube-scraper
```

### Create the deployment

```bash
kubectl create deploy/deployment.yaml
```