-
Notifications
You must be signed in to change notification settings - Fork 15
Add support for custom bot name and avatar in Slack client #1441
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
Conversation
Introduces optional parameters to set a custom bot username and avatar (emoji or image URL) when sending messages via the Slack client. Updates documentation and OAuth scopes to include 'chat:write.customize'.
WalkthroughAdds optional per-message custom bot name and avatar: new Props field for avatar, forwards customBotName and customBotAvatar into SlackClient, updates postMessage to apply username/icon fields based on avatar format, and adds the Slack OAuth scope Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Mod as slack/mod.ts
participant Client as SlackClient
participant Slack as Slack API
User->>Mod: Provide channel config (displayName, botName, avatar)
Mod->>Mod: Derive customBotName = displayName || botName
Mod->>Mod: Derive customBotAvatar = avatar
Mod->>Client: new SlackClient(..., customBotName, customBotAvatar)
Client->>Client: Store customBotName & customBotAvatar
User->>Client: postMessage(payload)
alt customBotName/customBotAvatar set
Client->>Client: Detect avatar type (":name:" / "http(s)://" / bare)
Client->>Client: Set as_user = false, username = customBotName
Client->>Client: Set icon_emoji or icon_url accordingly
end
Client->>Slack: POST /chat.postMessage (with customized fields)
Slack-->>Client: 200 OK
Client-->>User: Return response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)slack/client.ts (1)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Tagging OptionsShould a new tag be published when this PR is merged?
|
Co-authored-by: viktormarinho <[email protected]>
Cleaned up formatting by deleting an extra blank line in the SlackClient class for improved code readability.
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
slack/client.ts (2)
275-288: Consider validating constructor inputs.The constructor accepts
customBotNameandcustomBotAvatarwithout validation. Empty strings or malformed URLs could lead to unexpected behavior when posting messages.Consider adding validation:
constructor( botToken: string, oauthClient?: OAuthClients<SlackApiClient, SlackAuthClient>, customBotName?: string, customBotAvatar?: string, ) { this.botHeaders = { Authorization: `Bearer ${botToken}`, "Content-Type": "application/json; charset=utf-8", }; this.oauthClient = oauthClient; - this.customBotName = customBotName; - this.customBotAvatar = customBotAvatar; + this.customBotName = customBotName?.trim() || undefined; + this.customBotAvatar = customBotAvatar?.trim() || undefined; }
390-396: Strengthen URL validation for icon_url.The current check
this.customBotAvatar.startsWith("http")is weak and could match malformed URLs like "httpx" or "httpabc".Consider using a more robust URL validation:
- } else if (this.customBotAvatar.startsWith("http")) { + } else if (this.customBotAvatar.startsWith("http://") || this.customBotAvatar.startsWith("https://")) { payload.icon_url = this.customBotAvatar;Or for stricter validation with HTTPS enforcement:
- } else if (this.customBotAvatar.startsWith("http")) { + } else if (this.customBotAvatar.startsWith("https://")) { payload.icon_url = this.customBotAvatar;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
slack/client.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
slack/client.ts (1)
slack/utils/client.ts (1)
SlackApiClient(11-126)
🔇 Additional comments (2)
slack/client.ts (2)
272-273: LGTM!The private field declarations are properly typed and encapsulated.
434-462: Verify: Should thread replies use custom bot identity?The
postReplymethod doesn't apply custom bot name and avatar settings, which creates an inconsistency withpostMessage. Thread replies will appear with the default bot identity even when custom settings are configured.If this is intentional (e.g., only top-level messages should be customized), consider adding a comment to clarify. Otherwise, consider applying the same custom bot logic to
postReply.
Refactors the logic for applying custom bot names and avatars to ensure 'as_user' is set to false when either is configured. This improves clarity and prevents potential issues when only one of the customizations is set.
Summary by CodeRabbit
New Features
Chores