Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new prop to pre-process transcripts for human-readability. #14698

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: "Retrieve Transcripts Of Calls",
description: "Retrieve transcripts of calls. [See the documentation](https://us-66463.app.gong.io/settings/api/documentation#post-/v2/calls/transcript)",
type: "action",
version: "0.0.2",
version: "0.0.3",
props: {
app,
fromDateTime: {
Expand Down Expand Up @@ -35,6 +35,13 @@ export default {
"callIds",
],
},
returnSimplifiedTranscript: {
type: "boolean",
label: "Return Simplified Transcript",
description: "If true, returns a simplified version of the transcript with normalized speaker IDs and formatted timestamps",
optional: true,
default: false,
},
},
methods: {
retrieveTranscriptsOfCalls(args = {}) {
Expand All @@ -43,21 +50,101 @@ export default {
...args,
});
},

millisToTimestamp(millis) {
const totalSeconds = Math.floor(millis / 1000);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;

return `[${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}]`;
},

simplifyTranscript(originalResponse) {
const simplified = {
...originalResponse,
callTranscripts: originalResponse.callTranscripts.map((callTranscript) => {
// Create a map of unique speaker IDs to simplified names
const speakerMap = new Map();
let speakerCounter = 1;
let currentSpeaker = null;
let currentTopic = null;
let formattedTranscript = "";

// Process each sentence maintaining chronological order
const allSentences = [];
callTranscript.transcript.forEach((segment) => {
segment.sentences.forEach((sentence) => {
allSentences.push({
...sentence,
speakerId: segment.speakerId,
topic: segment.topic,
});
});
});

// Sort by start time
allSentences.sort((a, b) => a.start - b.start);

// Process sentences
allSentences.forEach((sentence) => {
// Map speaker ID to simplified name
if (!speakerMap.has(sentence.speakerId)) {
speakerMap.set(sentence.speakerId, `Speaker ${speakerCounter}`);
speakerCounter++;
}

const speaker = speakerMap.get(sentence.speakerId);
const timestamp = this.millisToTimestamp(sentence.start);

// Handle topic changes
if (sentence.topic !== currentTopic) {
currentTopic = sentence.topic;
if (currentTopic) {
formattedTranscript += `\nTopic: ${currentTopic}\n-------------------\n\n`;
}
}

// Add speaker name only if it changes
if (speaker !== currentSpeaker) {
currentSpeaker = speaker;
formattedTranscript += `\n${speaker}:\n`;
}

// Add timestamp and text
formattedTranscript += `${timestamp} ${sentence.text}\n`;
});

return {
callId: callTranscript.callId,
formattedTranscript: formattedTranscript.trim(),
};
}),
};

return simplified;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
},
run({ $: step }) {

async run({ $: step }) {
const {
// eslint-disable-next-line no-unused-vars
app,
retrieveTranscriptsOfCalls,
returnSimplifiedTranscript,
simplifyTranscript,
...filter
} = this;

return retrieveTranscriptsOfCalls({
const response = await retrieveTranscriptsOfCalls({
step,
data: {
filter,
},
summary: (response) => `Successfully retrieved transcripts of calls with request ID \`${response.requestId}\`.`,
});

if (returnSimplifiedTranscript) {
return simplifyTranscript(response);
}

return response;
},
};
2 changes: 1 addition & 1 deletion components/gong/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gong",
"version": "0.1.1",
"version": "0.1.2",
"description": "Pipedream Gong Components",
"main": "gong.app.mjs",
"keywords": [
Expand Down
Loading