@@ -14,8 +14,9 @@ import (
1414)
1515
1616func FetchTranscriptInformations (agentID , startTime , endTime , tag , rang string ) ([]transcript.TranscriptInformation , error ) {
17- const pageSize = 100
17+ const pageSize = 99 // API max take is exclusive < 100
1818 var allTranscripts []transcript.TranscriptInformation
19+ seen := make (map [string ]bool )
1920
2021 reqBody := transcript.SearchTranscriptsRequest {}
2122 if startTime != "" {
@@ -25,8 +26,11 @@ func FetchTranscriptInformations(agentID, startTime, endTime, tag, rang string)
2526 reqBody .EndDate = endTime
2627 }
2728
28- for skip := 0 ; ; skip += pageSize {
29- url := fmt .Sprintf ("%s/v1/transcript/project/%s?take=%d&skip=%d&order=DESC" , global .GetAnalyticsBaseURL (), agentID , pageSize , skip )
29+ // Use cursor-based pagination with endDate to avoid skip limits.
30+ // Results are ordered DESC (newest first), so we move the endDate
31+ // cursor backwards after each full page.
32+ for {
33+ url := fmt .Sprintf ("%s/v1/transcript/project/%s?take=%d&skip=0&order=DESC" , global .GetAnalyticsBaseURL (), agentID , pageSize )
3034
3135 bodyBytes , err := json .Marshal (reqBody )
3236 if err != nil {
@@ -63,12 +67,25 @@ func FetchTranscriptInformations(agentID, startTime, endTime, tag, rang string)
6367 return nil , fmt .Errorf ("error unmarshalling response: %v" , err )
6468 }
6569
66- allTranscripts = append (allTranscripts , searchResponse .Transcripts ... )
70+ if len (searchResponse .Transcripts ) == 0 {
71+ break
72+ }
73+
74+ for _ , t := range searchResponse .Transcripts {
75+ if ! seen [t .ID ] {
76+ seen [t .ID ] = true
77+ allTranscripts = append (allTranscripts , t )
78+ }
79+ }
6780
6881 // If we got fewer results than the page size, we've reached the end
6982 if len (searchResponse .Transcripts ) < pageSize {
7083 break
7184 }
85+
86+ // Use the oldest transcript's createdAt as the new endDate cursor
87+ oldest := searchResponse .Transcripts [len (searchResponse .Transcripts )- 1 ]
88+ reqBody .EndDate = oldest .CreatedAt
7289 }
7390
7491 return allTranscripts , nil
@@ -87,8 +104,15 @@ func FetchTranscriptCSV(agentID, transcriptID string) ([][]string, error) {
87104 message := ""
88105 switch turn .Payload .Type {
89106 case "text" :
90- if tp , err := turn .Payload .GetTextPayload (); err == nil {
91- message = tp .Message
107+ if turn .Type == "user-text" {
108+ // User text payload is a plain string
109+ if s , ok := turn .Payload .Payload .(string ); ok {
110+ message = s
111+ }
112+ } else {
113+ if tp , err := turn .Payload .GetTextPayload (); err == nil {
114+ message = tp .Message
115+ }
92116 }
93117 case "intent" :
94118 if ip , err := turn .Payload .GetIntentPayload (); err == nil {
0 commit comments