Skip to content

Commit da1f99f

Browse files
Adding a new prop to pre-process transcripts for human-readability. (#14698)
* Adding a new prop to pre-process transcripts for human-readability. * Refactoring to use direct array manipulation per Coderabbit suggestion.
1 parent f5bcfc9 commit da1f99f

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

components/gong/actions/retrieve-transcripts-of-calls/retrieve-transcripts-of-calls.mjs

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Retrieve Transcripts Of Calls",
66
description: "Retrieve transcripts of calls. [See the documentation](https://us-66463.app.gong.io/settings/api/documentation#post-/v2/calls/transcript)",
77
type: "action",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
props: {
1010
app,
1111
fromDateTime: {
@@ -35,6 +35,13 @@ export default {
3535
"callIds",
3636
],
3737
},
38+
returnSimplifiedTranscript: {
39+
type: "boolean",
40+
label: "Return Simplified Transcript",
41+
description: "If true, returns a simplified version of the transcript with normalized speaker IDs and formatted timestamps",
42+
optional: true,
43+
default: false,
44+
},
3845
},
3946
methods: {
4047
retrieveTranscriptsOfCalls(args = {}) {
@@ -43,21 +50,101 @@ export default {
4350
...args,
4451
});
4552
},
53+
54+
millisToTimestamp(millis) {
55+
const totalSeconds = Math.floor(millis / 1000);
56+
const minutes = Math.floor(totalSeconds / 60);
57+
const seconds = totalSeconds % 60;
58+
59+
return `[${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}]`;
60+
},
61+
62+
simplifyTranscript(originalResponse) {
63+
const simplified = {
64+
...originalResponse,
65+
callTranscripts: originalResponse.callTranscripts.map((callTranscript) => {
66+
// Create a map of unique speaker IDs to simplified names
67+
const speakerMap = new Map();
68+
let speakerCounter = 1;
69+
let currentSpeaker = null;
70+
let currentTopic = null;
71+
let formattedTranscript = "";
72+
73+
// Process each sentence maintaining chronological order
74+
const allSentences = [];
75+
callTranscript.transcript.forEach((segment) => {
76+
segment.sentences.forEach((sentence) => {
77+
allSentences.push({
78+
...sentence,
79+
speakerId: segment.speakerId,
80+
topic: segment.topic,
81+
});
82+
});
83+
});
84+
85+
// Sort by start time
86+
allSentences.sort((a, b) => a.start - b.start);
87+
88+
// Process sentences
89+
allSentences.forEach((sentence) => {
90+
// Map speaker ID to simplified name
91+
if (!speakerMap.has(sentence.speakerId)) {
92+
speakerMap.set(sentence.speakerId, `Speaker ${speakerCounter}`);
93+
speakerCounter++;
94+
}
95+
96+
const speaker = speakerMap.get(sentence.speakerId);
97+
const timestamp = this.millisToTimestamp(sentence.start);
98+
99+
// Handle topic changes
100+
if (sentence.topic !== currentTopic) {
101+
currentTopic = sentence.topic;
102+
if (currentTopic) {
103+
formattedTranscript += `\nTopic: ${currentTopic}\n-------------------\n\n`;
104+
}
105+
}
106+
107+
// Add speaker name only if it changes
108+
if (speaker !== currentSpeaker) {
109+
currentSpeaker = speaker;
110+
formattedTranscript += `\n${speaker}:\n`;
111+
}
112+
113+
// Add timestamp and text
114+
formattedTranscript += `${timestamp} ${sentence.text}\n`;
115+
});
116+
117+
return {
118+
callId: callTranscript.callId,
119+
formattedTranscript: formattedTranscript.trim(),
120+
};
121+
}),
122+
};
123+
124+
return simplified;
125+
},
46126
},
47-
run({ $: step }) {
127+
128+
async run({ $: step }) {
48129
const {
49-
// eslint-disable-next-line no-unused-vars
50-
app,
51130
retrieveTranscriptsOfCalls,
131+
returnSimplifiedTranscript,
132+
simplifyTranscript,
52133
...filter
53134
} = this;
54135

55-
return retrieveTranscriptsOfCalls({
136+
const response = await retrieveTranscriptsOfCalls({
56137
step,
57138
data: {
58139
filter,
59140
},
60141
summary: (response) => `Successfully retrieved transcripts of calls with request ID \`${response.requestId}\`.`,
61142
});
143+
144+
if (returnSimplifiedTranscript) {
145+
return simplifyTranscript(response);
146+
}
147+
148+
return response;
62149
},
63150
};

components/gong/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gong",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Pipedream Gong Components",
55
"main": "gong.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)