Skip to content

Commit e295594

Browse files
isaacrowntreeclaude
andcommitted
feat: auto-switch to bot when sending DM to yourself
When the DM target matches the authenticated user, automatically use the bot client for posting so you actually get a notification. Sending a DM to yourself as yourself is a no-op in Slack. Also adds users:read to user token manifest scopes (from v0.8.2). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5b46110 commit e295594

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/cmd/message/send.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/slack-go/slack"
1010
"github.com/spf13/cobra"
1111
"github.com/triptechtravel/slackbuzz-cli/internal/api"
12+
"github.com/triptechtravel/slackbuzz-cli/internal/auth"
1213
"github.com/triptechtravel/slackbuzz-cli/pkg/cmdutil"
1314
)
1415

@@ -119,6 +120,19 @@ func sendRun(opts *sendOptions) error {
119120
return fmt.Errorf("%s", api.FormatResolveError(err, opts.channel))
120121
}
121122

123+
// Self-DM: if sending a DM to yourself, switch to bot so you get a notification
124+
if api.LooksLikeUser(opts.channel) && !opts.asBot {
125+
if selfID, _, _ := auth.ResolveUserID(); selfID != "" {
126+
targetID := resolveTargetUserID(resolver, opts.channel)
127+
if targetID == selfID {
128+
if botClient, botErr := opts.factory.BotClient(); botErr == nil {
129+
client = botClient
130+
fmt.Fprintf(ios.ErrOut, "%s Sending to yourself — using bot so you get a notification\n", cs.Blue("→"))
131+
}
132+
}
133+
}
134+
}
135+
122136
// Get message text from args or stdin
123137
text := opts.text
124138
if text == "" {
@@ -187,6 +201,16 @@ func sendRun(opts *sendOptions) error {
187201
return nil
188202
}
189203

204+
// resolveTargetUserID resolves a DM target to a user ID without opening a conversation.
205+
// Returns empty string if resolution fails.
206+
func resolveTargetUserID(r *api.Resolver, target string) string {
207+
id, err := r.ResolveUser(target)
208+
if err != nil {
209+
return ""
210+
}
211+
return id
212+
}
213+
190214
// unescapeShellArtifacts removes common shell escape sequences that leak into
191215
// CLI arguments. For example, zsh's history expansion escapes ! as \! when
192216
// passed through double-quoted strings.

0 commit comments

Comments
 (0)