fix: ignore non-query Feishu messages

This commit is contained in:
ar51
2026-08-08 18:09:05 +08:00
parent 0aaedb8b66
commit d97b788e0e
7 changed files with 187 additions and 19 deletions

View File

@@ -43,8 +43,13 @@ The bridge extracts exactly one eRob model and one positive quantity from either
a compact input or a natural-language message. Text such as “请查询
eRob142H100I-BHM-18ET[V4]这个数量20台的交期” is accepted. The bridge stops when
the model is missing, multiple different models are present, the quantity is
missing, or multiple possible quantities remain ambiguous. It invokes only the
existing controlled delivery-prediction script. It generates the full Cartesian
missing, or multiple possible quantities remain ambiguous. These non-triggering
messages are ignored silently: the bridge sends no Feishu reply, makes no API
request, and appends no record. Only a message containing exactly one complete,
rule-valid eRob model and exactly one positive quantity enters the query workflow.
This gate applies even when the bot receives every message in a group; an @mention
alone does not bypass it. The bridge invokes only the existing controlled
delivery-prediction script. It generates the full Cartesian
set of candidates allowed by the packaged Skill: brake upgrades, encoder
upgrades, sensor upgrades, low-temperature grease upgrades, and DZ/LF reducer
brand variants. Strong constraints and version stay unchanged. The original

View File

@@ -154,6 +154,18 @@ def parse_request(text: str) -> RequestInput:
return RequestInput(model=model, quantity=quantity)
def parse_trigger_request(text: str) -> RequestInput | None:
"""Return a query only when one complete model and one quantity are present.
Feishu group messages that do not satisfy the complete AM516 input contract
are unrelated traffic from the bridge's point of view and must stay silent.
"""
try:
return parse_request(text)
except InputError:
return None
def build_model(fields: dict[str, str]) -> str:
closing_bracket = "]" if fields["bracket"] == "[" else ")"
return (
@@ -818,8 +830,17 @@ def handle_message(client: lark.Client, data: lark.im.v1.P2ImMessageReceiveV1) -
message_id = data.event.message.message_id
if not text or not message_id:
return
request = parse_trigger_request(text)
if request is None:
logging.info(
"Feishu message ignored: no complete AM516 model-and-quantity request; message_id=%s",
message_id,
)
return
try:
report = build_report(parse_request(text))
report = build_report(request)
except InputError as exc:
report = f"AM516 内部候选查询已停止:{exc}\n\n{DISCLAIMER}"
except RuntimeError as exc: