Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用 bot.edit_message_text 函数出现报错 <ActionFailed Bad Request: business connection not found> #78

Open
XiaoQiu2451 opened this issue Nov 12, 2024 · 2 comments

Comments

@XiaoQiu2451
Copy link

环境
OS: Debian 12
Python: 3.11.2

问题影响的版本
0.1.0b18 - 0.1.0b19

问题描述
在使用Telegram bot api的第三方API Client时,调用bot.edit_message_text时会报错,并且执行失败。
报错信息:
无论是否使用api_server,问题依然存在。

简单代码复现

from nonebot import on, on_command
from nonebot.adapters.telegram import Bot
from nonebot.adapters.telegram.event import CallbackQueryEvent, Event
from nonebot.adapters.telegram.model import (
    InlineKeyboardButton,
    InlineKeyboardMarkup
)

@on_command('test').handle()
async def _(bot: Bot, event: Event):
    inline_keyboard = [[InlineKeyboardButton(text=f"Click >>",callback_data='changetext')]]
    await bot.send_to(event.telegram_model.message.chat.id, 'bot.edit_message_text Test', 
                      reply_markup=InlineKeyboardMarkup(inline_keyboard=inline_keyboard))

@on("inline").handle()
async def _(bot: Bot, event: CallbackQueryEvent):
    if event.data == 'changetext':
        await bot.edit_message_text("Hello World!", 
                                    event.message.chat.id, event.message.message_id)
        await bot.answer_callback_query(event.id, text="Hello World!")

报错信息

11-12 16:48:58 [SUCCESS] nonebot | Telegram * | [inline.callback_query]: CallbackQuery * from *: changetext
11-12 16:48:58 [DEBUG] nonebot | Checking for matchers in priority 1...
11-12 16:48:58 [INFO] nonebot | Event will be handled by Matcher(type='inline', module=*.plugins.inline, lineno=15)
11-12 16:48:58 [DEBUG] nonebot | Running Matcher(type='inline', module=*.plugins.inline, lineno=15)
11-12 16:48:58 [DEBUG] nonebot | Running handler Dependent(call=_)
11-12 16:48:59 [DEBUG] nonebot | Telegram | Calling API editMessageText
11-12 16:48:59 [DEBUG] nonebot | Telegram | Calling API {'text': 'Now edit_message_text. Hello World!', 'business_connection_id': '*', 'chat_id': '*'}
11-12 16:48:59 [INFO] nonebot | Matcher(type='inline', module=*.plugins.inline, lineno=15) running complete
11-12 16:48:59 [ERROR] nonebot | Running Matcher(type='inline', module=*.plugins.inline, lineno=15) failed.
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File ".venv/lib/python3.11/site-packages/nonebot/__init__.py", line 337, in run
    get_driver().run(*args, **kwargs)
  File ".venv/lib/python3.11/site-packages/nonebot/drivers/fastapi.py", line 188, in run
    uvicorn.run(
  File ".venv/lib/python3.11/site-packages/uvicorn/main.py", line 579, in run
    server.run()
  File ".venv/lib/python3.11/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File ".venv/lib/python3.11/site-packages/nonebot/utils.py", line 254, in run_coro_with_shield
    return await coro
  File ".venv/lib/python3.11/site-packages/nonebot/message.py", line 506, in check_and_run_matcher
    await _run_matcher(
> File ".venv/lib/python3.11/site-packages/nonebot/message.py", line 458, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File ".venv/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 900, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File ".venv/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 837, in simple_run
    await handler(
  File ".venv/lib/python3.11/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "*/plugins/inline.py", line 18, in _
    await bot.edit_message_text("Now edit_message_text. Hello World!",
  File ".venv/lib/python3.11/site-packages/nonebot/adapters/telegram/bot.py", line 103, in call_api
    await super().call_api(api, **kargs)
  File ".venv/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 176, in call_api
    raise exception
  File ".venv/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 128, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File ".venv/lib/python3.11/site-packages/nonebot/adapters/telegram/adapter.py", line 248, in _call_api
    raise ActionFailed(json.loads(response.content)["description"])
nonebot.adapters.telegram.exception.ActionFailed: <ActionFailed Bad Request: business connection not found>
11-12 16:48:59 [DEBUG] nonebot | Checking for matchers completed
11-12 16:49:29 [DEBUG] nonebot | Telegram | Calling API getUpdates
@rampagege
Copy link

同样遇到了 已经回退版本了

@j1g5awi
Copy link
Member

j1g5awi commented Nov 13, 2024

这个是官方 API 文档的参数排序改了,我没改示例。

以后示例的所有 call_api 将改为用 kwarg 的形式,此示例为:

@on("inline").handle()
async def _(bot: Bot, event: CallbackQueryEvent):
    if event.data == 'changetext':
        await bot.edit_message_text(text="Hello World!", 
                                    chat_id=event.message.chat.id,
                                    message_id=event.message.message_id)
        await bot.answer_callback_query(event.id, text="Hello World!")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants