Skip to content

Commit 3fdd47a

Browse files
committed
get-transcripts & updated get-call
1 parent 8fe1c71 commit 3fdd47a

File tree

5 files changed

+116
-6
lines changed

5 files changed

+116
-6
lines changed

components/twilio/actions/get-call/get-call.mjs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "twilio-get-call",
66
name: "Get Call",
77
description: "Return call resource of an individual call. [See the documentation](https://www.twilio.com/docs/voice/api/call-resource#fetch-a-call-resource)",
8-
version: "0.1.3",
8+
version: "0.1.4",
99
type: "action",
1010
props: {
1111
twilio,
@@ -16,9 +16,60 @@ export default {
1616
],
1717
optional: false,
1818
},
19+
includeTranscripts: {
20+
type: "boolean",
21+
label: "Include Transcripts",
22+
description: "Set to `true` to include recording transcript(s) if available",
23+
optional: true,
24+
},
25+
},
26+
methods: {
27+
async getTranscripts(callSid) {
28+
const transcripts = [];
29+
const recordings = await this.twilio.listRecordings({
30+
callSid,
31+
});
32+
for (const recording of recordings) {
33+
const recordingTranscripts = await this.getRecordingTranscripts(recording.sid);
34+
if (recordingTranscripts?.length) {
35+
transcripts.push(...recordingTranscripts);
36+
}
37+
}
38+
return transcripts;
39+
},
40+
async getRecordingTranscripts(sourceSid) {
41+
const transcripts = await this.twilio.listTranscripts({
42+
sourceSid,
43+
});
44+
const results = [];
45+
for (const transcript of transcripts) {
46+
const {
47+
sentences, transcript: fullTranscript,
48+
} = await this.twilio.getSentences(transcript.sid);
49+
results.push({
50+
...transcript,
51+
_version: undefined,
52+
sentences,
53+
transcript: fullTranscript,
54+
});
55+
}
56+
return results;
57+
},
1958
},
2059
async run({ $ }) {
21-
const resp = await this.twilio.getCall(this.sid);
60+
let resp = await this.twilio.getCall(this.sid);
61+
62+
if (this.includeTranscripts) {
63+
const transcripts = await this.getTranscripts(this.sid);
64+
if (transcripts?.length) {
65+
resp = {
66+
...resp,
67+
_version: undefined,
68+
transcripts,
69+
};
70+
}
71+
}
72+
2273
$.export("$summary", `Successfully fetched the call, "${callToString(resp)}"`);
2374
return resp;
2475
},
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import twilio from "../../twilio.app.mjs";
2+
3+
export default {
4+
key: "twilio-get-transcripts",
5+
name: "Get Transcripts",
6+
description: "Retrieves full transcripts for the specified transcript SIDs. [See the documentation](https://www.twilio.com/docs/voice/intelligence/api/transcript-sentence-resource#get-transcript-sentences)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
twilio,
11+
transcriptSids: {
12+
propDefinition: [
13+
twilio,
14+
"transcriptSids",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const transcripts = [];
20+
for (const sid of this.transcriptSids) {
21+
transcripts.push(await this.twilio.getTranscript(sid));
22+
}
23+
const results = [];
24+
for (const transcript of transcripts) {
25+
const {
26+
sentences, transcript: fullTranscript,
27+
} = await this.twilio.getSentences(transcript.sid);
28+
results.push({
29+
...transcript,
30+
_version: undefined,
31+
sentences,
32+
transcript: fullTranscript,
33+
});
34+
}
35+
$.export("$summary", `Successfully fetched ${results.length} transcript${results.length === 1
36+
? ""
37+
: "s"}`);
38+
return results;
39+
},
40+
};

components/twilio/common/utils.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function recordingToString(recording) {
136136
}
137137

138138
export {
139+
formatTimeElapsed,
139140
timeBetween,
140141
omitEmptyStringValues,
141142
callToString,

components/twilio/package.json

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

components/twilio/twilio.app.mjs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import twilio from "twilio";
22
import {
3+
formatTimeElapsed,
34
callToString,
45
messageToString,
56
recordingToString,
@@ -177,6 +178,22 @@ export default {
177178
})) || [];
178179
},
179180
},
181+
transcriptSids: {
182+
type: "string[]",
183+
label: "Transcript SIDs",
184+
description: "The unique SID identifiers of the Transcripts to retrieve",
185+
async options({ page }) {
186+
const transcripts = await this.listTranscripts({
187+
page,
188+
});
189+
return transcripts?.map(({
190+
sid: value, dateCreated, duration,
191+
}) => ({
192+
value,
193+
label: `${dateCreated} for ${formatTimeElapsed(duration)}`,
194+
})) || [];
195+
},
196+
},
180197
},
181198
methods: {
182199
validateRequest({
@@ -259,6 +276,10 @@ export default {
259276
const client = this.getClient();
260277
return client.intelligence.v2.transcripts(transcriptId).sentences.list(params);
261278
},
279+
getTranscript(transcriptId) {
280+
const client = this.getClient();
281+
return client.intelligence.v2.transcripts(transcriptId).fetch();
282+
},
262283
async getSentences(transcriptId) {
263284
const sentences = await this.listTranscriptSentences(transcriptId, {
264285
limit: 1000,
@@ -394,7 +415,6 @@ export default {
394415
const client = this.getClient();
395416
return client.recordings(sid).transcriptions.list(params);
396417
},
397-
398418
/**
399419
* Send a verification code via sms
400420
*
@@ -409,7 +429,6 @@ export default {
409429
channel: "sms",
410430
});
411431
},
412-
413432
/**
414433
* List all services
415434
*
@@ -419,7 +438,6 @@ export default {
419438
const client = this.getClient();
420439
return client.verify.v2.services.list();
421440
},
422-
423441
/**
424442
* Check whether the verification token is valid
425443
*

0 commit comments

Comments
 (0)