File size: 1,889 Bytes
cf41a36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# ── Build dependencies ────────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y \
    cmake \
    g++ \
    git \
    libssl-dev \
    zlib1g-dev \
    gperf \
    make \
    curl \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# ── Clone and build the official Telegram Bot API server ─────────────────────
# Pin to a specific commit for reproducibility
RUN git clone --recursive https://github.com/tdlib/telegram-bot-api.git /tmp/telegram-bot-api

WORKDIR /tmp/telegram-bot-api

RUN mkdir build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
          .. && \
    cmake --build . --target install -j$(nproc)

# ── Runtime setup ─────────────────────────────────────────────────────────────
RUN mkdir -p /data /var/log/telegram-bot-api

# HuggingFace Spaces requires the app to run as a non-root user
RUN useradd -m -u 1000 botapi && \
    chown -R botapi:botapi /data /var/log/telegram-bot-api

USER botapi

# HF Spaces exposes port 7860
EXPOSE 7860

# ── Entrypoint ────────────────────────────────────────────────────────────────
# API_ID and API_HASH must be set as HF Space secrets
CMD telegram-bot-api \
    --api-id=${API_ID} \
    --api-hash=${API_HASH} \
    --http-port=7860 \
    --dir=/data \
    --temp-dir=/data/temp \
    --log=/var/log/telegram-bot-api/server.log \
    --verbosity=1