fix: resolve Discord usernames to user IDs for outbound messages #2649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2627
When sending Discord messages via cron jobs or the message tool, usernames like `john.doe` were incorrectly treated as channel names, causing silent delivery failures.
Problem
The Discord outbound adapter had no `resolveTarget` hook. The `parseDiscordTarget()` function fell back to treating unrecognized strings as channel names:
```typescript
return buildMessagingTarget("channel", trimmed, trimmed);
```
So `john.doe` was passed as a channel name lookup, which fails because no channel named `john.doe` exists.
Solution
This fix adds a `resolveDiscordTarget()` function that:
Changes
Testing
After this fix, cron jobs can target usernames:
```json
{
"to": "john.doe",
"channel": "discord"
}
```
The username will be resolved to a Discord user ID, and the message will be delivered as a DM.
Note: This is a first step. For username resolution to work, Discord directory integration must be configured and bot must have access to guild member lists.