Skip to content

Commit 81e6041

Browse files
committed
feat: migrate to new transcript API
1 parent 70fe5f5 commit 81e6041

5 files changed

Lines changed: 235 additions & 164 deletions

File tree

internal/types/voiceflow/transcript/fetchTranscriptInformationsResponseTypes copy.go

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package transcript
2+
3+
type TranscriptInformation struct {
4+
ID string `json:"id,omitempty"`
5+
ProjectID string `json:"projectID,omitempty"`
6+
SessionID string `json:"sessionID,omitempty"`
7+
EnvironmentID string `json:"environmentID,omitempty"`
8+
CreatedAt string `json:"createdAt,omitempty"`
9+
UpdatedAt string `json:"updatedAt,omitempty"`
10+
}
11+
12+
// SearchTranscriptsRequest is the request body for the search transcripts API.
13+
type SearchTranscriptsRequest struct {
14+
StartDate string `json:"startDate,omitempty"`
15+
EndDate string `json:"endDate,omitempty"`
16+
SessionID string `json:"sessionID,omitempty"`
17+
EnvironmentID string `json:"environmentID,omitempty"`
18+
}
19+
20+
// SearchTranscriptsResponse is the response from the search transcripts API.
21+
type SearchTranscriptsResponse struct {
22+
Transcripts []TranscriptInformation `json:"transcripts"`
23+
}

internal/types/voiceflow/transcript/fetchTranscriptJSONResponseTypes.go

Lines changed: 31 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,49 @@ type Turn struct {
1414
StartTime time.Time `json:"startTime"`
1515
}
1616

17-
type Payload struct {
18-
Time int64 `json:"time,omitempty"`
19-
Type string `json:"type,omitempty"`
20-
Payload interface{} `json:"payload,omitempty"`
17+
// GetTranscriptResponse is the wrapper for the v1 get-transcript API response.
18+
type GetTranscriptResponse struct {
19+
Transcript TranscriptDetail `json:"transcript"`
2120
}
2221

23-
type BlockPayload struct {
24-
BlockID string `json:"blockID"`
22+
// TranscriptDetail contains the transcript data from the v1 API.
23+
type TranscriptDetail struct {
24+
ID string `json:"id"`
25+
SessionID string `json:"sessionID"`
26+
ProjectID string `json:"projectID"`
27+
EnvironmentID string `json:"environmentID"`
28+
CreatedAt string `json:"createdAt"`
29+
UpdatedAt string `json:"updatedAt"`
30+
Logs []Log `json:"logs"`
2531
}
2632

27-
type FlowPayload struct {
28-
DiagramID string `json:"diagramID"`
33+
// Log represents a single log entry in the v1 transcript response.
34+
type Log struct {
35+
Type string `json:"type"`
36+
Data json.RawMessage `json:"data"`
37+
CreatedAt string `json:"createdAt"`
38+
UpdatedAt string `json:"updatedAt"`
2939
}
3040

31-
type DebugPayload struct {
32-
Type string `json:"type,omitempty"`
33-
Message string `json:"message"`
34-
}
35-
36-
type TextPayload struct {
37-
Slate Slate `json:"slate"`
38-
Message string `json:"message"`
39-
Delay int `json:"delay"`
40-
AI bool `json:"ai"`
41+
// LogData is used to partially parse the Data field of a Log entry.
42+
type LogData struct {
43+
Type string `json:"type"`
44+
Payload json.RawMessage `json:"payload,omitempty"`
4145
}
4246

43-
type Slate struct {
44-
ID string `json:"id"`
45-
Content []Content `json:"content"`
46-
MessageDelayMilliseconds int `json:"messageDelayMilliseconds"`
47-
}
48-
49-
type Content struct {
50-
Children []Children `json:"children"`
51-
}
52-
53-
type Children struct {
54-
Text string `json:"text"`
47+
type Payload struct {
48+
Time int64 `json:"time,omitempty"`
49+
Type string `json:"type,omitempty"`
50+
Payload interface{} `json:"payload,omitempty"`
5551
}
5652

57-
type RequestPayload struct {
58-
Type string `json:"type"`
59-
Payload IntentPayload `json:"payload"`
53+
type TextPayload struct {
54+
Message string `json:"message"`
6055
}
6156

6257
type IntentPayload struct {
63-
Query string `json:"query"`
64-
Intent Intent `json:"intent"`
65-
Entities []interface{} `json:"entities"`
66-
Confidence float64 `json:"confidence"`
67-
}
68-
69-
type Intent struct {
70-
Name string `json:"name"`
71-
}
72-
73-
type AIResponseParameters struct {
74-
System string `json:"system"`
75-
Assistant string `json:"assistant"`
76-
Output string `json:"output"`
77-
Model string `json:"model"`
78-
Temperature float64 `json:"temperature"`
79-
MaxTokens int `json:"maxTokens"`
80-
QueryTokens int `json:"queryTokens"`
81-
AnswerTokens int `json:"answerTokens"`
82-
Tokens int `json:"tokens"`
83-
Multiplier float64 `json:"multiplier"`
58+
Query string `json:"query"`
59+
Confidence float64 `json:"confidence"`
8460
}
8561

8662
// GetTextPayload extracts TextPayload from generic Payload
@@ -104,26 +80,7 @@ func (p Payload) GetTextPayload() (*TextPayload, error) {
10480
return &textPayload, nil
10581
}
10682

107-
func (p Payload) GetRequestPayload() (*RequestPayload, error) {
108-
// Modified condition to accept both "request" and "intent" types
109-
if p.Type != "request" {
110-
return nil, fmt.Errorf("payload type is not 'request' or 'intent', got: %s", p.Type)
111-
}
112-
113-
payloadBytes, err := json.Marshal(p.Payload)
114-
if err != nil {
115-
return nil, fmt.Errorf("failed to marshal request payload: %w", err)
116-
}
117-
118-
var requestPayload RequestPayload
119-
if err := json.Unmarshal(payloadBytes, &requestPayload); err != nil {
120-
return nil, fmt.Errorf("failed to unmarshal request payload: %w", err)
121-
}
122-
123-
return &requestPayload, nil
124-
}
125-
126-
// Add GetIntentPayload method
83+
// GetIntentPayload extracts IntentPayload from generic Payload
12784
func (p Payload) GetIntentPayload() (*IntentPayload, error) {
12885
if p.Type != "intent" {
12986
return nil, fmt.Errorf("payload type is not 'intent', got: %s", p.Type)

pkg/transcript/to-test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ func TranscriptToTest(transcriptJSON []transcript.Turn, testName, testDescriptio
7979
},
8080
},
8181
})
82+
case "user-text":
83+
userText, _ := turn.Payload.Payload.(string)
84+
agentResponse := findNextAgentTextResponse(transcriptJSON, index)
85+
test.Interactions = append(test.Interactions, tests.Interaction{
86+
ID: uuid.New().String(),
87+
User: tests.User{
88+
Text: userText,
89+
Type: "text",
90+
},
91+
Agent: tests.Agent{
92+
Validate: []tests.Validation{
93+
{
94+
ID: uuid.New().String(),
95+
Type: "equals",
96+
Value: agentResponse,
97+
},
98+
},
99+
},
100+
})
82101
}
83102
}
84103
return test, nil

0 commit comments

Comments
 (0)