mirror of
https://github.com/EchoZenith/TelegramContactBot.git
synced 2026-02-09 18:05:20 +00:00
feat(bot): add source code link to greeting message
- Define GITHUB_URL environment variable with fallback
- Implement InlineKeyboardMarkup for the start command
- Add "🌟 查看项目源码" button to welcome message
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
BOT_TOKEN=your_token_here
|
BOT_TOKEN=your_token_here
|
||||||
ADMIN_ID=your_chat_id_here
|
ADMIN_ID=your_chat_id_here
|
||||||
|
GITHUB_URL=https://githhb.com/EchoZenith/TelegramContactBot
|
||||||
|
|||||||
16
bot.py
16
bot.py
@@ -1,13 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
from telegram import Update
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
from telegram.ext import Application, MessageHandler, CommandHandler, filters, ContextTypes
|
from telegram.ext import Application, MessageHandler, CommandHandler, filters, ContextTypes
|
||||||
|
|
||||||
# --- 从环境变量读取配置 ---
|
# --- 从环境变量读取配置 ---
|
||||||
BOT_TOKEN = os.getenv('BOT_TOKEN')
|
BOT_TOKEN = os.getenv('BOT_TOKEN')
|
||||||
ADMIN_ID = int(os.getenv('ADMIN_ID', '0'))
|
ADMIN_ID = int(os.getenv('ADMIN_ID', '0'))
|
||||||
DB_FILE = os.getenv('DB_PATH', '/app/data/messages.db')
|
DB_FILE = os.getenv('DB_PATH', '/app/data/messages.db')
|
||||||
|
GITHUB_URL = os.getenv('GITHUB_URL', 'https://github.com/EchoZenith/TelegramContactBot')
|
||||||
|
|
||||||
# 启用日志
|
# 启用日志
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -27,7 +28,18 @@ async def init_db():
|
|||||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
user_id = update.effective_chat.id
|
user_id = update.effective_chat.id
|
||||||
if user_id != ADMIN_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:
|
else:
|
||||||
await update.message.reply_text("你好,管理员!有人给机器人发消息时,我会转发给你。你直接【回复】该消息即可回信。")
|
await update.message.reply_text("你好,管理员!有人给机器人发消息时,我会转发给你。你直接【回复】该消息即可回信。")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user