fix(migrate-v2): infer is_group from JID format

v1 didn't track is_group separately; db.ts hardcoded `is_group: 1` for
every messaging_group. v2 uses is_group=0 to collapse DM sub-thread
sessions and to drive routing decisions, so getting it wrong is latent
risk on otherwise-working installs.

New helper inferIsGroup(channelType, platformId) lives in shared.ts so
tasks.ts and any future migration step can reuse it. Inferred per
channel:
  - whatsapp: `<id>@g.us` is a group, anything else is a DM
  - telegram: negative chat IDs are groups, positive are DMs
  - everything else: default to 1 (least surprising for chats v1 chose
    to register, where DM auto-create paths weren't used)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gavriel Cohen
2026-05-02 15:24:57 +03:00
parent 416c283dcb
commit 2a915e8af0
2 changed files with 23 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ import { readEnvFile } from '../../src/env.js';
import { buildDiscordResolver, type DiscordResolver } from './discord-resolver.js';
import {
generateId,
inferIsGroup,
parseJid,
triggerToEngage,
v2PlatformId,
@@ -148,7 +149,7 @@ async function main(): Promise<void> {
channel_type: channelType,
platform_id: platformId,
name: g.name || null,
is_group: 1,
is_group: inferIsGroup(channelType, platformId),
unknown_sender_policy: 'public',
created_at: createdAt,
});