-
Notifications
You must be signed in to change notification settings - Fork 24.1k
feat(imessage): add myNumbers config to filter by destination phone number #5654
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
feat(imessage): add myNumbers config to filter by destination phone number #5654
Conversation
…umber
When the Mac has multiple iMessage numbers (e.g., dual-SIM setup), messages
to ALL numbers are received. This adds a myNumbers config option that filters
messages by destination_caller_id, so the bot only responds to messages sent
to the configured number(s).
Config example:
{
channels: {
imessage: {
myNumbers: ["+16466128299"]
}
}
}
Requires imsg to expose destination_caller_id (see steipete/imsg#29).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 2 comments
| const myNumbers = imessageCfg.myNumbers; | ||
| if (myNumbers && myNumbers.length > 0) { | ||
| const destinationCallerId = message.destination_caller_id; | ||
| if (destinationCallerId) { | ||
| const normalizedDest = normalizeIMessageHandle(destinationCallerId); | ||
| const normalizedMyNumbers = myNumbers.map((n) => normalizeIMessageHandle(n)); | ||
| if (!normalizedMyNumbers.includes(normalizedDest)) { | ||
| logVerbose( | ||
| `imessage: skipping message to ${destinationCallerId} (not in myNumbers: ${myNumbers.join(", ")})`, | ||
| ); | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] myNumbers filter is bypassed when destination_caller_id is missing
In handleMessageNow, the filter only runs if destinationCallerId is truthy (if (destinationCallerId) { ... }). If imsg is older (or sends null/empty) then messages will be processed even when myNumbers is configured, which undermines the main safety goal (avoid responding on the wrong number). Consider treating missing destination_caller_id as non-matching (skip) when myNumbers is set, or at least logging a clear warning so operators know the filter isn’t being applied.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/imessage/monitor/monitor-provider.ts
Line: 216:228
Comment:
[P1] `myNumbers` filter is bypassed when `destination_caller_id` is missing
In `handleMessageNow`, the filter only runs if `destinationCallerId` is truthy (`if (destinationCallerId) { ... }`). If `imsg` is older (or sends `null`/empty) then messages will be processed even when `myNumbers` is configured, which undermines the main safety goal (avoid responding on the wrong number). Consider treating missing `destination_caller_id` as non-matching (skip) when `myNumbers` is set, or at least logging a clear warning so operators know the filter isn’t being applied.
How can I resolve this? If you propose a fix, please make it concise.| const normalizedMyNumbers = myNumbers.map((n) => normalizeIMessageHandle(n)); | ||
| if (!normalizedMyNumbers.includes(normalizedDest)) { | ||
| logVerbose( | ||
| `imessage: skipping message to ${destinationCallerId} (not in myNumbers: ${myNumbers.join(", ")})`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Avoid per-message re-normalization of myNumbers
normalizedMyNumbers is recomputed on every inbound message (myNumbers.map(normalizeIMessageHandle)), even though imessageCfg.myNumbers is static for the provider lifetime. Precomputing a Set of normalized numbers once (outside handleMessageNow) would avoid repeated allocations and make the membership check O(1).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/imessage/monitor/monitor-provider.ts
Line: 221:224
Comment:
[P3] Avoid per-message re-normalization of `myNumbers`
`normalizedMyNumbers` is recomputed on every inbound message (`myNumbers.map(normalizeIMessageHandle)`), even though `imessageCfg.myNumbers` is static for the provider lifetime. Precomputing a `Set` of normalized numbers once (outside `handleMessageNow`) would avoid repeated allocations and make the membership check O(1).
How can I resolve this? If you propose a fix, please make it concise.
Summary
[This PR was closed and replaced by #5655 - content removed for privacy]