#这是机器人的源码,附带了api,开箱即用
import telebot
import requests
TOKEN = '你的机器人token'
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
welcome_message = "我叫小爱,很高兴这次的遇见,我会一直陪伴你的。"
bot.reply_to(message, welcome_message)
@bot.message_handler(func=lambda message: True)
def handle_message(message):
user_question = message.text
api_url = f'http://81.70.100.130/api/xiaoai.php?msg={user_question}&n=text'
response = requests.get(api_url)
if response.status_code == 200:
response_text = response.text.strip()
print("Response Text:", response_text)
if response_text:
bot.reply_to(message, response_text)
else:
bot.reply_to(message, "响应文本为空。")
else:
bot.reply_to(message, "抱歉,无法获取响应。")
bot.polling()
import telebot
import requests
TOKEN = '你的机器人token'
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
welcome_message = "我叫小爱,很高兴这次的遇见,我会一直陪伴你的。"
bot.reply_to(message, welcome_message)
@bot.message_handler(func=lambda message: True)
def handle_message(message):
user_question = message.text
api_url = f'http://81.70.100.130/api/xiaoai.php?msg={user_question}&n=text'
response = requests.get(api_url)
if response.status_code == 200:
response_text = response.text.strip()
print("Response Text:", response_text)
if response_text:
bot.reply_to(message, response_text)
else:
bot.reply_to(message, "响应文本为空。")
else:
bot.reply_to(message, "抱歉,无法获取响应。")
bot.polling()