From 3fdd47adb81bcbf65edb187af85c393dfccdc825 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 20 Nov 2024 17:43:39 -0500 Subject: [PATCH 1/2] get-transcripts & updated get-call --- .../twilio/actions/get-call/get-call.mjs | 55 ++++++++++++++++++- .../get-transcripts/get-transcripts.mjs | 40 ++++++++++++++ components/twilio/common/utils.mjs | 1 + components/twilio/package.json | 2 +- components/twilio/twilio.app.mjs | 24 +++++++- 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 components/twilio/actions/get-transcripts/get-transcripts.mjs diff --git a/components/twilio/actions/get-call/get-call.mjs b/components/twilio/actions/get-call/get-call.mjs index d29b67b07e030..a5c9c49f7eb8d 100644 --- a/components/twilio/actions/get-call/get-call.mjs +++ b/components/twilio/actions/get-call/get-call.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-get-call", name: "Get Call", description: "Return call resource of an individual call. [See the documentation](https://www.twilio.com/docs/voice/api/call-resource#fetch-a-call-resource)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, @@ -16,9 +16,60 @@ export default { ], optional: false, }, + includeTranscripts: { + type: "boolean", + label: "Include Transcripts", + description: "Set to `true` to include recording transcript(s) if available", + optional: true, + }, + }, + methods: { + async getTranscripts(callSid) { + const transcripts = []; + const recordings = await this.twilio.listRecordings({ + callSid, + }); + for (const recording of recordings) { + const recordingTranscripts = await this.getRecordingTranscripts(recording.sid); + if (recordingTranscripts?.length) { + transcripts.push(...recordingTranscripts); + } + } + return transcripts; + }, + async getRecordingTranscripts(sourceSid) { + const transcripts = await this.twilio.listTranscripts({ + sourceSid, + }); + const results = []; + for (const transcript of transcripts) { + const { + sentences, transcript: fullTranscript, + } = await this.twilio.getSentences(transcript.sid); + results.push({ + ...transcript, + _version: undefined, + sentences, + transcript: fullTranscript, + }); + } + return results; + }, }, async run({ $ }) { - const resp = await this.twilio.getCall(this.sid); + let resp = await this.twilio.getCall(this.sid); + + if (this.includeTranscripts) { + const transcripts = await this.getTranscripts(this.sid); + if (transcripts?.length) { + resp = { + ...resp, + _version: undefined, + transcripts, + }; + } + } + $.export("$summary", `Successfully fetched the call, "${callToString(resp)}"`); return resp; }, diff --git a/components/twilio/actions/get-transcripts/get-transcripts.mjs b/components/twilio/actions/get-transcripts/get-transcripts.mjs new file mode 100644 index 0000000000000..8fa68dcc6061d --- /dev/null +++ b/components/twilio/actions/get-transcripts/get-transcripts.mjs @@ -0,0 +1,40 @@ +import twilio from "../../twilio.app.mjs"; + +export default { + key: "twilio-get-transcripts", + name: "Get Transcripts", + 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)", + version: "0.0.1", + type: "action", + props: { + twilio, + transcriptSids: { + propDefinition: [ + twilio, + "transcriptSids", + ], + }, + }, + async run({ $ }) { + const transcripts = []; + for (const sid of this.transcriptSids) { + transcripts.push(await this.twilio.getTranscript(sid)); + } + const results = []; + for (const transcript of transcripts) { + const { + sentences, transcript: fullTranscript, + } = await this.twilio.getSentences(transcript.sid); + results.push({ + ...transcript, + _version: undefined, + sentences, + transcript: fullTranscript, + }); + } + $.export("$summary", `Successfully fetched ${results.length} transcript${results.length === 1 + ? "" + : "s"}`); + return results; + }, +}; diff --git a/components/twilio/common/utils.mjs b/components/twilio/common/utils.mjs index 17fdf5ddda4f6..5985df4e5371c 100644 --- a/components/twilio/common/utils.mjs +++ b/components/twilio/common/utils.mjs @@ -136,6 +136,7 @@ function recordingToString(recording) { } export { + formatTimeElapsed, timeBetween, omitEmptyStringValues, callToString, diff --git a/components/twilio/package.json b/components/twilio/package.json index 2a1635097dc0c..5ee746f484f20 100644 --- a/components/twilio/package.json +++ b/components/twilio/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/twilio", - "version": "0.5.0", + "version": "0.6.0", "description": "Pipedream Twilio Components", "main": "twilio.app.mjs", "keywords": [ diff --git a/components/twilio/twilio.app.mjs b/components/twilio/twilio.app.mjs index 2080fb05daac8..65c95a08bce4e 100644 --- a/components/twilio/twilio.app.mjs +++ b/components/twilio/twilio.app.mjs @@ -1,5 +1,6 @@ import twilio from "twilio"; import { + formatTimeElapsed, callToString, messageToString, recordingToString, @@ -177,6 +178,22 @@ export default { })) || []; }, }, + transcriptSids: { + type: "string[]", + label: "Transcript SIDs", + description: "The unique SID identifiers of the Transcripts to retrieve", + async options({ page }) { + const transcripts = await this.listTranscripts({ + page, + }); + return transcripts?.map(({ + sid: value, dateCreated, duration, + }) => ({ + value, + label: `${dateCreated} for ${formatTimeElapsed(duration)}`, + })) || []; + }, + }, }, methods: { validateRequest({ @@ -259,6 +276,10 @@ export default { const client = this.getClient(); return client.intelligence.v2.transcripts(transcriptId).sentences.list(params); }, + getTranscript(transcriptId) { + const client = this.getClient(); + return client.intelligence.v2.transcripts(transcriptId).fetch(); + }, async getSentences(transcriptId) { const sentences = await this.listTranscriptSentences(transcriptId, { limit: 1000, @@ -394,7 +415,6 @@ export default { const client = this.getClient(); return client.recordings(sid).transcriptions.list(params); }, - /** * Send a verification code via sms * @@ -409,7 +429,6 @@ export default { channel: "sms", }); }, - /** * List all services * @@ -419,7 +438,6 @@ export default { const client = this.getClient(); return client.verify.v2.services.list(); }, - /** * Check whether the verification token is valid * From 4bb1afeb4bc3a3b730d00bff5dd0420c1637b26d Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 20 Nov 2024 17:47:39 -0500 Subject: [PATCH 2/2] versions --- .../check-verification-token/check-verification-token.mjs | 2 +- .../create-verification-service/create-verification-service.mjs | 2 +- components/twilio/actions/delete-call/delete-call.mjs | 2 +- components/twilio/actions/delete-message/delete-message.mjs | 2 +- .../download-recording-media/download-recording-media.mjs | 2 +- components/twilio/actions/get-message/get-message.mjs | 2 +- components/twilio/actions/list-calls/list-calls.mjs | 2 +- .../twilio/actions/list-message-media/list-message-media.mjs | 2 +- components/twilio/actions/list-messages/list-messages.mjs | 2 +- components/twilio/actions/list-transcripts/list-transcripts.mjs | 2 +- components/twilio/actions/make-phone-call/make-phone-call.mjs | 2 +- .../twilio/actions/phone-number-lookup/phone-number-lookup.mjs | 2 +- components/twilio/actions/send-message/send-message.mjs | 2 +- .../actions/send-sms-verification/send-sms-verification.mjs | 2 +- components/twilio/sources/new-call/new-call.mjs | 2 +- components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs | 2 +- components/twilio/sources/new-phone-number/new-phone-number.mjs | 2 +- components/twilio/sources/new-recording/new-recording.mjs | 2 +- .../sources/new-transcript-created/new-transcript-created.mjs | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/components/twilio/actions/check-verification-token/check-verification-token.mjs b/components/twilio/actions/check-verification-token/check-verification-token.mjs index ac0d31fa1c99d..50b5c7d04f635 100644 --- a/components/twilio/actions/check-verification-token/check-verification-token.mjs +++ b/components/twilio/actions/check-verification-token/check-verification-token.mjs @@ -6,7 +6,7 @@ export default { name: "Check Verification Token", description: "Check if user-provided token is correct. [See the documentation](https://www.twilio.com/docs/verify/api)", type: "action", - version: "0.0.2", + version: "0.0.3", props: { app, serviceSid: { diff --git a/components/twilio/actions/create-verification-service/create-verification-service.mjs b/components/twilio/actions/create-verification-service/create-verification-service.mjs index 916078333308b..a21260daa8d01 100644 --- a/components/twilio/actions/create-verification-service/create-verification-service.mjs +++ b/components/twilio/actions/create-verification-service/create-verification-service.mjs @@ -5,7 +5,7 @@ export default { name: "Create Verification Service", description: "Create a verification service for sending SMS verifications. [See the documentation](https://www.twilio.com/docs/verify/api/service#create-a-verification-service)", type: "action", - version: "0.0.1", + version: "0.0.2", props: { twilio, friendlyName: { diff --git a/components/twilio/actions/delete-call/delete-call.mjs b/components/twilio/actions/delete-call/delete-call.mjs index d7b1b92267dcf..b1c2253b0de8c 100644 --- a/components/twilio/actions/delete-call/delete-call.mjs +++ b/components/twilio/actions/delete-call/delete-call.mjs @@ -4,7 +4,7 @@ export default { key: "twilio-delete-call", name: "Delete Call", description: "Remove a call record from your account. [See the documentation](https://www.twilio.com/docs/voice/api/call-resource#delete-a-call-resource)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, diff --git a/components/twilio/actions/delete-message/delete-message.mjs b/components/twilio/actions/delete-message/delete-message.mjs index 1bfb71fd27d91..75d98ecbb7286 100644 --- a/components/twilio/actions/delete-message/delete-message.mjs +++ b/components/twilio/actions/delete-message/delete-message.mjs @@ -4,7 +4,7 @@ export default { key: "twilio-delete-message", name: "Delete Message", description: "Delete a message record from your account. [See the documentation](https://www.twilio.com/docs/sms/api/message-resource#delete-a-message-resource)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, diff --git a/components/twilio/actions/download-recording-media/download-recording-media.mjs b/components/twilio/actions/download-recording-media/download-recording-media.mjs index 570a276aecb6a..33a9340e6f14a 100644 --- a/components/twilio/actions/download-recording-media/download-recording-media.mjs +++ b/components/twilio/actions/download-recording-media/download-recording-media.mjs @@ -8,7 +8,7 @@ export default { key: "twilio-download-recording-media", name: "Download Recording Media", description: "Download a recording media file. [See the documentation](https://www.twilio.com/docs/voice/api/recording#fetch-a-recording-media-file)", - version: "0.1.5", + version: "0.1.6", type: "action", props: { twilio, diff --git a/components/twilio/actions/get-message/get-message.mjs b/components/twilio/actions/get-message/get-message.mjs index 5af74af277e87..f5f65eed531f2 100644 --- a/components/twilio/actions/get-message/get-message.mjs +++ b/components/twilio/actions/get-message/get-message.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-get-message", name: "Get Message", description: "Return details of a message. [See the documentation](https://www.twilio.com/docs/sms/api/message-resource#fetch-a-message-resource)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, diff --git a/components/twilio/actions/list-calls/list-calls.mjs b/components/twilio/actions/list-calls/list-calls.mjs index 0f64a583fddc4..66276d614c32d 100644 --- a/components/twilio/actions/list-calls/list-calls.mjs +++ b/components/twilio/actions/list-calls/list-calls.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-list-calls", name: "List Calls", description: "Return a list of calls associated with your account. [See the documentation](https://www.twilio.com/docs/voice/api/call-resource#read-multiple-call-resources)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, diff --git a/components/twilio/actions/list-message-media/list-message-media.mjs b/components/twilio/actions/list-message-media/list-message-media.mjs index 4aec0ead589e7..dddef1db1ec6e 100644 --- a/components/twilio/actions/list-message-media/list-message-media.mjs +++ b/components/twilio/actions/list-message-media/list-message-media.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-list-message-media", name: "List Message Media", description: "Return a list of media associated with your message. [See the documentation](https://www.twilio.com/docs/sms/api/media-resource#read-multiple-media-resources)", - version: "0.1.3", + version: "0.1.4", type: "action", props: { twilio, diff --git a/components/twilio/actions/list-messages/list-messages.mjs b/components/twilio/actions/list-messages/list-messages.mjs index e5ebb2d7c145f..78da1e45289e5 100644 --- a/components/twilio/actions/list-messages/list-messages.mjs +++ b/components/twilio/actions/list-messages/list-messages.mjs @@ -6,7 +6,7 @@ export default { key: "twilio-list-messages", name: "List Messages", description: "Return a list of messages associated with your account. [See the documentation](https://www.twilio.com/docs/sms/api/message-resource#read-multiple-message-resources)", - version: "0.1.4", + version: "0.1.5", type: "action", props: { twilio, diff --git a/components/twilio/actions/list-transcripts/list-transcripts.mjs b/components/twilio/actions/list-transcripts/list-transcripts.mjs index 0638d97520c03..012970cf1740c 100644 --- a/components/twilio/actions/list-transcripts/list-transcripts.mjs +++ b/components/twilio/actions/list-transcripts/list-transcripts.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-list-transcripts", name: "List Transcripts", description: "Return a list of transcripts. [See the documentation](https://www.twilio.com/docs/voice/intelligence/api/transcript-resource#fetch-multiple-transcripts)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { twilio, diff --git a/components/twilio/actions/make-phone-call/make-phone-call.mjs b/components/twilio/actions/make-phone-call/make-phone-call.mjs index d7afc09598444..5ba8a59c2bb12 100644 --- a/components/twilio/actions/make-phone-call/make-phone-call.mjs +++ b/components/twilio/actions/make-phone-call/make-phone-call.mjs @@ -6,7 +6,7 @@ export default { key: "twilio-make-phone-call", name: "Make a Phone Call", description: "Make a phone call passing text, a URL, or an application that Twilio will use to handle the call. [See the documentation](https://www.twilio.com/docs/voice/api/call-resource#create-a-call-resource)", - version: "0.1.4", + version: "0.1.5", type: "action", props: { twilio, diff --git a/components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs b/components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs index f7fbd9d5b688a..6867ea35e5b7b 100644 --- a/components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs +++ b/components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs @@ -5,7 +5,7 @@ export default { name: "Phone Number Lookup", description: "Lookup information about a phone number. [See the documentation](https://www.twilio.com/docs/lookup/v2-api/line-type-intelligence) for more information", type: "action", - version: "0.0.1", + version: "0.0.2", props: { app, sid: { diff --git a/components/twilio/actions/send-message/send-message.mjs b/components/twilio/actions/send-message/send-message.mjs index 2cfc3600b9191..57c495861d802 100644 --- a/components/twilio/actions/send-message/send-message.mjs +++ b/components/twilio/actions/send-message/send-message.mjs @@ -7,7 +7,7 @@ export default { name: "Send Message", description: "Send an SMS text with optional media files. [See the documentation](https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource)", type: "action", - version: "0.0.1", + version: "0.0.2", props: { twilio, from: { diff --git a/components/twilio/actions/send-sms-verification/send-sms-verification.mjs b/components/twilio/actions/send-sms-verification/send-sms-verification.mjs index 0d808ef4a9c99..465c23a9af42c 100644 --- a/components/twilio/actions/send-sms-verification/send-sms-verification.mjs +++ b/components/twilio/actions/send-sms-verification/send-sms-verification.mjs @@ -5,7 +5,7 @@ export default { name: "Send SMS Verification", description: "Send an SMS verification to a phone number. [See the documentation](https://www.twilio.com/docs/verify/api)", type: "action", - version: "0.0.2", + version: "0.0.3", props: { app, serviceSid: { diff --git a/components/twilio/sources/new-call/new-call.mjs b/components/twilio/sources/new-call/new-call.mjs index 892fe12a4ad15..2036834890d80 100644 --- a/components/twilio/sources/new-call/new-call.mjs +++ b/components/twilio/sources/new-call/new-call.mjs @@ -6,7 +6,7 @@ export default { key: "twilio-new-call", name: "New Call (Instant)", description: "Emit new event each time a call to the phone number is completed. Configures a webhook in Twilio, tied to a phone number.", - version: "0.1.4", + version: "0.1.5", type: "source", dedupe: "unique", methods: { diff --git a/components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs b/components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs index f04d9f619e0a9..8385831a82aae 100644 --- a/components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs +++ b/components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs @@ -9,7 +9,7 @@ export default { key: "twilio-new-incoming-sms", name: "New Incoming SMS (Instant)", description: "Emit new event every time an SMS is sent to the phone number set. Configures a webhook in Twilio, tied to an incoming phone number.", - version: "0.1.4", + version: "0.1.5", type: "source", dedupe: "unique", props: { diff --git a/components/twilio/sources/new-phone-number/new-phone-number.mjs b/components/twilio/sources/new-phone-number/new-phone-number.mjs index 39297d5420451..84354bf6a8406 100644 --- a/components/twilio/sources/new-phone-number/new-phone-number.mjs +++ b/components/twilio/sources/new-phone-number/new-phone-number.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-new-phone-number", name: "New Phone Number", description: "Emit new event when you add a new phone number to your account", - version: "0.1.5", + version: "0.1.6", type: "source", dedupe: "unique", methods: { diff --git a/components/twilio/sources/new-recording/new-recording.mjs b/components/twilio/sources/new-recording/new-recording.mjs index 761f515bcabd2..32d00fae95610 100644 --- a/components/twilio/sources/new-recording/new-recording.mjs +++ b/components/twilio/sources/new-recording/new-recording.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-new-recording", name: "New Recording", description: "Emit new event when a new call recording is created", - version: "0.1.5", + version: "0.1.6", type: "source", dedupe: "unique", methods: { diff --git a/components/twilio/sources/new-transcript-created/new-transcript-created.mjs b/components/twilio/sources/new-transcript-created/new-transcript-created.mjs index fb53e8d932ba7..66a7882d67c79 100644 --- a/components/twilio/sources/new-transcript-created/new-transcript-created.mjs +++ b/components/twilio/sources/new-transcript-created/new-transcript-created.mjs @@ -5,7 +5,7 @@ export default { key: "twilio-new-transcript-created", name: "New Transcript Created", description: "Emit new event when a new call transcript is created", - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", props: {