#!/bin/bash # FINAL FINAL ATTEMPT # Uses user's known-good config structure, adapted for Docker + Websocket. BRIDGE_SERVICE="telegram" DATA_DIR="data/$BRIDGE_SERVICE" CONFIG_FILE="$DATA_DIR/config.yaml" REG_FILE="$DATA_DIR/registration.yaml" # ... (Token extraction same as before) ... if command -v bbctl &> /dev/null; then BBCTL_OUT=$(bbctl register "sh-$BRIDGE_SERVICE" 2>&1) if [ $? -eq 0 ]; then YAML_CONTENT=$(echo "$BBCTL_OUT" | sed -n '/^id:/,$p') echo "$YAML_CONTENT" > "$REG_FILE" fi fi get_yaml_val() { grep "^$1:" "$REG_FILE" | sed 's/^[^:]*: *//' | tr -d '\r'; } REG_ID=$(get_yaml_val "id") AS_TOKEN=$(get_yaml_val "as_token") HS_TOKEN=$(get_yaml_val "hs_token") BOT_USERNAME=$(get_yaml_val "sender_localpart") if [ -z "$API_ID" ]; then read -p "Telegram API ID: " API_ID read -p "Telegram API Hash: " API_HASH fi # USER'S CONFIG (Adapted) cat < "$CONFIG_FILE" homeserver: address: https://matrix.beeper.com/_hungryserv/inswe domain: beeper.local verify_ssl: true software: hungry http_retry_count: 4 async_media: true # ADDED FOR DOCKER: websocket: true ping_interval_seconds: -1 appservice: address: http://localhost:29317 hostname: 0.0.0.0 port: 29317 max_body_size: 1 database: sqlite:////data/bridge.db id: $REG_ID bot_username: $BOT_USERNAME as_token: $AS_TOKEN hs_token: $HS_TOKEN ephemeral_events: true # Beeper usually needs this for WS async_transactions: true metrics: enabled: false listen_port: 8000 manhole: enabled: false bridge: username_template: ${BRIDGE_SERVICE}_{userid} alias_template: ${BRIDGE_SERVICE}_{groupname} displayname_template: '{displayname}' displayname_preference: - full name - username - phone number displayname_max_length: 100 allow_avatar_remove: true allow_contact_info: true max_initial_member_sync: 20 max_member_count: 10000 sync_channel_members: false skip_deleted_members: true startup_sync: false sync_update_limit: 0 sync_create_limit: 10 sync_deferred_create_all: true sync_direct_chats: true max_telegram_delete: 10 sync_matrix_state: true allow_matrix_login: true public_portals: false sync_with_custom_puppets: false sync_direct_chat_list: false double_puppet_server_map: beeper.com: https://matrix.beeper.com/_hungryserv/inswe double_puppet_allow_discovery: false # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # # If set, custom puppets will be enabled automatically for local users # instead of users having to find an access token and run `login-matrix` # manually. # If using this for other servers than the bridge's server, # you must also set the URL in the double_puppet_server_map. login_shared_secret_map: "beeper.com": "as_token:hua_GgntyU8meanud1GBjx4kh8sWf2XZJrXtnrQzHJZ8Fa1mKB52mWQpA_OdwUC3" telegram_link_preview: true # Whether or not the !tg join command should do a HTTP request # to resolve redirects in invite links. invite_link_resolve: false caption_in_message: true image_as_file_size: 10 image_as_file_pixels: 5000000 parallel_file_transfer: false federate_rooms: false always_custom_emoji_reaction: false animated_sticker: target: webp convert_from_webm: false args: width: 256 height: 256 fps: 25 animated_emoji: target: webp args: width: 64 height: 64 fps: 25 encryption: allow: true default: true appservice: true msc4190: false require: true allow_key_sharing: true delete_keys: delete_outbound_on_ack: true dont_store_outbound: false ratchet_on_decrypt: true delete_fully_used_on_decrypt: true delete_prev_on_new_session: true delete_on_device_delete: true periodically_delete_expired: true delete_outdated_inbound: true verification_levels: receive: cross-signed-tofu send: cross-signed-tofu share: cross-signed-tofu rotation: enable_custom: true milliseconds: 2592000000 messages: 10000 disable_device_change_key_rotation: true private_chat_portal_meta: default disable_reply_fallbacks: true cross_room_replies: false delivery_receipts: false delivery_error_reports: false incoming_bridge_error_reports: true message_status_events: true resend_bridge_info: false mute_bridging: true pinned_tag: m.favourite archive_tag: m.lowpriority tag_only_on_create: true bridge_matrix_leave: false kick_on_logout: false always_read_joined_telegram_notice: true create_group_on_invite: false backfill: enable: true normal_groups: true unread_hours_threshold: 720 forward_limits: initial: user: 50 normal_group: 100 supergroup: 50 channel: 50 sync: user: 0 normal_group: 0 supergroup: 0 channel: 0 forward_timeout: 900 incremental: messages_per_batch: 100 post_batch_delay: 20 max_batches: user: -1 normal_group: -1 supergroup: 10 channel: -1 initial_power_level_overrides: user: {} group: {} bot_messages_as_notices: true bridge_notices: default: false exceptions: [] relay_user_distinguishers: ["🟦", "🟣", "🟩", "⭕️", "🔶", "⬛️", "🔵", "🟢"] # The formats to use when sending messages to Telegram via the relay bot. # Text msgtypes (m.text, m.notice and m.emote) support HTML, media msgtypes don't. # # Available variables: # \$sender_displayname - The display name of the sender (e.g. Example User) # \$sender_username - The username (Matrix ID localpart) of the sender (e.g. exampleuser) # \$sender_mxid - The Matrix ID of the sender (e.g. @exampleuser:example.com) # \$distinguisher - A random string from the options in the relay_user_distinguishers array. # \$message - The message content message_formats: m.text: '\$distinguisher \$sender_displayname: \$message' m.notice: '\$distinguisher \$sender_displayname: \$message' m.emote: '* \$distinguisher \$sender_displayname \$message' m.file: '\$distinguisher \$sender_displayname sent a file: \$message' m.image: '\$distinguisher \$sender_displayname sent an image: \$message' m.audio: '\$distinguisher \$sender_displayname sent an audio file: \$message' m.video: '\$distinguisher \$sender_displayname sent a video: \$message' m.location: '\$distinguisher \$sender_displayname sent a location: \$message' # Telegram doesn't have built-in emotes, this field specifies how m.emote's from authenticated # users are sent to telegram. All fields in message_formats are supported. Additionally, the # Telegram user info is available in the following variables: # \$displayname - Telegram displayname # \$username - Telegram username (may not exist) # \$mention - Telegram @username or displayname mention (depending on which exists) emote_format: '* \$mention \$formatted_body' # The formats to use when sending state events to Telegram via the relay bot. # # Variables from `message_formats` that have the `sender_` prefix are available without the prefix. # In name_change events, `\$prev_displayname` is the previous displayname. # # Set format to an empty string to disable the messages for that event. state_event_formats: join: \$distinguisher \$displayname joined the room. leave: \$distinguisher \$displayname left the room. name_change: \$distinguisher \$prev_displayname changed their name to \$distinguisher \$displayname filter: mode: blacklist list: [] users: true command_prefix: '!tg' management_room_text: welcome: Hello, I'm a Telegram bridge bot. welcome_connected: Use `help` for help. welcome_unconnected: Use `help` for help or `login` to log in. additional_help: '' management_room_multiple_messages: false permissions: "beeper.local": user "beeper.com": user "@inswe:beeper.com": admin relaybot: private_chat: invite: [] state_changes: true message: This is a Matrix bridge relaybot and does not support direct chats group_chat_invite: [] ignore_unbridged_group_chat: true authless_portals: true whitelist_group_admins: true ignore_own_incoming_events: true whitelist: [] telegram: api_id: $API_ID api_hash: $API_HASH bot_token: disabled catch_up: true sequential_updates: true exit_on_update_error: true force_refresh_interval_seconds: 0 connection: timeout: 120 retries: 5 retry_delay: 1 flood_sleep_threshold: 60 request_retries: 5 use_ipv6: false device_info: device_model: Beeper (self-hosted) system_version: auto app_version: auto lang_code: en system_lang_code: en server: enabled: false dc: 2 ip: 149.154.167.40 port: 80 proxy: type: disabled logging: version: 1 formatters: colored: format: "[%(asctime)s] [%(levelname)s@%(name)s] %(message)s" datefmt: "%b %d %H:%M:%S" handlers: console: class: logging.StreamHandler formatter: colored stream: ext://sys.stdout root: level: INFO handlers: [console] EOF cat < docker-compose.yml services: telegram: container_name: beeper-telegram image: dock.mau.dev/mautrix/telegram:latest restart: unless-stopped network_mode: "host" volumes: - ./data/telegram:/data environment: # Explicitly force websocket via env var just in case - MAUTRIX_TELEGRAM_HOMESERVER_WEBSOCKET=true logging: driver: json-file options: max-size: "10m" max-file: "3" EOF echo "Starting FINAL ATTEMPT..." docker compose up -d --force-recreate telegram docker compose logs -f telegram