Skip to content

Commit

Permalink
First implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
igolaizola committed Jul 2, 2023
1 parent 811f96a commit 1c2002b
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 6 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Build
run: go build -v ./...
- name: Lint
uses: golangci/golangci-lint-action@v3
- name: Test
run: go test -v ./...
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin

# Test binary, built with `go test -c`
*.test
Expand All @@ -17,5 +15,8 @@
# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
# Other
.history
.vscode
*.conf
*.session
14 changes: 14 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
builds:
- id: tgfwd
binary: tgfwd
main: ./cmd/tgfwd
goarch:
- amd64
- arm64
- arm
archives:
- id: tgfwd
builds:
- tgfwd
format: zip
name_template: 'tgfwd_{{ .Version }}_{{- if eq .Os "darwin" }}macos{{- else }}{{ .Os }}{{ end }}_{{ .Arch }}'
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# builder image
FROM golang:alpine as builder
ARG TARGETPLATFORM
COPY . /src
WORKDIR /src
RUN apk add --no-cache make bash git
RUN make app-build PLATFORMS=$TARGETPLATFORM

# running image
FROM alpine
WORKDIR /home
COPY --from=builder /src/bin/tgfwd-* /bin/tgfwd

# executable
ENTRYPOINT [ "/bin/tgfwd" ]
74 changes: 74 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

SHELL = /bin/bash
PLATFORMS ?= linux/amd64 darwin/amd64 windows/amd64
IMAGE_PREFIX ?= igolaizola
REPO_NAME ?= tgfwd
COMMIT_SHORT ?= $(shell git rev-parse --verify --short HEAD)
VERSION ?= $(COMMIT_SHORT)
VERSION_NOPREFIX ?= $(shell echo $(VERSION) | sed -e 's/^[[v]]*//')

# Build the binaries for the current platform
.PHONY: build
build:
os=$$(go env GOOS); \
arch=$$(go env GOARCH); \
PLATFORMS="$$os/$$arch" make app-build

# Build the binaries
# Example: PLATFORMS=linux/amd64 make app-build
.PHONY: app-build
app-build:
@for platform in $(PLATFORMS) ; do \
os=$$(echo $$platform | cut -f1 -d/); \
arch=$$(echo $$platform | cut -f2 -d/); \
arm=$$(echo $$platform | cut -f3 -d/); \
arm=$${arm#v}; \
ext=""; \
if [ "$$os" == "windows" ]; then \
ext=".exe"; \
fi; \
file=./bin/$(REPO_NAME)-$(VERSION_NOPREFIX)-$$(echo $$platform | tr / -)$$ext; \
GOOS=$$os GOARCH=$$arch GOARM=$$arm CGO_ENABLED=0 \
go build \
-a -x -tags netgo,timetzdata -installsuffix cgo -installsuffix netgo \
-ldflags " \
-X main.Version=$(VERSION_NOPREFIX) \
-X main.GitRev=$(COMMIT_SHORT) \
" \
-o $$file \
./cmd/$(REPO_NAME); \
if [ $$? -ne 0 ]; then \
exit 1; \
fi; \
chmod +x $$file; \
done

# Build the docker image
# Example: PLATFORMS=linux/amd64 make docker-build
.PHONY: docker-build
docker-build:
rm -rf bin; \
@platforms=($(PLATFORMS)); \
platform=$${platforms[0]}; \
if [[ $${#platforms[@]} -ne 1 ]]; then \
echo "Multi-arch build not supported"; \
exit 1; \
fi; \
docker build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi

# Build the docker images using buildx
# Example: PLATFORMS="linux/amd64 darwin/amd64 windows/amd64" make docker-buildx
.PHONY: docker-buildx
docker-buildx:
@platforms=($(PLATFORMS)); \
platform=$$(IFS=, ; echo "$${platforms[*]}"); \
docker buildx build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .

# Clean binaries
.PHONY: clean
clean:
rm -rf bin
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,111 @@
# tgfwd
Telegram message forwarder

Telegram message forwarder.

Use this tool to forward messages from one Telegram chat to another.
All type of chats are supported: private chats, groups, channels, supergroups, etc.

## 📦 Installation

You can use the Golang binary to install **tgfwd**:

```bash
go install github.com/igolaizola/tgfwd/cmd/tgfwd@latest
```

Or you can download the binary from the [releases](https://github.com/igolaizola/tgfwd/releases)

## 🛠️ Requirements

Obtain your Telegram App ID and App Hash by following this guide https://core.telegram.org/api/obtaining_api_id

## 🕹️ Usage

### Login command

Use the `login` command to login to your Telegram account and generate a session file:

```bash
tgfwd login --hash app-hash --id app-id --session file.session --phone phone-number
```

The phone number must be in the international format (e.g. +34666666666)

### List chats command

Use the `list` command to list your Telegram chats and obtain their IDs:

```bash
tgfwd list --hash app-hash --id app-id --session file.session
```

Use this command to find out the ID of the chats from which you want to forward messages and to which you want to forward them.

### Forward messages command

Use the `run` command to forward telegram messages from one chat to another:

```bash
tgfwd run --hash app-hash --id app-id --session file.session \
--fwd from-chat-id-1:to-chat-id-2 \
--fwd from-chat-id-3:to-chat-id-4
```

You can use the `--fwd` flag multiple times to forward messages using different chats.

### Configuration file

Instead of passing the parameters to the command, you can use a configuration file:

```bash
tgfwd run --config tgfwd.conf
```

An example configuration file `tgfwd.conf`:

```
debug true
hash app-hash
id app-id
session tgfwd.session
fwd 10000001:10000002
fwd 10000003:10000004
```

## 💖 Support

If you have found my code helpful, please give the repository a star ⭐

Additionally, if you would like to support my late-night coding efforts and the coffee that keeps me going, I would greatly appreciate a donation.

You can invite me for a coffee at ko-fi (0% fees):

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/igolaizola)

Or at buymeacoffee:

[![buymeacoffee](https://user-images.githubusercontent.com/11333576/223217083-123c2c53-6ab8-4ea8-a2c8-c6cb5d08e8d2.png)](https://buymeacoffee.com/igolaizola)

Donate to my PayPal:

[paypal.me/igolaizola](https://www.paypal.me/igolaizola)

Sponsor me on GitHub:

[github.com/sponsors/igolaizola](https://github.com/sponsors/igolaizola)

Or donate to any of my crypto addresses:

- BTC `bc1qvuyrqwhml65adlu0j6l59mpfeez8ahdmm6t3ge`
- ETH `0x960a7a9cdba245c106F729170693C0BaE8b2fdeD`
- USDT (TRC20) `TD35PTZhsvWmR5gB12cVLtJwZtTv1nroDU`
- USDC (BEP20) / BUSD (BEP20) `0x960a7a9cdba245c106F729170693C0BaE8b2fdeD`
- Monero `41yc4R9d9iZMePe47VbfameDWASYrVcjoZJhJHFaK7DM3F2F41HmcygCrnLptS4hkiJARCwQcWbkW9k1z1xQtGSCAu3A7V4`

Thanks for your support!

## 📚 Resources

Some of the resources I used to create this project:

- [gotd/td](https://github.com/gotd/td)
Loading

0 comments on commit 1c2002b

Please sign in to comment.