diff --git a/README.md b/README.md index 1433772..58a7108 100644 --- a/README.md +++ b/README.md @@ -12,27 +12,55 @@ The bot is designed to run within a Kubernetes environment, but can be operated ## Configuration -All configuration is provided via environment variables +SMSBot can be configured using either a configuration file or environment variables. Environment variables will override any values set in the configuration file. -| Variable | Required? | Description | -| -------------------------- | --------- | --------------------------------------------------------------------------- | -| SMSBOT_DEFAULT_SUBSCRIBERS | No | A list of IDs, seperated by commas, to add to the subscribers list on start | -| SMSBOT_LISTEN_HOST | No | The host for the webhooks to listen on, defaults to `0.0.0.0` | -| SMSBOT_LISTEN_PORT | No | The port to listen to, defaults to `80` | -| SMSBOT_OWNER_ID | No | ID of the owner of this bot | -| SMSBOT_TELEGRAM_BOT_TOKEN | Yes | Your Bot Token for Telegram | -| SMSBOT_TWILIO_AUTH_TOKEN | No | Twilio auth token, used to validate any incoming webhook calls | +### Configuration File + +Create a configuration file (e.g., `config.ini`) based on the provided `config-example.ini`: + +```ini +[logging] +level = INFO + +[webhook] +host = 127.0.0.1 +port = 80 + +[telegram] +owner_id = OWNER_USER_ID +bot_token = BOT_TOKEN + +[twilio] +account_sid = TWILIO_ACCOUNT_SID +auth_token = TWILIO_AUTH_TOKEN +``` + +### Environment Variables + +All configuration options can be overridden using environment variables: + +| Environment Variable | Config Section | Config Key | Required? | Description | +| --------------------------- | -------------- | ----------- | --------- | --------------------------------------------------------------------------- | +| SMSBOT_LOGGING_LEVEL | logging | level | No | The log level to output to the console, defaults to `INFO` | +| SMSBOT_TELEGRAM_BOT_TOKEN | telegram | bot_token | Yes | Your Bot Token for Telegram | +| SMSBOT_TELEGRAM_OWNER_ID | telegram | owner_id | No | ID of the owner of this bot | +| SMSBOT_TELEGRAM_SUBSCRIBERS | telegram | subscribers | No | A list of IDs, separated by commas, to add to the subscribers list on start | +| SMSBOT_TWILIO_ACCOUNT_SID | twilio | account_sid | No | Twilio account SID | +| SMSBOT_TWILIO_AUTH_TOKEN | twilio | auth_token | No | Twilio auth token, used to validate any incoming webhook calls | +| SMSBOT_WEBHOOK_HOST | webhook | host | No | The host for the webhooks to listen on, defaults to `127.0.0.1` | +| SMSBOT_WEBHOOK_PORT | webhook | port | No | The port to listen to, defaults to `80` | ## Setup To configure SMSBot, you'll need a Twilio account, either paid or trial is fine. -* Setup a number in the location you want. -* Under Phone Numbers -> Manage -> Active Numbers, click the number you want to setup. -* In the "Voice & Fax" section, update the "A Call Comes In" to the URL of your SMSBot instance, with the endpoint being `/call`, e.g. `http://mymachine.test.com/call` -* In the "Messaging" section, update the "A Message Comes In" to the URL of your SMSBot instance, with the endpoint being `/message`, e.g. `http://mymachine.test.com/message` +1. Copy `config-example.ini` to `config.ini` and update the values, or set the appropriate environment variables. +2. Setup a number in the location you want. +3. Under Phone Numbers -> Manage -> Active Numbers, click the number you want to setup. +4. In the "Voice & Fax" section, update the "A Call Comes In" to the URL of your SMSBot instance, with the endpoint being `/call`, e.g. `http://mymachine.test.com/call` +5. In the "Messaging" section, update the "A Message Comes In" to the URL of your SMSBot instance, with the endpoint being `/message`, e.g. `http://mymachine.test.com/message` -Your bot should now receive messages, on Telegram you need to start a chat or invite it into any channels you want, then update the `SMSBOT_DEFAULT_SUBSCRIBERS` values with their IDs. +Your bot should now receive messages, on Telegram you need to start a chat or invite it into any channels you want, then update the `SMSBOT_TELEGRAM_SUBSCRIBERS` values with their IDs. **Note**: You cannot send test messages from your Twilio account to your Twilio numbers, they'll be silently dropped or fail with an "Invalid Number" error. diff --git a/config-example.ini b/config-example.ini index ef2ef9f..9ea19aa 100644 --- a/config-example.ini +++ b/config-example.ini @@ -7,6 +7,7 @@ port = 80 [telegram] owner_id = OWNER_USER_ID +subscribers = 1111,2222,3333 bot_token = BOT_TOKEN [twilio] diff --git a/pyproject.toml b/pyproject.toml index 244727f..1825228 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,3 +30,6 @@ dev = [ "ruff>=0.12.9", ] github = ["pytest-github-actions-annotate-failures>=0.3.0"] + +[tool.ruff] +line-length = 120