Skip to content

Commit dd3b305

Browse files
committed
feat: add ALLOWED_USERNAMES env for telegram bot
Adds ALLOWED_USERNAMES environment variable to restrict telegram bot usage to specific usernames. Also moves supervisor config files to /etc.
1 parent 0895729 commit dd3b305

File tree

8 files changed

+15
-7
lines changed

8 files changed

+15
-7
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ LITESTREAM_REPLICA_PATH=memos_prod.db
77
# For Memogram
88
BOT_TOKEN=your_telegram_bot_token # you can get it from @BotFather
99
MEMOS_TOKEN=your_memos_token # you can get it from your memos account settings
10-
TG_ID=your_telegram_user_id # you can get it from @userinfobot
10+
TG_ID=your_telegram_user_id # you can get it from @userinfobot
11+
ALLOWED_USERNAMES=your_telegram_username # leave empty or remove the variable to allow all telegram users, Usernames must not include the @ symbol

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ COPY --from=memos_package /usr/local/memos/memos /usr/local/memos/
2626
RUN mkdir -p /var/opt/memos
2727
VOLUME /var/opt/memos
2828

29-
# Copy litestream configuration file to /etc/
29+
# Copy litestream configuration file
3030
COPY etc/litestream.yml /etc/litestream.yml
3131

32-
# Copy startup script and supervisor config
32+
# Copy supervisor configuration files
33+
COPY etc/supervisord.conf /etc/supervisord.conf
34+
COPY etc/memos_service.conf /etc/supervisord/conf.d/memos_service.conf
35+
COPY etc/memogram_service.conf /usr/local/memos/memogram_service.conf
36+
37+
# Copy startup script
3338
COPY scripts/run.sh /usr/local/memos/run.sh
34-
COPY scripts/supervisord.conf /etc/supervisord.conf
35-
COPY scripts/conf.d/memos_service.conf /etc/supervisord/conf.d/memos_service.conf
36-
COPY scripts/conf.d/memogram_service.conf /usr/local/memos/memogram_service.conf
37-
# We will create two small helper scripts for supervisor
3839
COPY scripts/start_memos_service.sh /usr/local/memos/start_memos_service.sh
3940
COPY scripts/start_memogram_service.sh /usr/local/memos/start_memogram_service.sh
4041

42+
# Make scripts executable
4143
RUN chmod +x /usr/local/memos/run.sh \
4244
&& chmod +x /usr/local/memos/start_memos_service.sh \
4345
&& chmod +x /usr/local/memos/start_memogram_service.sh
@@ -61,6 +63,7 @@ ENV MEMOS_PORT="5230"
6163
ENV MEMOS_MODE="prod"
6264
ENV SERVER_ADDR=dns:localhost:${MEMOS_PORT}
6365
ENV DB_PATH="/var/opt/memos/memos_prod.db"
66+
ENV ALLOWED_USERNAMES=""
6467

6568
# Expose port
6669
EXPOSE ${MEMOS_PORT}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ghcr.io/hu3rror/memos-litestream:stable # Tag is `stable` or use official image
103103
- `BOT_TOKEN`: Your Telegram BOT token, only for `stable-memogram` image. Official project: [usememos/telegram-integration](https://github.com/usememos/telegram-integration)
104104
- `MEMOS_TOKEN`: Memos API token for Memogram to use. If not set, Memogram will attempt to use the first admin user's token.
105105
- `TG_ID`: Telegram User ID that will be allowed to use the bot.
106+
- `ALLOWED_USERNAMES`: Allows you to restrict bot usage to specific Telegram users. When set, only users with usernames in this list will be able to interact with the bot (Usernames must not include the @ symbol). Leave empty or remove the variable if you want to allow all users.
106107

107108
And for more information about litestream, see [https://litestream.io/getting-started/](https://litestream.io/getting-started/)
108109

README_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ghcr.io/hu3rror/memos-litestream:stable # 标签为 stable 或直接使用 neosm
103103
- `BOT_TOKEN`:你的 Telegram BOT token (仅限 `stable-memogram` 镜像使用),官方项目:https://github.com/usememos/telegram-integration
104104
- `MEMOS_TOKEN`: Memos API token,供 Memogram 使用。 如果未设置,Memogram 将尝试使用第一个管理员用户的 token。
105105
- `TG_ID`: Telegram 用户 ID,允许使用该 Bot。
106+
- `ALLOWED_USERNAMES`: 允许您将机器人使用权限限制给特定的Telegram用户。设置后,只有用户名在此列表中的用户才能与机器人交互(用户名不得包含@符号)。如需允许所有用户使用,请留空或删除该变量。
106107

107108
有关 litestream 的更多信息,请参阅 https://litestream.io/getting-started/
108109

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ services:
1717
- LITESTREAM_ACCESS_KEY_ID=000000001a2b3c40000000001 # Your s3/b2 access-key-id
1818
- LITESTREAM_SECRET_ACCESS_KEY=K000ABCDEFGHiJkLmNoPqRsTuVwXyZ0 # Your s3/b2 secret-access-key
1919
- BOT_TOKEN=0000000000000000000000000000000000000000 # Your telegram bot token (only for ghcr.io/hu3rror/memos-litestream:stable-memogram)
20+
- ALLOWED_USERNAMES=your_telegram_username # leave empty or remove the variable to allow all telegram users, Usernames must not include the @ symbol
2021
# env_file:
2122
# - .env
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ environment=
1313
MEMOS_PORT="%(ENV_MEMOS_PORT)s",
1414
MEMOS_TOKEN="%(ENV_MEMOS_TOKEN)s",
1515
TG_ID="%(ENV_TG_ID)s",
16+
ALLOWED_USERNAMES="%(ENV_ALLOWED_USERNAMES)s",
1617
TZ="%(ENV_TZ)s"

0 commit comments

Comments
 (0)