我正在做一个项目,即TG中的一个聊天机器人,任务之一就是回答用户的问题。我有一个常见问题列表,但我不知道如何将它们添加到数据库(sqlite)中,或者是否值得这样做。问题还在于,本质上相同的问题可以用不同的词语提出,据我所知,它可以通过 nltk 库来解决。告诉我如何最好地做到这一点,或者告诉我如何正确地谷歌搜索这个问题。提前致谢!
Jarry Roxwell
Asked:
2024-08-07 06:09:46 +0800 CST
我正在分析电报网络应用程序,出现了一个问题。我可以在消息中发送内联按钮来打开它,但我不明白如何确保应用程序在电报中打开。服务器上的标头不会泄露任何特殊信息。一个想法出现了(但很快就消失了,或者我找不到信息),按下按钮本身可以发送 POST 或添加某种标头。
问题是,如何确保启动按钮的链接确实在标签中打开,甚至更好的是特定用户单击了它?
----
我正在制作一个机器人,它可以读取邮箱并发送有关新信件(发件人、主题)的新消息,并使用内联按钮下载信件本身。但结果应该来自单击按钮。作为一个想法,我想到在链接中传递字母 ID 以及主题 + 发件人的加盐哈希。理想情况下,向标头添加授权会很棒,可能......
UPD:我没有仔细阅读文档
Alex
Asked:
2024-07-03 02:22:05 +0800 CST
完整的错误代码
Traceback (most recent call last):
File "C:\Users\marse\PycharmProjects\NFO\main.py", line 5, in <module>
from aiogram import Bot, Dispatcher, executor, types
ImportError: cannot import name 'executor' from 'aiogram' (C:\Users\marse\PycharmProjects\NFO\.venv\Lib\site-packages\aiogram\__init__.py)
aiogram 版本 3.8.0,一切正常,除了这个,请帮助,我将非常感激
Андрей Литвинчук
Asked:
2024-05-29 23:56:59 +0800 CST
import sqlite3
import asyncio
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command
API_TOKEN = 'ТОКЕН'
bot = Bot(token=API_TOKEN)
dp = Dispatcher()
conn = sqlite3.connect('bot.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
username TEXT,
points INTEGER DEFAULT 0,
invited_by INTEGER
)
''')
conn.commit()
def add_user(user_id, username, invited_by=None):
cursor.execute('SELECT * FROM users WHERE user_id=?', (user_id,))
if cursor.fetchone() is None:
cursor.execute('INSERT INTO users (user_id, username, invited_by) VALUES (?, ?, ?)',
(user_id, username, invited_by))
conn.commit()
def add_points(user_id, points):
cursor.execute('UPDATE users SET points = points + ? WHERE user_id = ?', (points, user_id))
conn.commit()
@dp.message(Command('start'))
async def send_welcome(message: types.Message):
command = message.get_command()
args = message.get_args()
user_id = message.from_user.id
username = message.from_user.username
invited_by = None
if args:
try:
invited_by = int(args)
except ValueError:
pass
add_user(user_id, username, invited_by)
if invited_by:
add_points(invited_by, 10)
await bot.send_message(invited_by, f"Вас пригласил пользователь @{username}. Вы получили 10 очков!")
markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton("Реферальная ссылка", callback_data="referral_link"))
await message.answer("Добро пожаловать! Нажмите кнопку ниже, чтобы получить реферальную ссылку:",
reply_markup=markup)
@dp.callback_query(lambda callback_query: callback_query.data == "referral_link")
async def process_referral_link(callback_query: types.CallbackQuery):
user_id = callback_query.from_user.id
referral_link = f"https://t.me/YOUR_BOT_USERNAME?start={user_id}"
await bot.send_message(user_id, f"Ваша реферальная ссылка: {referral_link}")
async def main():
await dp.start_polling()
if __name__ == '__main__':
asyncio.run(main())
错误:
ValueError: At least one bot instance is required to start polling.
user580418
Asked:
2024-04-20 03:25:12 +0800 CST
有一个电报机器人已经工作了 3 个月,大约 2 周前开始出现定期错误,无法连接到电报服务器,尽管那里有互联网,有关于如何解决此问题的想法吗?
python --version
Python 3.11.5
python -m pip show aiogram
Name: aiogram
Version: 3.3.0
Summary: Modern and fully asynchronous framework for Telegram Bot API
Home-page:
Author:
Author-email: Alex Root Junior <[email protected]>
License:
Location: C:\Users\adelt\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: aiofiles, aiohttp, certifi, magic-filter, pydantic, typing-extensions
Required-by:
python -m pip show aiohttp
Name: aiohttp
Version: 3.9.1
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: C:\Users\adelt\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: aiosignal, attrs, frozenlist, multidict, yarl
Required-by: aiogram
该机器人在 Windows 11 的 PC 上启动,PC 上的时间是正确的错误示例:
Failed to fetch updates - TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [getaddrinfo failed]
Sleep for 1.000000 seconds and try again... (tryings = 0, bot id = *******))
Failed to fetch updates - TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [getaddrinfo failed]
Sleep for 1.264188 seconds and try again... (tryings = 1, bot id = *******))
Failed to fetch updates - TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [getaddrinfo failed]
Sleep for 1.678613 seconds and try again... (tryings = 2, bot id = *******))
Failed to fetch updates - TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [getaddrinfo failed]
Sleep for 2.187897 seconds and try again... (tryings = 3, bot id = *******)