Skip to content

feat(contact-center): Implementing get suggested response feature within CC SDK#4952

Open
Kesari3008 wants to merge 4 commits into
webex:task-refactorfrom
Kesari3008:Get-Suggested-Response-Implementation
Open

feat(contact-center): Implementing get suggested response feature within CC SDK#4952
Kesari3008 wants to merge 4 commits into
webex:task-refactorfrom
Kesari3008:Get-Suggested-Response-Implementation

Conversation

@Kesari3008
Copy link
Copy Markdown
Contributor

@Kesari3008 Kesari3008 commented May 5, 2026

COMPLETES #< INSERT LINK TO ISSUE >

This pull request addresses

Implementation for Get Suggestions feature

by making the following changes

  1. Added new events to be handled under real time websocket connection listener callbakc
  2. Added new method getSuggestedResponse exposed to users via cc.ApiAiAssistant object which invokes sendEvent() based on the received params.
  3. Modified sendEvent to accommodate parameters required for GET_SUGGESTIONS and ADD_SUGGESTIONS_EXTRA_CONTEXT events and send correct pyaload so that AI assistant can start listening on conversation and give suggestions.
  4. Sample app changes to add AI Assistant section.
  5. Updated UT for the changes done.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

https://app.vidcast.io/share/dc286450-408f-49d8-99b8-cf8b983db293?playerMode=vidcast

Screenshot 2026-05-07 at 10 13 18 PM

The GAI Coding Policy And Copyright Annotation Best Practices

  • GAI was not used (or, no additional notation is required)
  • Code was generated entirely by GAI
  • GAI was used to create a draft that was subsequently customized or modified
  • Coder created a draft manually that was non-substantively modified by GAI (e.g., refactoring was performed by GAI on manually written code)
  • Tool used for AI assistance (GitHub Copilot / Other - specify)
    • Github Copilot
    • Other - Please Specify
  • This PR is related to
    • Feature
    • Defect fix
    • Tech Debt
    • Automation

I certified that

  • I have read and followed contributing guidelines
  • I discussed changes with code owners prior to submitting this pull request
  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the documentation accordingly

Make sure to have followed the contributing guidelines before submitting.

@Kesari3008 Kesari3008 added the validated If the pull request is validated for automation. label May 6, 2026
@Kesari3008 Kesari3008 marked this pull request as ready for review May 7, 2026 08:04
@Kesari3008 Kesari3008 requested a review from a team as a code owner May 7, 2026 08:04
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f171b6631e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +179 to +181
const eventName = context
? AIAssistantEventName.ADD_SUGGESTIONS_EXTRA_CONTEXT
: AIAssistantEventName.GET_SUGGESTIONS;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive suggestion event from trimmed context

getSuggestedResponse() chooses ADD_SUGGESTIONS_EXTRA_CONTEXT based on the raw context value, but sends context?.trim() to the backend. If callers pass whitespace-only input (common from text fields), this emits the “add extra context” event with an empty context payload, which can be rejected or ignored by the AI service instead of issuing a normal GET_SUGGESTIONS request.

Useful? React with 👍 / 👎.

Comment on lines +104 to +106
case CC_EVENTS.POST_CALL_SUMMARY:
case CC_EVENTS.MID_CALL_SUMMARY:
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Emit summary RTD events instead of dropping them

This switch now explicitly swallows POST_CALL_SUMMARY and MID_CALL_SUMMARY RTD messages. Before this change, RTD payload types were re-emitted to the task, so these events would reach SDK consumers; after this commit they are silently discarded, which prevents any listener from receiving summary payloads even though these event constants were added to CC_EVENTS in the same change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48f08b217c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +101 to +103
case CC_EVENTS.SUGGESTED_RESPONSE_ACKNOWLEDGE:
// TODO: Handling this event
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Emit suggested-response acknowledge events to tasks

CC_EVENTS.SUGGESTED_RESPONSE_ACKNOWLEDGE was added as a task event, but this switch currently swallows it instead of re-emitting on the task. In environments where clients wait for an acknowledge before updating UI/request state, those listeners will never fire, so consumers cannot observe the backend acknowledgment despite the event being part of the exported event surface.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@Shreyas281299 Shreyas281299 left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Just 1 think that might be a privacy issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this ai-docs? These 4 files dont seem to fit with our ai-docs structure,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

break;
case CC_EVENTS.POST_CALL_SUMMARY:
case CC_EVENTS.MID_CALL_SUMMARY:
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these todos? If yes can we put some jiras for these todos

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are no JIRAs for these I think, I just added them because they will be implemented in future so I just added their case. I will remove the TODO comment


return 'en';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I dont think we should be accessing global like this. Ideally we should have a default and then we can ask customers to set a language using a public method, rather than accessing their browser window. Might get flagged as a privacy issue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, this can be moved out to a util file. We should keep the core logic in this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I missed it's implementation, fixed it now

@Kesari3008 Kesari3008 changed the title feat(contact-center): initial changes for implementing get suggested response feature feat(contact-center): Implementing get suggested response feature within CC SDK May 20, 2026
Copy link
Copy Markdown
Contributor

@rarajes2 rarajes2 left a comment

Choose a reason for hiding this comment

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

  1. Based on the data processing complexity handled in the samples app, should we consider handling that inside the core sdk logic itself and provide a processed data to the end application for easy consumption ?
  2. Please see if need to clean up the newly added ai-docs files
  3. Also, the JIRA link is missing, please update the PR description

const transcriptEntries = [];
const MAX_TRANSCRIPT_LINES = 200;
const MAX_AI_ASSISTANT_ENTRIES = 50;
const registeredTaskListeners = new WeakSet();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q. Why are we using WeakSet and not regular Set ?


const transcriptEntries = [];
const MAX_TRANSCRIPT_LINES = 200;
const MAX_AI_ASSISTANT_ENTRIES = 50;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q. Is this value set only for the samples page or this is the recommended value ?


function trimAiAssistantEntries(state) {
if (state.entries.length > MAX_AI_ASSISTANT_ENTRIES) {
state.entries.splice(0, state.entries.length - MAX_AI_ASSISTANT_ENTRIES);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we not keeping this data paginated ? Or is this because this info has to be short lived and agent does not have to scroll through to get the whole transcript at any time

}
}

function getAdaptiveCardTextLines(node, lines = []) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add js-doc with info on the structure of data it receives for node and lines ? It will be easy to understand the implementation with that since it's a recursive function

appendRealtimeTranscript(payload);
});

task.on('SUGGESTED_RESPONSE', (payload) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we keep the event name consistent with other casing ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For AI assistant features, they are independent features so they are realy tied 1:1 with task. All the task related event are received in terms of AgentContact or similar but these events are handled in different manner and their payload also differs quite a bit. These events are also received on different channels. Due to these differences, we are keeping different naming convention for these events

task.emit(payload.type, payload.data);
break;
case CC_EVENTS.SUGGESTED_RESPONSE_ACKNOWLEDGE:
// TODO: Handling this event
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have to address this in this PR itself or planning for future? We can add JIRA ticket link if needed to be handled later. We should add a log for the cases where it's silent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no Jira link for this. I added listening for this event just because this gets used to indicate whether AI assistant is in thinking or listening mode. But that's somehting we can keep internal to SDK hence in terms of implementation of this event, at present nothign is needed from the payload of this event but m not sure about future so just added the case for future refernce

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed these events for now


return 'en';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, this can be moved out to a util file. We should keep the core logic in this file

Comment on lines +183 to +187
LoggerProxy.info('Requesting suggested response', {
module: CC_FILE,
method: METHODS.GET_SUGGESTED_RESPONSE,
interactionId,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can also add debug log for success and error log in the catch block. loggerContext can be reused as separate variable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines +219 to +226
{
agentId,
orgId,
interactionId,
eventName,
trackingId,
context,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This info is repeated in success and failed cases. We can create a const with common fields

Comment on lines +743 to +746
if (
this.agentConfig.aiFeature?.realtimeTranscripts?.enable ||
this.agentConfig.aiFeature?.suggestedResponses?.enable
) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we update the associated TODO comment ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5efa0fc964

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

* @public
*/
public async getSuggestedResponse(params: SuggestedResponseParams): Promise<any> {
const {agentId, interactionId, context, languageCode} = params;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Default suggested-response language to English

getSuggestedResponse() forwards languageCode as-is, so when callers omit it the payload sends languageCode: undefined instead of the documented default ('en'). This changes behavior for the common path (no explicit language) and can cause backend routing/locale selection to be inconsistent or rejected if the service expects a concrete code. Add a local default (for example during destructuring) before calling sendEvent.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

validated If the pull request is validated for automation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants