mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-04 10:14:47 +08:00
feat(migrate-v2): resolve WhatsApp LIDs from store/auth, alias DMs
v1 stored every WhatsApp DM as `<phone>@s.whatsapp.net`. v2's WA adapter sometimes resolves the chat to `<lid>@lid` instead — when WhatsApp delivers via the LID protocol and Baileys hasn't yet learned a LID→phone mapping for that contact (cold cache after migration). The router then can't find the phone-keyed messaging_group and silently drops the message at router.ts:184. Baileys persists every LID↔phone pair it has ever learned to disk as `store/auth/lid-mapping-<phone>.json` (forward) and `lid-mapping-<lid>_reverse.json` (reverse). v1 will already have these populated for every contact it has talked to. New step 2d-whatsapp-lids parses the reverse files and writes paired LID-keyed `messaging_groups` + `messaging_group_agents` rows so both `<phone>@s.whatsapp.net` and `<lid>@lid` route to the same agent_group with the same engage rules. No Baileys boot, no WhatsApp connectivity required — pure filesystem read of files we've already copied via 2b-channel-auth. Step is no-op-on-skip if either store/auth or whatsapp DM rows are missing. Anything that slips through (a contact whose LID v1 never learned) falls back to the runtime approval flow once the WA adapter sets isMention=true on DMs — each unknown LID DM auto-creates an approval-required messaging_group and the owner gets a one-tap register prompt. Verified end-to-end on a 12-group v1 install: 3 DM rows aliased, inbound DM routed via the LID-keyed row. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -392,6 +392,21 @@ else
|
||||
record_step "$STEP_NAME" "failed"
|
||||
fi
|
||||
done
|
||||
|
||||
# 2d. WhatsApp LID resolution. After whatsapp is installed (so Baileys
|
||||
# is on disk) and auth files have been copied (so we can connect with
|
||||
# the migrated identity), boot Baileys briefly to learn LID↔phone
|
||||
# mappings during initial sync, then write paired LID-keyed
|
||||
# messaging_groups. Best-effort: any failure degrades to runtime
|
||||
# approval flow, which the WA adapter's isMention=true on DMs handles.
|
||||
for ch in "${SELECTED_CHANNELS[@]}"; do
|
||||
if [ "$ch" = "whatsapp" ]; then
|
||||
run_step "2d-whatsapp-lids" \
|
||||
"Resolve WhatsApp LIDs for migrated DMs" \
|
||||
"setup/migrate-v2/whatsapp-resolve-lids.ts"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user