Skip to content

Configuration

To configure options, you have the following ways:

  • Directly set envrionment variables
  • Use .env.example as a template, modify the values and rename it to .env

ENV

Optional, defaults to production

The default option (production) uses Webhook mode, you can set to development to use polling mode.

TOKEN

Required

API token of your bot, can be obtained from @BotFather.

WEBHOOK_URL

Required if using webhook mode

Webhook URL to be set for Telegram server, the bot server should be accessible on this URL, should end with /, e.g. https://xxx.fly.dev/.

HOST

Required if using webhook mode

The host to bind to, defaults to 0.0.0.0. Set to 127.0.0.1 if you are using a reverse proxy.

If you are using Docker, configure container networking instead.

PORT

Required if using webhook mode

Webhook port, automatically set if on Heroku.

If you are using Docker, configure container networking instead.

DATABASE

Required, defaults to Local

Type of database, e.g. Mongo.

Supported databases:

Driver Usage Config Value Note
TinyDB TinyDB Local Default
Firestore Firestore Firebase
MongoDB MongoDB Mongo MongoDB Atlas supported
Cloudant Cloudant Cloudant

You can also implement your own database driver by creating a file under database folder, and set this option to the name of driver class.

STORAGE

Required, defaults to Local

List of storage types, separated by commas, e.g. Local,OneDrive.

Supported storage:

Name Usage Config Value Note
Local Local Local Default
Telegram Telegram Telegram Added in v2
MEGA MEGA Mega
Google Drive Google Drive GoogleDrive
OneDrive OneDrive OneDrive
S3 S3 S3

Implement other storage by creating a file under storage folder with a store method.

Changed in v2.

STORAGE_DIR

Optional, defaults to Pictures

Directory path in local storage or remote, will be created if not exists.

Optional

Telegram channel ID used for storing messages, messages containing links sent to bot will be forwarded here for reviewing.

Tip

You need to add your bot to channel administrators.

ADMIN_ID

Required

Telegram user ID (not username) of the admin user, some bot functions are restricted to the admin user.

IS_PUBLIC

Optional, defaults to false

Whether to make this bot public, when set to true, everyone can use the bot.

Added in v2.

ALLOW_ID

Optional

Attention

When IS_PUBLIC is true, this option will be ignored.

Telegram ID (not username) of the users allowed to use this bot, separated by commas.

e.g.:

export ALLOW_ID=111111 # single user
export ALLOW_ID=111111,222222,333333 # multiple users

Tip

You can get your User ID & Channel ID via @GetIDs Bot.

Changed in v2.

ALLOW_USERNAME

Optional

Attention

When IS_PUBLIC is true, this option will be ignored.

Telegram username of the users allowed to use this bot, separated by commas.

Changed in v2.

GROUP_ID

Optional

Attention

When IS_PUBLIC is true, this option will be ignored.

Telegram group ID, separated by commas. Users in these groups will be able to use the bot in group chat.

Changed in v2.

About access control

  1. Allow all if IS_PUBLIC=true
  2. User in ALLOW_ID or ALLOW_USERNAME or ADMIN_ID can access the bot via private chat
  3. User in ALLOW_GROUP can access via specified group chat

For more information, see nazurin/middleware.py.

RETRIES

Optional, defaults to 5

Number of attempts to retry on network related operations.

Added in v2.

TIMEOUT

Optional, defaults to 20

Request timeout in seconds.

DOWNLOAD_CHUNK_SIZE

Optional, defaults to 4096

Chunk size when writing downloaded files, in bytes.

Added in v2.6.0.

MAX_PARALLEL_DOWNLOAD

Optional, defaults to 5

Maximum number of parallel downloads.

Added in v2.7.0.

MAX_PARALLEL_UPLOAD

Optional, defaults to 5

Maximum number of parallel uploads.

Added in v2.7.0.

HTTP_PROXY

Optional, defaults to your environment

Proxy URL for network requests, e.g. http://127.0.0.1:7890, will follow your environment.

CAPTION_IGNORE

Optional, defaults to none

Items to ignore in image caption, separated by commas, e.g. bookmarked.

Added in v2.

CLEANUP_INTERVAL

Optional, defaults to 7

Temporary directory cleanup interval, in days. Files whose access time is older than 1 day will be deleted during cleanup. Automatic cleanup will be disabled if set to 0.

Added in v2.4.1.


Last update: January 21, 2024
Created: April 12, 2023