Skip to content

feat: add /view-skills CRM slash command#56

Merged
michaelmwu merged 1 commit intomainfrom
michaelmwu/view-skills-cmd
Feb 26, 2026
Merged

feat: add /view-skills CRM slash command#56
michaelmwu merged 1 commit intomainfrom
michaelmwu/view-skills-cmd

Conversation

@michaelmwu
Copy link
Member

@michaelmwu michaelmwu commented Feb 25, 2026

Description

Adds a new /view-skills CRM slash command for Members that shows either your own skills or a targeted contact's skills via optional search term (@mention, email, username, name, or contact ID).
The command prioritizes structured cSkillAttrs strengths, falls back to skills Multi-Enum when needed, and handles malformed cSkillAttrs JSON with best-effort recovery before dropping invalid payloads.
This also reuses existing skill-attribute parsing logic in CRMCog to avoid duplicate parsers and keeps audit logging behavior consistent with other CRM commands.

Related Issue

#46

How Has This Been Tested?

  • uv run pytest tests/unit/test_crm.py -q
  • uv run ruff check apps/discord_bot/src/five08/discord_bot/cogs/crm.py tests/unit/test_crm.py

Summary by CodeRabbit

  • New Features

    • Added view-skills command to display contact skills with strength levels
    • Supports lookup by @mention, Discord ID, or contact search
    • Implements inline selection when multiple matches found
  • Bug Fixes

    • Improved error handling for malformed skill data with recovery parsing
  • Tests

    • Added comprehensive test coverage for skill viewing, parsing, and error scenarios

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Warning

Rate limit exceeded

@michaelmwu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 76b7f30 and 922529e.

📒 Files selected for processing (2)
  • apps/discord_bot/src/five08/discord_bot/cogs/crm.py
  • tests/unit/test_crm.py
📝 Walkthrough

Walkthrough

Added Discord bot CRM module enhancements for skill viewing: new JSON parsing recovery helper, Discord ID extraction from @mentions, and a view-skills command supporting contact lookup by mention, direct ID, or name search with embed display and audit logging.

Changes

Cohort / File(s) Summary
CRM Skill View Helpers
apps/discord_bot/src/five08/discord_bot/cogs/crm.py
Introduced _parse_json_object_with_recovery for robust JSON parsing of malformed cSkillAttrs, _extract_discord_id_from_mention for @mention parsing, _extract_contact_skills_for_view to structure skill display with strengths, and _search_contacts_for_view_skills for multi-method contact resolution (mention, ID, name search).
View Skills Command
apps/discord_bot/src/five08/discord_bot/cogs/crm.py
Implemented view_skills async command supporting @mention/direct lookup, handling multiple matches with inline selection, retrieving full contact data, rendering skill embeds with CRM links, and maintaining audit logging for all outcomes.
CRM Unit Tests
tests/unit/test_crm.py
Added comprehensive test coverage for JSON recovery parsing, structured skill attribute display, fallback to plain skills, multi-contact refinement flow, and missing CRM linkage error handling.

Sequence Diagram

sequenceDiagram
    participant User
    participant CRMCog as CRM Cog
    participant ContactDB as Contact Lookup
    participant Discord as Discord API

    User->>CRMCog: /view_skills [`@mention` or search_term]
    alt By `@mention` or Direct ID
        CRMCog->>ContactDB: Lookup by Discord ID
    else By Name/Search Term
        CRMCog->>ContactDB: Search contacts with fallback suffix
    end
    
    ContactDB-->>CRMCog: Contact data (or multiple matches)
    
    alt Multiple Matches Found
        CRMCog->>User: Display selection prompt
        User->>CRMCog: Select contact
    else No Match
        CRMCog->>User: Send error embed
    end
    
    alt Contact Found
        CRMCog->>CRMCog: Extract skills from cSkillAttrs or raw skills
        CRMCog->>CRMCog: Build skill embed with strengths
        CRMCog->>Discord: Send embed with CRM link
        CRMCog->>CRMCog: Audit log success
    else Missing Linkage
        CRMCog->>User: Send linkage error
        CRMCog->>CRMCog: Audit log error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hop along now, skills on display!
JSON's twisted? No need to dismay—
Recovery parsing saves the day,
With @mentions and embeds on their way,
The view-skills command's here to stay! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and concisely describes the main feature: adding a new /view-skills CRM slash command, which aligns with the primary change across the modified files.
Docstring Coverage ✅ Passed Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch michaelmwu/view-skills-cmd

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.

Copy link

@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 (1)
tests/unit/test_crm.py (1)

293-306: Avoid mocking the lookup helper in the multi-match behavior test.

This patching pattern bypasses real lookup behavior, so regressions in contact-resolution logic won’t be caught. Prefer mocking espo_api.request and driving _search_contacts_for_view_skills end-to-end for this case.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_crm.py` around lines 293 - 306, The test currently patches
crm_cog._search_contacts_for_view_skills which hides contact-resolution logic;
instead remove the patch of _search_contacts_for_view_skills and simulate
backend responses by mocking espo_api.request so the real
_search_contacts_for_view_skills runs end-to-end, then call
crm_cog.view_skills.callback with mock_interaction and "john" and assert the
multi-match refine behavior; reference crm_cog,
_search_contacts_for_view_skills, espo_api.request, view_skills.callback and
mock_interaction when updating the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/discord_bot/src/five08/discord_bot/cogs/crm.py`:
- Around line 2407-2429: _search_contacts_for_view_skills currently delegates to
_search_contact_for_linking which forces maxSize=1 for queries with spaces,
allowing a single arbitrary contact to be returned for full-name queries; change
the behavior so full-name queries are not limited to a single result.
Specifically, update the call site in _search_contacts_for_view_skills to
request unrestricted (or a larger) result set from _search_contact_for_linking
(or pass an explicit parameter to override the maxSize=1 logic), and/or change
_search_contact_for_linking to stop applying maxSize=1 for queries that contain
spaces so that multiple matches are returned and the caller can prompt for
disambiguation.

---

Nitpick comments:
In `@tests/unit/test_crm.py`:
- Around line 293-306: The test currently patches
crm_cog._search_contacts_for_view_skills which hides contact-resolution logic;
instead remove the patch of _search_contacts_for_view_skills and simulate
backend responses by mocking espo_api.request so the real
_search_contacts_for_view_skills runs end-to-end, then call
crm_cog.view_skills.callback with mock_interaction and "john" and assert the
multi-match refine behavior; reference crm_cog,
_search_contacts_for_view_skills, espo_api.request, view_skills.callback and
mock_interaction when updating the test.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0545357 and 76b7f30.

📒 Files selected for processing (2)
  • apps/discord_bot/src/five08/discord_bot/cogs/crm.py
  • tests/unit/test_crm.py

@michaelmwu michaelmwu force-pushed the michaelmwu/view-skills-cmd branch from 76b7f30 to 922529e Compare February 26, 2026 07:48
@michaelmwu michaelmwu merged commit 602e003 into main Feb 26, 2026
5 checks passed
@michaelmwu michaelmwu deleted the michaelmwu/view-skills-cmd branch February 26, 2026 08:07
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.

1 participant