mkdryden / telegram-stats-bot

A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.
GNU General Public License v3.0
53 stars 20 forks source link

Question: how can i use this for multiple chats? #24

Closed Mrs-Feathers closed 11 months ago

Mrs-Feathers commented 1 year ago

i'm using the docker version and its great for my community's general chat, but we have like ~30+ different topic chats and i need to get statistics on a few of them at the same time so i can better plan community events and stuff by seeing times people are active etc... how can i do this? should i list the CHAT_IDs? like -100XXXXXXX, -100XXXXXXX or should i copypaste the docker compose to run two bots on the same database?

Mrs-Feathers commented 1 year ago

in postgres i figured out using

myapp-postgresql: image: postgres:9.6.2 volumes:

allows me to use different databases in postgres, but running a couple instances of the bot for each room cause a weird update error, and i wasn't able to do that list with CHAT_ID

mkdryden commented 1 year ago

Currently there is not a way to make one bot instance handle multiple chats. It was always on the list, but I've been quite busy lately and haven't had the chance to look at it (and there are some changes to the Telegram bot API I need to double check). As far as I know, there should be no problem in using the same Postgres, but you need to make sure each bot service is pointing to the correct database (with the POSTGRES_DB environment var), so you might have:

  bot1:
    image: mkdryden/telegram-stats-bot:master
    depends_on:
      - db
    environment:
      TZ: "America/Toronto"
      BOT_TOKEN: 111111111:AAA-MpBVQ7i2cIRfwedfsfesdg6webc0r-Y
      CHAT_ID: 0
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_HOST: db
      POSTGRES_DB: telegram_bot_1
  bot2:
    image: mkdryden/telegram-stats-bot:master
    depends_on:
      - db
    environment:
      TZ: "America/Toronto"
      BOT_TOKEN: 111111111:AAA-MpBVQ7i2cIRfwedfsfesdg6webc0r-Y
      CHAT_ID: 0
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_HOST: db
      POSTGRES_DB: telegram_bot_2

From your config, I assume you are using the init script from here. Postgres 9.6 is probably too old to be supported, I think you need at least 12. I didn't look that close, but the script will probably work with later versions too.

Mrs-Feathers commented 1 year ago

ive got this working, however using the same bot token for multiple bots gave weird results so i had to create a new bot for each of my 30 chats, which is a bit excessive but it works for now

Mrs-Feathers commented 1 year ago

as a side note, you get banned from botfather for 24 hours every 5th new bot you make within an hour. so a multiple group function would be a lot more efficient