An open API service indexing awesome lists of open source software.

https://github.com/alexiii/messageredir

Redirect SMS and other messages to Telegram via Webhook
https://github.com/alexiii/messageredir

sms sms-gateway telegram telegram-bot webhook-receiver

Last synced: 7 months ago
JSON representation

Redirect SMS and other messages to Telegram via Webhook

Awesome Lists containing this project

README

          

# Message Redir: Redirect Messages to Telegram via Webhook

This app serves a webhook that forwards messages to a Telegram bot.

Designed to work with [SMS to URL Forwarder](https://f-droid.org/en/packages/tech.bogomolov.incomingsmsgateway/) (Android app).

Other potential use cases include automated notifications from server monitoring systems, Grafana, etc.

This bot is multi-user, meaning you can connect with different Telegram accounts, and forward messages separately.

## Security Considerations

- Do not use other people's servers or bots. They will have access to your messages.
- Configure HTTPS! Either with an Nginx reverse-proxy or use the built-in HTTPS support. Even without a valid certificate, it offers partial security.

## Usage

1. Run the server

### Run the server in a single `docker` command

Prebuilt image is available on dockerhub: https://hub.docker.com/r/alex3iii/messageredir

```sh
docker run -d --name messageredir-inst -e MREDIR_TG_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN" -v "$(pwd)/messageredir.db:/root/app/messageredir.db" -p 8089:8080 alex3iii/messageredir:latest
```

This will serve HTTP by default. You can pass `MREDIR_TLS_CERT_FILE` and `MREDIR_TLS_KEY_FILE` environment variables to enable HTTPS.

### Or use `docker compose` (recommended)

i. Copy [docker-compose.yaml](./docker-compose.yaml) to an empty directory on your server.
```sh
wget https://github.com/AlexIII/messageredir/raw/refs/heads/main/docker-compose.yaml -O docker-compose.yaml
```

ii. Create an `.env` file in the same directory and set your configuration there. Example:
```env
MREDIR_TG_BOT_TOKEN=
MREDIR_LOG_USER_MESSAGES=true
MREDIR_TLS_CERT_FILE=tls/tls.crt # Self-signed certificate is generated by Docker Compose. When MREDIR_TLS_* are specified, the app will serve HTTPS.
MREDIR_TLS_KEY_FILE=tls/tls.key
```

iii. Run:
```sh
docker compose up -d
```
Remove `-d` on the first try to see the app log (errors, etc).

The default HTTP(S) port is 8089. Create `docker-compose.override.yaml` to override the port and/or other settings.

See logs with `docker compose logs`.

iv. Later, if you want to update to the latest version:
```sh
docker compose down
wget https://github.com/AlexIII/messageredir/raw/refs/heads/main/docker-compose.yaml -O docker-compose.yaml
docker pull alex3iii/messageredir:latest
docker compose up -d
```

2. After the server is running, write to the bot from your Telegram account. The `\start` command will return an access token.

3. Configure the SMS to URL Forwarder app to use this URL:
`http(s)://://smstourlforwarder`
When using HTTPS with a self-signed certificate, check the "ignore certificate" checkbox in the SMS to URL Forwarder app.

## Configuration

All properties are optional, except `tgBotToken` / `TG_BOT_TOKEN`.

| YAML Property | Environment Variable | Type | Description |
|------------------|-----------------------------|--------|----------------------|
| `tgBotToken` | `MREDIR_TG_BOT_TOKEN` | string | Telegram bot token |
| `dbFileName` | `MREDIR_DB_FILE_NAME` | string | Database file name |
| `userTokenLength`| `MREDIR_USER_TOKEN_LENGTH` | int | User token length |
| `logUserMessages`| `MREDIR_LOG_USER_MESSAGES` | bool | Log user messages |
| `restApiPort` | `MREDIR_REST_API_PORT` | int | REST API port |
| `tlsCertFile` | `MREDIR_TLS_CERT_FILE` | string | TLS certificate file |
| `tlsKeyFile` | `MREDIR_TLS_KEY_FILE` | string | TLS key file |
| `logFileName` | `MREDIR_LOG_FILE_NAME` | string | Log file name |
| `MyHost` | `MREDIR_MY_HOST` | string | Hostname:Port |

## How to Post a Message to the Hook

HTTP `POST http://://smstourlforwarder`

Body format:

```
{
"from": "%from%",
"text": "%text%",
"sentStamp": %sentStampMs%,
"receivedStamp": %receivedStampMs%,
"sim": "%sim%"
}
```

## License

MIT License © github.com/AlexIII