telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

Add docker secrets support for TELEGRAM_API_ID and TELEGRAM_API_HASH

Open jieggii opened this issue 1 year ago • 0 comments

Summary

Resolves #19

After this update users will be able to provide Telegram API credentials via env vars containing paths to files containing the actual values.

Example showcase:

  1. Create ./secrets dir and containing telegram_api_hash and telegram_api_id files:
 secrets
├──  telegram_api_hash
└──  telegram_api_id
  1. Fill the files with the actual credentials:
$ echo "12345" > ./secrets/telegram_api_id
$ echo "ba78...165ad" > ./secrets/telegram_api_hash
  1. Create docker-compose.yml, for example:
services:
  telegram-bot-api:
    build: .

    environment:
      # in this section we set paths to the mounted secrets: 
      TELEGRAM_API_ID_FILE: /run/secrets/telegram_api_id
      TELEGRAM_API_HASH_FILE: /run/secrets/telegram_api_hash
    
    secrets:
      # here we define list of secrets that will be used by the service
      - telegram_api_id
      - telegram_api_hash

secrets:
  # here we define the secrets and their location on the host machine:
  telegram_api_id:
    file: ./secrets/telegram_api_id
  telegram_api_hash:
    file: ./secrets/telegram_api_hash

Notes

I've also included checks for env vars presense:

$ docker run telegram-bot-api:latest
error: expected TELEGRAM_API_ID or TELEGRAM_API_ID_FILE env vars to be set

I think this will slightly improve user experience and will not break anything, as environmental variables containing Telegram API credentials were essential to run the telegram-bot-api anyway.

Please share your thoughts and whether any changes needed. Then I will update the README file to reflect the usecase changes.

jieggii avatar Aug 08 '24 12:08 jieggii