telegram 机器人开发(python)

import asyncio
import logging
from typing import List, Tuple
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import CommandHandler, MessageHandler, filters
from telegram.ext import CallbackContext
from telegram.ext import (
   Application,
   CallbackQueryHandler,
   CommandHandler,
   ContextTypes,
   PicklePersistence,
)
from telegram import Bot
from telegram import InputFile
import pandas as pd
import asyncio
import logging
from typing import List, Tuple
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import CommandHandler, MessageHandler, filters
from telegram.ext import CallbackContext
from telegram.ext import (
   Application,
   CallbackQueryHandler,
   CommandHandler,
   ContextTypes,
   PicklePersistence,
)
from telegram import Bot
from telegram import InputFile
import pandas as pd

logging.basicConfig(
   format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)

def buildkeyboard() -> InlineKeyboardMarkup:
   buttons = [
       InlineKeyboardButton(text="爬虫", callback_data='1'),
       InlineKeyboardButton(text="搜索", callback_data='2'),
       InlineKeyboardButton(text="社工", callback_data='3'),
       InlineKeyboardButton(text="翻译", callback_data='4'),
       InlineKeyboardButton(text="ip", callback_data='5'),
       InlineKeyboardButton(text="按钮", callback_data='6'),
       InlineKeyboardButton(text="按钮", callback_data='7'),
       InlineKeyboardButton(text="按钮", callback_data='8'),
       InlineKeyboardButton(text="按钮", callback_data='9')
  ]
   keyboard = [buttons[i:i+3] for i in range(0, len(buttons), 3)]
   return InlineKeyboardMarkup(keyboard)

async def start(update: Update, context:ContextTypes.DEFAULT_TYPE) -> None:
   await update.message.reply_text("请从下面的按钮中选择:", reply_markup=buildkeyboard())

persistence = PicklePersistence(filepath="arbitrarycallbackdatabot")
application = (
   Application.builder()
  .token("填入你自己的API token")
  .persistence(persistence)
  .arbitrary_callback_data(True)
  .build()
)
# 你需要将 handleuserinput 注册为处理用户输入的消息
application.add_handler(CommandHandler("start", start))
application.run_polling(allowed_updates=Update.ALL_TYPES)

发表回复

Your email address will not be published. Required fields are marked *.

*
*