Skip to content

Conversation

@kevinicolas22
Copy link
Contributor

@kevinicolas22 kevinicolas22 commented Oct 30, 2025

Summary by CodeRabbit

  • New Features

    • Configure a custom bot username and avatar for Slack messages.
    • Per-message customization of bot display name and avatar, supporting emoji or image URL formats.
  • Chores

    • Added Slack OAuth scope chat:write.customize to enable per-message customization.

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'.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

Adds 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 chat:write.customize.

Changes

Cohort / File(s) Summary
OAuth & Docs
slack/README.md, slack/utils/constants.ts
Added chat:write.customize to SCOPES and documented it in README.
Client Implementation
slack/client.ts
Added private customBotName? and customBotAvatar?; constructor accepts both. postMessage sets as_user = false when customizing, applies username, and picks icon_emoji or icon_url based on avatar format (colon-wrapped emoji, http(s) URL, or wraps bare name with colons).
Configuration Layer
slack/mod.ts
Added customBotAvatar?: string to Props. new SlackClient(...) now forwards props.customBotName and props.customBotAvatar. Channel config derives `customBotName = config.displayName

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect avatar-format detection and edge cases (empty string, already-colon-wrapped, malformed URL).
  • Verify constructor parameter propagation and Props type update.
  • Confirm OAuth scope addition and README text accuracy.

Possibly related PRs

Suggested reviewers

  • mcandeia
  • viktormarinho

Poem

🐇 I tweak a name, I paint an icon bright,

Messages don a new hat this night,
Emoji hops or a URL glide,
Each note now wears a playful stride,
Hooray — our rabbit shipped delight!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning No pull request description was provided by the author. The repository's description template requires several key sections including "What is this Contribution About?", "Issue Link", "Loom Video", and "Demonstration Link". The complete absence of a description means all required contextual information, issue references, and supporting materials are missing, making it difficult for reviewers to understand the motivation, scope, and testing approach for these changes. The author must add a pull request description that follows the repository's template. At minimum, they should provide a clear explanation of the changes under "What is this Contribution About?", link the relevant issue number, and ideally include a Loom video or demonstration link to help reviewers understand the feature in action. These details are essential for the review process.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Add support for custom bot name and avatar in Slack client" accurately and concisely describes the main changes in this pull request. The changes across all modified files (slack/README.md, slack/client.ts, slack/mod.ts, and slack/utils/constants.ts) collectively implement support for custom bot name and avatar configuration in the Slack client, which is exactly what the title conveys. The title is specific, clear, and meaningful—it avoids vague terms and directly communicates the primary change from a developer's perspective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/slack-bot-configurable

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 463d282 and 7a85f57.

📒 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 (4)
slack/client.ts (4)

272-273: LGTM!

The field declarations are clean and properly typed as optional strings.


275-288: LGTM!

The constructor properly accepts and assigns the new optional parameters. Backward compatibility is maintained since both parameters are optional.


382-403: LGTM! Previous issue has been resolved.

The custom avatar logic is now properly independent of the custom bot name, allowing either or both to be configured. The avatar format detection (emoji with colons, HTTP URL, or bare emoji name) is reasonable and handles common use cases well.


435-463: Verify: Should postReply also respect custom bot name and avatar?

The postReply method doesn't apply the custom bot name or avatar settings, while postMessage does. This means replies posted through this convenience method will use the default bot identity. Users can work around this by calling postMessage directly with thread_ts in the options.

Is this intentional, or should postReply also respect the custom bot settings for consistency?


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.129.1 update
  • 🎉 for Minor 0.130.0 update
  • 🚀 for Major 1.0.0 update

Co-authored-by: viktormarinho <[email protected]>
Cleaned up formatting by deleting an extra blank line in the SlackClient class for improved code readability.
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 customBotName and customBotAvatar without 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

📥 Commits

Reviewing files that changed from the base of the PR and between ed96b88 and 463d282.

📒 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 postReply method doesn't apply custom bot name and avatar settings, which creates an inconsistency with postMessage. 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.
@viktormarinho viktormarinho merged commit 0df144f into main Oct 30, 2025
2 checks passed
@viktormarinho viktormarinho deleted the feature/slack-bot-configurable branch October 30, 2025 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants