Phone Number to Telegram Proxy

A service that allows sending messages to Telegram users by specifying their phone numbers.
Table of Contents
Features
- Phone Number to Telegram Proxy: Send messages to Telegram users by specifying their phone number
- State Management: Finite State Machine (FSM) for handling bot interactions
- Secure Storage: Phone numbers are hashed for security
- Modular Architecture: Well-structured components for maintainability
- Dependency Injection: Using Uber FX for better testability
- Internationalization (i18n): Multi-language support with English and Russian translations
Installation
Prerequisites
- Redis server
- Telegram Bot Token
Using Pre-built Binaries (Recommended)
- Go to the GitHub Releases page
- Download the pre-built binary for your operating system and architecture
- Make the binary executable:
chmod +x phone2tg-proxy-linux-amd64
- Run the binary:
./phone2tg-proxy-linux-amd64
Using Docker (Recommended)
- Pull the latest image:
docker pull ghcr.io/capcom6/phone2tg-proxy:latest
- Run the container:
docker run -d \
--env HTTP__ADDRESS=0.0.0.0:3000 \
--env TELEGRAM__TOKEN=your_telegram_bot_token \
--env REDIS__URL=redis://localhost:6379/0 \
--env STORAGE__SECRET=your_storage_secret \
--publish 3000:3000 \
--name phone2tg-proxy \
ghcr.io/capcom6/phone2tg-proxy:latest
From Source (Alternative)
-
Clone the repository:
git clone https://github.com/capcom6/phone2tg-proxy.git
cd phone2tg-proxy
-
Download dependencies:
go mod download
-
Build and run:
go run main.go
Configuration
The service can be configured using environment variables or a configuration file.
Environment Variables
| Variable |
Description |
Default |
HTTP__ADDRESS |
HTTP server address |
127.0.0.1:3000 |
HTTP__PROXY_HEADER |
HTTP proxy header |
X-Forwarded-For |
HTTP__PROXIES |
Trusted proxy IPs/CIDRs (JSON array) |
[] |
HTTP__OPENAPI__ENABLED |
Serve the OpenAPI document and Swagger UI |
true |
HTTP__OPENAPI__PUBLIC_HOST |
Host written into the served spec |
empty (taken from request) |
HTTP__OPENAPI__PUBLIC_PATH |
Base path written into the served spec |
empty (keeps /api/v1) |
TELEGRAM__TOKEN |
Your Telegram bot token |
Required |
TELEGRAM__PROXY_URL |
SOCKS5 proxy for Telegram |
empty |
TELEGRAM__TIMEOUT |
Telegram API request bound (dial + response) |
30s |
REDIS__URL |
Redis connection URL |
redis://localhost:6379/0 |
STORAGE__SECRET |
Secret for phone number hashing |
Required |
I18N__DEFAULT_LANGUAGE |
Default language |
en |
I18N__TRANSLATIONS_PATH |
Translations path |
i18n/locales |
DEBUG |
Development logger (process environment only) |
false |
Notes on HTTP__PROXIES (format):
- The value is a JSON array of IP addresses or CIDR ranges, for example
["10.0.0.1","10.0.0.0/8"]. A
comma-separated list is not parsed - it arrives as a single malformed entry. Use [] to trust no proxy.
Notes on DEBUG (scope):
- The logger reads
DEBUG from the process environment, not from the .env file - the .env file is only
parsed into the app config and is never exported into the environment. Export it in the shell
(DEBUG=1 go run .) or use make air, which sets it.
Configuration File
Create a .env file in the project root with your configuration:
TELEGRAM__TOKEN=your_telegram_bot_token
REDIS__URL=redis://localhost:6379/0
STORAGE__SECRET=your_storage_secret
Usage
Using the API
The service provides a REST API for sending messages. See the API Documentation for details.
Using the Telegram Bot
- Start a chat with your bot
- Send
/start to register your phone number
- Send your contact to associate your phone number with your Telegram account
- You can now use this bot to send messages to registered users by providing their phone numbers.
API Documentation
The service provides a REST API for sending messages.
Endpoints
Send Message
Health Endpoints
The service exposes four probe endpoints for orchestrators and load balancers. All of them return the same
envelope and never include configuration values, tokens, secrets, or phone numbers.
- URLs: all four are
GET:
GET /health - liveness probe
GET /health/live - liveness probe
GET /health/ready - readiness probe
GET /health/startup - startup probe
- Status code contract:
200 OK unless the overall status is fail, in which case
503 Service Unavailable. A warn overall status is still 200 OK.
- Response:
{
"status": "pass",
"version": "dev",
"checks": {
"system:goroutines": {
"description": "Number of goroutines",
"observedUnit": "goroutines",
"observedValue": 5,
"status": "pass"
}
}
}
- Response keys: top level is limited to
status, version, releaseId, and checks; each entry under
checks is limited to description, observedUnit, observedValue, and status. Both releaseId and
checks are omitted when empty.
Notes on the current build:
version is always dev and releaseId is always absent. The release linker flags in
.goreleaser.yaml are -s -w only, so no version or build number is injected at compile time. A real
version has to be injected before release builds can report one.
/health and /health/live carry system:goroutines, system:memory and telegram:api. The
built-in system provider escalates to warn above 100 goroutines or 128 MiB of allocated heap. Because
warn maps to 200 OK, a small container under load shows warn in the body without affecting
availability.
telegram:api is the polling-loop watchdog (telegofx WithHealth). It reports seconds since the
last completed getUpdates request (-1 before the first one) and turns fail once three HTTP
client timeouts pass without a completion - 90 s with the default TELEGRAM__TIMEOUT. That silence
is the signature of a stalled getUpdates loop, which produces no log line of its own. The heartbeat
is scoped to the receive loop: sends and other Bot API calls do not refresh it, so outbound traffic
cannot mask a stalled poll. fail maps to 503 on liveness. The image HEALTHCHECK marks the
container unhealthy after three consecutive failures: a health-aware orchestrator (for example
Docker Swarm) restarts the task from that state, while a standalone docker run container without
a restart policy is only marked unhealthy. The probe always requests port 3000, so image
deployments must keep HTTP__ADDRESS on port 3000 as in the docker run example above - any
other port makes a healthy service report unhealthy. External Telegram outages stay 200, because
failed getUpdates still complete and refresh the timestamp.
/health/ready and /health/startup report no checks and therefore always answer 200 OK with no
checks object: no provider is registered for readiness or startup.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Push to the branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.