1
0
Fork 0
Telegram bot to post messages from a Telegram group to Mastodon.
Go to file
Daniele Tricoli 37a52eda8a Rephrase better the long description 2022-03-13 03:15:51 +01:00
cfg Move all the configuration stuff into cfg package 2022-03-13 03:09:51 +01:00
cmd Rephrase better the long description 2022-03-13 03:15:51 +01:00
mastodon Decouple layers 🚀 2022-03-13 02:21:25 +01:00
utils Move DownloadFile into utils package 2022-03-13 03:14:52 +01:00
.dockerignore Add dockerignore 2022-03-11 20:15:39 +01:00
.drone.yml Test sub packages 2022-02-28 23:26:05 +01:00
.gitignore Ignore the compiled bot 2022-03-11 16:25:03 +01:00
Dockerfile Upgrade all the packages on the final stage 2022-03-11 19:10:21 +01:00
LICENSE Initial import 2022-02-27 02:00:26 +01:00
README.md Make possible to set an optional footer for toots 2022-03-13 00:30:41 +01:00
docker-compose.yml Add a docker-compose file 2022-03-11 20:15:26 +01:00
go.mod Decouple layers 🚀 2022-03-13 02:21:25 +01:00
go.sum Decouple layers 🚀 2022-03-13 02:21:25 +01:00
main.go Rename the project to telegram-group2mastodon 2022-03-05 03:51:35 +01:00

README.md

telegram-group2mastodon

telegram-group2mastodon is a Telegram bot to post messages from a Telegram group to Mastodon. It's written in Go and it is relased under the AGPL3+. Since the bot must be able to read all the messages you should use it only on public groups.

Installation

  1. Build the bot (for example if version is v0.1.0 and you are on a unix system):

    cd /tmp; GOPATH=/tmp/go go install noa.mornie.org/eriol/telegram-group2mastodon@v0.1.0
    

    You will find the binary at /tmp/go/bin/telegram-group2mastodon. You don't need to set GOPATH if you already have it set and you are fine having the bot installed there.

  2. Create your bot using Telegram @BotFather.

  3. The bot uses environment variables as configuration, you have to export the following (except variables with a default) before starting it:

    Variable Meaning Default
    MASTODON_ACCESS_TOKEN Mastodon access token N/A
    MASTODON_SERVER_ADDRESS Mastodon server address N/A
    MASTODON_TOOT_FOOTER Footer of each toot ""
    MASTODON_TOOT_MAX_CHARACTERS Toot max lenght 500
    MASTODON_TOOT_VISIBILITY Default toot visibility unlisted
    TELEGRAM_BOT_TOKEN Telegram bot token N/A
    TELEGRAM_CHAT_ID Telegram alolowed chat id N/A
    TELEGRAM_DEBUG Debug messages from Telegram False

    MASTODON_TOOT_VISIBILITY allowed values are: direct, private, public and unlisted. MASTODON_TOOT_FOOTER default is an empty string that disable the footer feature, no character ad automatically added so you may want to add a space before your footer (or a new line). To get MASTODON_ACCESS_TOKEN see next point.

  4. To get MASTODON_ACCESS_TOKEN use the subcommand authenticate:

    telegram-group2mastodon authenticate
    

    and follow the istructions.

  5. Launch the bot:

    telegram-group2mastodon run
    

Deploy using Docker/Podman

Images are automatically built after each push on quay.io, here the list of available tags: https://quay.io/repository/eriol/telegram-group2mastodon?tab=tags

docker

Suppose you want to use the latest tag.

docker run \
    --env MASTODON_ACCESS_TOKEN=$MASTODON_ACCESS_TOKEN \
    --env MASTODON_SERVER_ADDRESS=$MASTODON_SERVER_ADDRESS \
    --env TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN \
    --env TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID \
    quay.io/eriol/telegram-group2mastodon:latest

podman

Suppose you want to use the latest tag.

podman run \
    --env MASTODON_ACCESS_TOKEN=$MASTODON_ACCESS_TOKEN \
    --env MASTODON_SERVER_ADDRESS=$MASTODON_SERVER_ADDRESS \
    --env TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN \
    --env TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID \
    quay.io/eriol/telegram-group2mastodon:latest

docker-compose

---
version: "3.9"

services:
  bot:
    image: quay.io/eriol/telegram-group2mastodon:latest
    environment:
      - MASTODON_ACCESS_TOKEN=${MASTODON_ACCESS_TOKEN}
      - MASTODON_SERVER_ADDRESS=${MASTODON_SERVER_ADDRESS}
      - TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
      - TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}