feat: implement search terms worksheet functionality#430
Merged
Conversation
- Added a new section for search terms in the conversations report. - Implemented the get_search_terms_worksheet method to retrieve search term data. - Introduced error handling for missing agent UUID configuration. - Updated tests to cover the new search terms functionality and ensure proper validation.
elitonzky
approved these changes
Jun 9, 2026
MarcusviniciusLsantos
approved these changes
Jun 9, 2026
- Implemented get_search_term_widget function to check for the existence of the search term widget for a given project. - Updated ConversationsReportService to include the search term widget in the available widgets list. - Enhanced unit tests to cover the new search term widget functionality and ensure proper validation.
…eportService - Removed conditional check for adding the search term widget to the available widgets list. - Integrated the search term widget directly into the special widgets retrieval process for improved clarity and efficiency.
…e/search-terms-metrics-report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
SEARCH_TERMSsection to the Conversations Report generation flow. When this section is selected, the generated report includes an extra "Search terms" worksheet containing the contact URN, the event date, and the searched term, sourced from datalakeweni_nexus_dataevents filtered by a configurable agent UUID and key.Changes include:
SEARCH_TERMSvalue inConversationsReportSections.get_search_terms_worksheetonBaseConversationsReportServiceand its concrete implementation onConversationsReportService.SEARCH_TERMSregistered in the worksheet mapping (_get_worksheets) and in the available widgets/sections list.CONVERSATIONS_METRICS_SEARCH_TERMS_AGENT_UUIDandCONVERSATIONS_METRICS_SEARCH_TERMS_KEY, raisingSearchTermsAgentUUIDNotConfiguredErrorwhen the agent UUID is missing._get_worksheets.Why
Customers need visibility into the search terms used by end contacts so they can analyze data directly from the Conversations Report. Exposing this data as an additional worksheet inside the existing report keeps the flow consistent with the other sections (CSAT, NPS, Tool Results, etc.) and reuses the datalake integration already in place.
Sequence diagram
sequenceDiagram participant Client participant View as ReportsView participant Serializer as RequestConversationsReportGenerationSerializer participant Service as ConversationsReportService participant Settings as Django settings participant Datalake as Datalake events participant Worksheet as ConversationsReportWorksheet Client->>View: POST generate report (sections=[SEARCH_TERMS]) View->>Serializer: validate payload Serializer-->>View: validated data View->>Service: generate report Service->>Service: _get_worksheets(report, start_date, end_date) Service->>Service: dispatch SEARCH_TERMS -> get_search_terms_worksheet Service->>Settings: read CONVERSATIONS_METRICS_SEARCH_TERMS_AGENT_UUID alt agent_uuid is empty Settings-->>Service: "" Service-->>View: raise SearchTermsAgentUUIDNotConfiguredError else agent_uuid is configured Settings-->>Service: agent_uuid Service->>Settings: read CONVERSATIONS_METRICS_SEARCH_TERMS_KEY Settings-->>Service: search_term_key Service->>Datalake: get_datalake_events(event_name=weni_nexus_data, key, metadata_key=agent_uuid, metadata_value) Datalake-->>Service: events list Service->>Service: translate headers using requester language alt events list is empty Service->>Worksheet: build worksheet with empty row else events list has items Service->>Worksheet: build rows (URN, Date, Terms) end Worksheet-->>Service: ConversationsReportWorksheet Service-->>View: worksheets including Search terms View-->>Client: report generated end