phone2tg-proxy

command module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Phone Number to Telegram Proxy

License

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
  1. Go to the GitHub Releases page
  2. Download the pre-built binary for your operating system and architecture
  3. Make the binary executable:
    chmod +x phone2tg-proxy-linux-amd64
    
  4. Run the binary:
    ./phone2tg-proxy-linux-amd64
    
  1. Pull the latest image:
    docker pull ghcr.io/capcom6/phone2tg-proxy:latest
    
  2. 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)
  1. Clone the repository:

    git clone https://github.com/capcom6/phone2tg-proxy.git
    cd phone2tg-proxy
    
  2. Download dependencies:

    go mod download
    
  3. 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
  1. Start a chat with your bot
  2. Send /start to register your phone number
  3. Send your contact to associate your phone number with your Telegram account
  4. 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
  • URL: /api/v1/messages
  • Method: POST
  • Description: Send a message to a user by phone number. The phoneNumber must be in E.164 format. Validation failures will occur if the format is not followed.
  • Request Body:
    {
      "phoneNumber": "string (E.164 format, e.g., +1234567890)",
      "text": "string"
    }
    
  • Response:
    {
      "id": "integer"
    }
    
  • Error Responses:
    • 400 Bad Request: Invalid request format
    • 404 Not Found: Phone number not found
    • 500 Internal Server Error: Server error
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:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
bot
bot/handler
Package handler defines the contract every bot handler implements to mount its routes directly on the shared telegofx router.
Package handler defines the contract every bot handler implements to mount its routes directly on the shared telegofx router.
bot/handlers/start
Package start implements the /start onboarding handler.
Package start implements the /start onboarding handler.
bot/handlers/stop
Package stop implements the /stop command handler.
Package stop implements the /stop command handler.
server/docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
state
Package state provides the in-memory fsm.Storage backing the bot's conversation state.
Package state provides the in-memory fsm.Storage backing the bot's conversation state.
telegramtest
Package telegramtest provides the offline fake Bot API and SOCKS5 harness re-homed from pkg/telegram: a loopback HTTP server that answers getMe plus a SOCKS5 tunnel to it, so the production client path can be exercised end to end without a single packet leaving the machine.
Package telegramtest provides the offline fake Bot API and SOCKS5 harness re-homed from pkg/telegram: a loopback HTTP server that answers getMe plus a SOCKS5 tunnel to it, so the production client path can be exercised end to end without a single packet leaving the machine.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址