Skip to content

feat(salesforce): add Knowledge AI connector with role-based agent/supervisor indexing#889

Open
Mattallmighty wants to merge 10 commits intoCognigy:masterfrom
Mattallmighty:master
Open

feat(salesforce): add Knowledge AI connector with role-based agent/supervisor indexing#889
Mattallmighty wants to merge 10 commits intoCognigy:masterfrom
Mattallmighty:master

Conversation

@Mattallmighty
Copy link
Copy Markdown

Summary

Adds a Salesforce Knowledge connector for Cognigy Knowledge AI that imports published Salesforce Knowledge Articles into a Cognigy Knowledge Store, with configurable role-based content separation between agent-facing and supervisor/manager-only views.

Changes

src/knowledge-connectors/salesforceKnowledgeConnector.ts (new)

Role-based content separation

Each article produces up to two knowledge sources:

  • Agent source — indexes a configurable set of content fields (e.g. Overview__c, Details__c, Processing_Steps_Text__c) and applies a configurable agent tag. Agent Copilot filters by this tag.
  • Supervisor source — indexes a separate set of manager-only fields (e.g. Manager_Actions__c, Manager_scripting__c) and applies a configurable supervisor tag. Only created when the article actually has content in those fields. Supervisor Copilot filters by both tags to surface the full article.

Robust text processing pipeline

  1. HTML stripping that preserves document structure — tables become pipe-separated rows, lists become bullet points, headings and paragraphs produce line breaks
  2. Non-printable character sanitization to prevent vector store embedding rejections
  3. Smart chunking at natural boundaries (double newline → single newline → sentence boundary → word boundary) with a configurable max chunk size (default 2 000 chars)
  4. Source name sanitization to comply with Cognigy's resource-name format — handles en/em dashes, ampersands, parentheses, slashes, and other special characters commonly found in Knowledge Article titles

Chunk metadata

Each chunk carries articleNumber, role (agent / supervisor), and url (Lightning URL to the source article) for context display in Agent Copilot.

Fully configurable via the connector UI

Field Default Description
Knowledge Article Object API Name Knowledge_Article__kav Supports custom article types
Language en_US SOQL language filter
Agent Content Fields 10 default fields textArray — no code changes needed
Agent Knowledge Tags ["agent"] Applied to agent sources
Supervisor / Manager Content Fields 4 default fields Collapsible section
Supervisor Knowledge Tags ["supervisor"] Applied to supervisor sources

src/knowledge-connectors/cognigyManagementApi.ts (new)

Thin axios wrapper providing paginated listing and deletion of knowledge sources — operations not exposed by to support incremental sync use cases.

src/module.ts (modified)

Registers salesforceKnowledgeConnector alongside the existing Salesforce nodes.

SOQL Query

SELECT Id, KnowledgeArticleId, ArticleNumber, Title, Summary, UrlName,
       Language, LastPublishedDate, <configured fields>
FROM   <KnowledgeApiName>
WHERE  PublishStatus = 'Online'
  AND  Language      = '<configured language>'
  AND  IsLatestVersion = true
ORDER BY Title ASC

autoFetch: true is used so all pages are retrieved in a single call.

Validation

Tested against a Salesforce sandbox with 688 published en_US articles:

- All 688 articles produce clean ASCII chunks with zero vector store rejections
- 688 agent sources · 64 supervisor sources · 752 total sources · 1 243 chunks
- Source name sanitization correctly handles the 352/688 articles whose titles contain special characters
- Articles with no supervisor content produce no unnecessary empty sources

… status ID bug

searchContact:
  - Replace SELECT FIELDS(All) with a two-step approach (SELECT Id + sobject.retrieve)
    to avoid requiring the "View All Data" Salesforce permission, which was causing 400
    errors across orgs
  - Change LIKE to = to support orgs with Salesforce Shield encryption on fields such
    as Email, where LIKE is not a supported operator
  - Add ORDER BY CreatedDate DESC for deterministic results when multiple records match
  - Add onErrorContact child node so errors route correctly instead of crashing with
    "Cannot read properties of undefined (reading 'id')"
  - Add null guard on onErrorChild to prevent cascade crash if child is not yet wired
    in an existing flow
  - Improve error logging to include Salesforce response body for easier debugging

  createCase:
  - Fix Status optionsResolver returning status.Id (the CaseStatus metadata record ID)
    instead of status.MasterLabel (the actual picklist string value e.g. "New"), which
    was causing cases to be created with an ID in the Status field rather than the
    human-readable value

  authenticate:
  - Fix missing semicolon on closing brace of exported arrow function (lint error)
 * Features:
 *  - Local state file (import-state.json) tracks what's been imported and when
 *  - Skip articles that are already up-to-date (same LastPublishedDate)
 *  - Delete + recreate articles whose content has changed
 *  - Retry with exponential backoff on 405/429/502/503
 *  - --from=N flag to resume from a specific article index (1-based)
htmlFieldToMarkdown() (replaces stripHtml)
  Converts HTML to proper Markdown instead of stripping it flat. Headings inside a field are shifted down (e.g. <h2>
  inside an Overview field → ####) so they sit correctly below the ## Overview field label.
Copilot AI review requested due to automatic review settings March 4, 2026 20:45
@graymalkin77
Copy link
Copy Markdown

graymalkin77 commented Mar 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Salesforce Knowledge connector to the Salesforce extension, enabling ingestion of published Salesforce Knowledge articles into Cognigy Knowledge AI with role-based (agent vs supervisor/manager) separation, plus a couple of related Salesforce node/package updates.

Changes:

  • Introduces a new salesforceKnowledgeConnector that queries published Salesforce Knowledge articles, converts field HTML to Markdown, chunks content, and creates agent/supervisor-tagged sources.
  • Adds a small Cognigy Management API wrapper to list/delete knowledge sources for stale cleanup use cases.
  • Updates the Salesforce extension module registration and improves the searchContact node’s branching/error handling; adjusts Case Status option mapping.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
extensions/salesforce/src/nodes/searchContact.ts Adds an explicit On Error branch and switches to an ID lookup + sobject.retrieve() for full record retrieval.
extensions/salesforce/src/nodes/createCase.ts Changes Case Status select option values to use MasterLabel (picklist value) instead of Id.
extensions/salesforce/src/module.ts Registers the new Salesforce Knowledge connector and the new onErrorContact node.
extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts New connector implementing role-based indexing, HTML→Markdown conversion, chunking, and stale-source cleanup logic.
extensions/salesforce/src/knowledge-connectors/cognigyManagementApi.ts New axios wrapper for listing/deleting knowledge sources via Cognigy Management API.
extensions/salesforce/src/authenticate.ts Small formatting/termination fix.
extensions/salesforce/package.json Version bump and dev dependency additions.
extensions/salesforce/package-lock.json Lockfile updates for the dependency changes.
Files not reviewed (1)
  • extensions/salesforce/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/salesforce/src/nodes/searchContact.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/package-lock.json
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
   - searchContact: escape single quotes in SOQL string literal to prevent injection
   - sanitizeText: preserve printable Unicode (accented chars, CJK, etc.) — only
     strip C0/C1 control characters, not all non-ASCII
   - salesforceKnowledgeConnector: guard agentFields/supervisorFields with
     Array.isArray so undefined supervisorFields doesn't throw at runtime
   - salesforceKnowledgeConnector: validate lastSyncDate as ISO 8601 before
     embedding in SOQL; throw a descriptive error on invalid input
   - salesforceKnowledgeConnector: prefix source names with [SF:<articleNumber>]
     so stale-removal pattern is unambiguous in shared knowledge stores
   - cognigyManagementApi: strip trailing slashes from apiUrl before building
     request paths to prevent double-slash issues
   - package-lock.json: regenerate to sync version with package.json (4.5.1)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • extensions/salesforce/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • extensions/salesforce/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
Comment thread extensions/salesforce/src/knowledge-connectors/salesforceKnowledgeConnector.ts Outdated
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