From 5e6820cca34dca4f6dcbc2b848161fbac1dab501 Mon Sep 17 00:00:00 2001 From: EchoZenith <60392923+EchoZenith@users.noreply.github.com> Date: Mon, 26 Jan 2026 11:43:15 +0800 Subject: [PATCH] feat(bot): add source code link to greeting message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Define GITHUB_URL environment variable with fallback - Implement InlineKeyboardMarkup for the start command - Add "🌟 查看项目源码" button to welcome message --- .env.example | 1 + bot.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 2dd440d..fa031ce 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ BOT_TOKEN=your_token_here ADMIN_ID=your_chat_id_here +GITHUB_URL=https://githhb.com/EchoZenith/TelegramContactBot diff --git a/bot.py b/bot.py index 5ea81f5..b223612 100644 --- a/bot.py +++ b/bot.py @@ -1,13 +1,14 @@ import os import logging import aiosqlite -from telegram import Update +from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Application, MessageHandler, CommandHandler, filters, ContextTypes # --- 从环境变量读取配置 --- BOT_TOKEN = os.getenv('BOT_TOKEN') ADMIN_ID = int(os.getenv('ADMIN_ID', '0')) DB_FILE = os.getenv('DB_PATH', '/app/data/messages.db') +GITHUB_URL = os.getenv('GITHUB_URL', 'https://github.com/EchoZenith/TelegramContactBot') # 启用日志 logging.basicConfig( @@ -27,7 +28,18 @@ async def init_db(): async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): user_id = update.effective_chat.id if user_id != ADMIN_ID: - await update.message.reply_text("Hello!\n\nYou can contact us using this bot.") + # 创建一个带有 URL 的按钮 + keyboard = [ + [ + InlineKeyboardButton("🌟 查看项目源码", url=GITHUB_URL) + ] + ] + reply_markup = InlineKeyboardMarkup(keyboard) + + await update.message.reply_text( + "Hello!\n\nYou can contact us using this bot.", + reply_markup=reply_markup + ) else: await update.message.reply_text("你好,管理员!有人给机器人发消息时,我会转发给你。你直接【回复】该消息即可回信。")