mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-15 00:46:07 +00:00
feat: Refactor input handling and feedback messages across multiple adapters
This commit is contained in:
@@ -93,7 +93,7 @@ def test_dingtalk_completed_input_lines_include_text_and_select_values():
|
||||
}
|
||||
)
|
||||
|
||||
assert lines == ['✅ 已填写 comment:looks good', '✅ 已选择 choice:B']
|
||||
assert lines == ['✅ comment:looks good', '✅ choice:B']
|
||||
|
||||
|
||||
def test_dingtalk_clean_form_content_uses_all_input_defs():
|
||||
|
||||
@@ -109,9 +109,9 @@ def test_lark_completed_input_lines_include_text_select_and_files():
|
||||
)
|
||||
|
||||
assert lines == [
|
||||
'✅ 已填写 us_input:**你好**',
|
||||
'✅ 已选择 xiala:**or**',
|
||||
'✅ 已上传 files:**2 file(s)**',
|
||||
'✅ us_input:你好',
|
||||
'✅ xiala:or',
|
||||
'✅ files:2 file(s)',
|
||||
]
|
||||
|
||||
|
||||
@@ -193,4 +193,4 @@ def test_lark_completed_input_lines_display_select_value_from_object():
|
||||
}
|
||||
)
|
||||
|
||||
assert lines == ['✅ 已选择 xiala:**B**']
|
||||
assert lines == ['✅ xiala:B']
|
||||
|
||||
@@ -75,6 +75,7 @@ def _stream_test_adapter():
|
||||
adapter.logger = AsyncMock()
|
||||
adapter.bot = MagicMock()
|
||||
adapter.bot.send_stream_msg = AsyncMock(return_value={'id': 'stream-1'})
|
||||
adapter.bot.send_markdown_keyboard = AsyncMock(return_value={'id': 'message-1'})
|
||||
adapter.ap = None
|
||||
adapter._stream_ctx = {}
|
||||
adapter._stream_ctx_ts = {}
|
||||
@@ -142,6 +143,36 @@ async def test_qq_non_streaming_fallback_keeps_latest_snapshot_only():
|
||||
assert str(sent_chain) == 'Hello'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_qq_text_field_prompt_keeps_form_content():
|
||||
from langbot.pkg.platform.sources.qqofficial import QQOfficialAdapter
|
||||
|
||||
adapter = _stream_test_adapter()
|
||||
adapter._pending_forms = {}
|
||||
adapter._session_event_ids = {}
|
||||
adapter._anchor_msg_seq = {}
|
||||
source = MagicMock()
|
||||
source.d_id = 'source-1'
|
||||
source.t = 'C2C_MESSAGE_CREATE'
|
||||
event = MagicMock()
|
||||
event.source_platform_object = source
|
||||
event.sender.id = 'user-1'
|
||||
form_data = {
|
||||
'_current_input_field': 'us_input',
|
||||
'node_title': 'Manual input',
|
||||
'form_content': '1234\nEnter your question',
|
||||
'input_defs': [{'output_variable_name': 'us_input', 'type': 'paragraph'}],
|
||||
'actions': [{'id': 'yes', 'title': 'yes'}],
|
||||
}
|
||||
|
||||
with patch.object(QQOfficialAdapter, '_resolve_target_from_event', return_value=('c2c', 'user-1')):
|
||||
await adapter._handle_form_chunk(event, platform_message.MessageChain([]), form_data)
|
||||
|
||||
send_call = adapter.bot.send_markdown_keyboard.await_args.kwargs
|
||||
assert send_call['markdown_content'] == '### Manual input\n\n1234\nEnter your question'
|
||||
assert send_call['keyboard'] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_qq_select_click_enqueues_input_progress_query():
|
||||
import langbot.pkg.core.app # noqa: F401
|
||||
|
||||
@@ -116,5 +116,8 @@ async def test_telegram_text_field_does_not_show_action_buttons():
|
||||
args = bot.send_message.await_args.kwargs
|
||||
assert isinstance(args['reply_markup'], ForceReply)
|
||||
assert args['reply_markup'].selective is False
|
||||
assert 'Please reply with a value for us_input.' in args['text']
|
||||
assert args['reply_markup'].input_field_placeholder == 'us_input'
|
||||
assert 'Please reply' not in args['text']
|
||||
assert args['text'].startswith('[人工介入]')
|
||||
assert 'us_input (paragraph)' in args['text']
|
||||
assert adapter._form_action_titles == {}
|
||||
|
||||
@@ -81,10 +81,10 @@ def test_build_button_interaction_update_card_marks_clicked_button():
|
||||
assert card['sub_title_text'] == 'Please choose one action.'
|
||||
assert card['button_list'][0] == {'text': 'Approve', 'style': 2, 'key': 'approve'}
|
||||
assert card['button_list'][1] == {
|
||||
'text': '已选择:Reject',
|
||||
'text': '✅ Reject',
|
||||
'style': 1,
|
||||
'key': 'reject',
|
||||
'replace_text': '已选择:Reject',
|
||||
'replace_text': '✅ Reject',
|
||||
}
|
||||
assert card['source'] == {'desc': 'LangBot'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user