-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Twilio - Get Transcript & update Get Call #14700
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThe pull request includes updates to various Twilio action components, primarily focusing on version increments and enhancements to functionality. Notably, a new action for retrieving transcripts has been introduced, along with modifications to existing actions to improve error handling and allow for additional properties. The changes maintain the overall structure and logic of the components while enhancing their capabilities. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TwilioAPI
participant Action
User->>Action: Request to get transcript
Action->>TwilioAPI: Fetch transcript by ID
TwilioAPI-->>Action: Return transcript data
Action-->>User: Provide transcript details
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (8)
components/twilio/sources/new-transcript-created/new-transcript-created.mjs (2)
Line range hint
22-35: Add error handling for transcript fetchingWhile the implementation is functionally correct, it lacks error handling for the
getSentencesAPI calls. Consider adding try-catch blocks to handle potential API failures gracefully.Here's a suggested improvement:
const transcripts = []; for (const result of results) { - const { - sentences, transcript, - } = await this.twilio.getSentences(result.sid); - transcripts.push({ - ...result, - sentences, - transcript, - }); + try { + const { + sentences, transcript, + } = await this.twilio.getSentences(result.sid); + transcripts.push({ + ...result, + sentences, + transcript, + }); + } catch (error) { + console.error(`Failed to fetch sentences for transcript ${result.sid}:`, error); + transcripts.push(result); + } }
Line range hint
22-35: Consider batch processing for better performanceThe current implementation makes a separate API call for each transcript when
includeTranscriptTextis true. This could lead to performance issues with large result sets.Consider implementing batch processing or pagination to optimize the API calls. This could involve:
- Processing transcripts in smaller batches
- Implementing concurrent API calls with rate limiting
- Adding pagination support to handle large datasets efficiently
Would you like assistance in implementing any of these optimizations?
components/twilio/actions/get-transcripts/get-transcripts.mjs (2)
9-17: Consider adding input validation for transcriptSidsWhile the props are well-structured, consider adding validation to ensure the transcriptSids array is not empty before processing.
transcriptSids: { propDefinition: [ twilio, "transcriptSids", ], + validate: (value) => { + if (!value?.length) { + throw new Error("At least one transcript SID is required"); + } + return true; + }, },
6-6: Enhance action documentationWhile the current description links to the API docs, consider adding examples of the action's usage and expected output format to improve developer experience.
- 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)", + description: "Retrieves full transcripts for the specified transcript SIDs. Returns both transcript metadata and sentence-level details for each transcript. [See the documentation](https://www.twilio.com/docs/voice/intelligence/api/transcript-sentence-resource#get-transcript-sentences)\n\nExample output:\n```json\n[{\n \"sid\": \"TR...\",\n \"sentences\": [...],\n \"transcript\": \"Full transcript text...\"\n}]\n```",components/twilio/actions/get-call/get-call.mjs (1)
Line range hint
1-76: Consider caching and rate limiting implementationWhile the implementation meets the requirements, consider these architectural improvements:
- Implement caching for transcript data to reduce API calls
- Add rate limiting to prevent API quota exhaustion
- Consider implementing a batch processing mode for multiple calls
Would you like assistance in implementing any of these architectural improvements?
components/twilio/common/utils.mjs (1)
Line range hint
13-38: Consider refactoring for better maintainability and consistencyWhile the function works correctly, consider refactoring it to improve maintainability and consistency in unit formatting:
function formatTimeElapsed(seconds) { - var interval = seconds / 31536000; - - if (interval > 1) { - return Math.floor(interval) + " years"; - } - interval = seconds / 2592000; - if (interval > 1) { - return Math.floor(interval) + " months"; - } - interval = seconds / 86400; - if (interval > 1) { - return Math.floor(interval) + "d"; - } - interval = seconds / 3600; - if (interval > 1) { - return Math.floor(interval) + "h"; - } - interval = seconds / 60; - if (interval > 1) { - return Math.floor(interval) + "min"; - } - return Math.floor(seconds) + "s"; + const TIME_UNITS = [ + { unit: 'y', seconds: 31536000 }, + { unit: 'mo', seconds: 2592000 }, + { unit: 'd', seconds: 86400 }, + { unit: 'h', seconds: 3600 }, + { unit: 'min', seconds: 60 }, + { unit: 's', seconds: 1 } + ]; + + for (const { unit, seconds: unitSeconds } of TIME_UNITS) { + const interval = seconds / unitSeconds; + if (interval >= 1) { + return `${Math.floor(interval)}${unit}`; + } + } + return '0s'; }Benefits:
- More maintainable with a single data structure
- Consistent unit abbreviations
- Easier to add/modify time units
- Handles edge case of 0 seconds explicitly
components/twilio/twilio.app.mjs (2)
181-196: Consider adding validation for maximum selectionsThe prop definition is well-structured and provides good user experience with formatted labels. However, consider adding a maximum limit to the number of transcript SIDs that can be selected to prevent potential performance issues or API rate limiting.
transcriptSids: { type: "string[]", label: "Transcript SIDs", description: "The unique SID identifiers of the Transcripts to retrieve", + max: 10, // or another appropriate limit async options({ page }) {
279-282: Add documentation and parameter validationWhile the implementation is correct, consider these improvements for consistency with other methods in the file:
- Add JSDoc documentation
- Add parameter validation
+ /** + * Returns a single transcript specified by the provided Transcript SID + * + * @param {String} transcriptId - The SID of the Transcript resource to fetch + * @returns {Promise<Object>} The transcript resource + * @throws {Error} If transcriptId is not provided or invalid + */ getTranscript(transcriptId) { + if (!transcriptId?.trim()) { + throw new Error("Transcript ID is required"); + } const client = this.getClient(); return client.intelligence.v2.transcripts(transcriptId).fetch(); },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (24)
components/twilio/actions/check-verification-token/check-verification-token.mjs(1 hunks)components/twilio/actions/create-verification-service/create-verification-service.mjs(1 hunks)components/twilio/actions/delete-call/delete-call.mjs(1 hunks)components/twilio/actions/delete-message/delete-message.mjs(1 hunks)components/twilio/actions/download-recording-media/download-recording-media.mjs(1 hunks)components/twilio/actions/get-call/get-call.mjs(2 hunks)components/twilio/actions/get-message/get-message.mjs(1 hunks)components/twilio/actions/get-transcripts/get-transcripts.mjs(1 hunks)components/twilio/actions/list-calls/list-calls.mjs(1 hunks)components/twilio/actions/list-message-media/list-message-media.mjs(1 hunks)components/twilio/actions/list-messages/list-messages.mjs(1 hunks)components/twilio/actions/list-transcripts/list-transcripts.mjs(1 hunks)components/twilio/actions/make-phone-call/make-phone-call.mjs(1 hunks)components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs(1 hunks)components/twilio/actions/send-message/send-message.mjs(1 hunks)components/twilio/actions/send-sms-verification/send-sms-verification.mjs(1 hunks)components/twilio/common/utils.mjs(1 hunks)components/twilio/package.json(1 hunks)components/twilio/sources/new-call/new-call.mjs(1 hunks)components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs(1 hunks)components/twilio/sources/new-phone-number/new-phone-number.mjs(1 hunks)components/twilio/sources/new-recording/new-recording.mjs(1 hunks)components/twilio/sources/new-transcript-created/new-transcript-created.mjs(1 hunks)components/twilio/twilio.app.mjs(3 hunks)
✅ Files skipped from review due to trivial changes (18)
- components/twilio/actions/create-verification-service/create-verification-service.mjs
- components/twilio/actions/delete-call/delete-call.mjs
- components/twilio/actions/delete-message/delete-message.mjs
- components/twilio/actions/download-recording-media/download-recording-media.mjs
- components/twilio/actions/get-message/get-message.mjs
- components/twilio/actions/list-calls/list-calls.mjs
- components/twilio/actions/list-message-media/list-message-media.mjs
- components/twilio/actions/list-messages/list-messages.mjs
- components/twilio/actions/list-transcripts/list-transcripts.mjs
- components/twilio/actions/make-phone-call/make-phone-call.mjs
- components/twilio/actions/phone-number-lookup/phone-number-lookup.mjs
- components/twilio/actions/send-message/send-message.mjs
- components/twilio/actions/send-sms-verification/send-sms-verification.mjs
- components/twilio/package.json
- components/twilio/sources/new-call/new-call.mjs
- components/twilio/sources/new-incoming-sms/new-incoming-sms.mjs
- components/twilio/sources/new-phone-number/new-phone-number.mjs
- components/twilio/sources/new-recording/new-recording.mjs
🔇 Additional comments (12)
components/twilio/sources/new-transcript-created/new-transcript-created.mjs (3)
8-8: Version bump is appropriate
The version increment from 0.0.1 to 0.0.2 is justified given the addition of the new transcript text inclusion feature.
Line range hint 37-46: LGTM! Meta generation looks good
The generateMeta implementation correctly uses the transcript's sid for deduplication and properly formats the timestamp.
Line range hint 13-18: Verify the performance impact of includeTranscriptText
The property implementation looks good and aligns with the common pattern. However, when enabled, it will make additional API calls to fetch sentence data for each transcript.
Let's check the common module for the property definition and rate limiting considerations:
✅ Verification successful
Performance impact of includeTranscriptText is acceptable
After reviewing the implementation, the performance concerns are adequately addressed:
- The
includeTranscriptTextproperty is optional and disabled by default - When enabled, it makes additional API calls only for new transcripts through the
getSentencesmethod - The implementation uses proper pagination with a reasonable limit of 1000 sentences per transcript
- The Twilio client handles rate limiting internally
The property implementation follows best practices and its performance impact is proportional to its utility.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check the property definition and any rate limiting logic
# Check the property definition
rg -A 5 "includeTranscriptText" --type js
# Look for rate limiting or pagination logic
ast-grep --pattern 'rateLimit'
Length of output: 72
Script:
#!/bin/bash
# Let's try a broader search in the common props directory and check for rate limiting
# First, find the common props file
fd props.twilio -t f
# Then check the content of any found files
fd props.twilio -t f -x cat {}
# Also search for rate limiting in Twilio related files
rg -i "rate.?limit" --type js $(fd -t f twilio)
Length of output: 140
Script:
#!/bin/bash
# Let's try a different approach to locate the common module and property definition
# First, check the directory structure around the source file
fd . components/twilio --type d
# Then look for common files or modules
fd common components/twilio --type f
# Finally, let's check the content of the source file itself to understand the import
cat components/twilio/sources/new-transcript-created/new-transcript-created.mjs
Length of output: 2505
Script:
#!/bin/bash
# Let's check the common polling file since we now know the import path
cat components/twilio/sources/common/common-polling.mjs
# Also check the Twilio app file for any rate limiting or API call handling
cat components/twilio/twilio.app.mjs
Length of output: 15876
components/twilio/actions/check-verification-token/check-verification-token.mjs (2)
Line range hint 38-44: LGTM! Improved error handling for verification failures
The enhanced error handling now provides a more descriptive message when a verification SID is not found, explaining the possible reasons (expiration, approval, or max attempts reached). This is a good user experience improvement.
Line range hint 1-48: Verify the inclusion of this file in the PR scope
This file's changes appear unrelated to the main PR objective of adding transcript functionality. While the improvements are valuable, they might be better suited for a separate PR focused on verification-related enhancements.
components/twilio/actions/get-transcripts/get-transcripts.mjs (1)
1-8: LGTM! Well-structured action metadata
The action metadata is well-defined with clear naming, appropriate versioning, and helpful documentation links.
components/twilio/actions/get-call/get-call.mjs (3)
8-8: Version bump is appropriate
The increment from 0.1.3 to 0.1.4 correctly reflects the addition of a new feature while maintaining backward compatibility.
19-24: Property definition looks good
The includeTranscripts property is well-defined with appropriate type, label, and description. It aligns perfectly with the PR objective of optionally including transcript information in call details.
60-71: Add response validation and document version removal
The run method modifications need some improvements:
- The removal of
_versionfield should be documented - Response validation should be added
- Error handling should be more explicit
Consider this improvement:
- let resp = await this.twilio.getCall(this.sid);
+ let resp = await this.twilio.getCall(this.sid)
+ .catch(err => {
+ throw new Error(`Failed to fetch call details: ${err.message}`);
+ });
+
+ if (!resp) {
+ throw new Error('No response received from Twilio API');
+ }
if (this.includeTranscripts) {
- const transcripts = await this.getTranscripts(this.sid);
+ try {
+ const transcripts = await this.getTranscripts(this.sid);
+ if (transcripts?.length) {
+ resp = {
+ ...resp,
+ _version: undefined, // Remove internal version tracking
+ transcripts,
+ };
+ }
+ } catch (err) {
+ console.log(`Failed to fetch transcripts: ${err.message}`);
+ // Continue without transcripts
+ }
- if (transcripts?.length) {
- resp = {
- ...resp,
- _version: undefined,
- transcripts,
- };
- }
}Let's verify if _version removal is consistent across the codebase:
components/twilio/common/utils.mjs (1)
139-139: LGTM!
The addition of formatTimeElapsed to exports is appropriate as it's used by external modules, and the export maintains good organization with alphabetical ordering.
components/twilio/twilio.app.mjs (2)
Line range hint 3-7: LGTM: Import changes are well-organized
The addition of formatTimeElapsed to the existing utility imports is clean and follows the established pattern.
279-282: Verify integration with existing transcript functionality
The new getTranscript method looks good, but let's verify its integration with existing transcript-related methods.
✅ Verification successful
Based on the search results, I can now provide a final response:
The getTranscript method is properly integrated with existing transcript functionality
The implementation aligns well with Twilio's transcript-related features:
- The method is part of a cohesive set of transcript-related methods including
listTranscripts()andlistTranscriptSentences() - It follows the same pattern of using Twilio's intelligence v2 API as the other transcript methods
- The method is used by other components in the codebase, particularly in the transcript-related actions under
components/twilio/actions/
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for consistent usage of transcript-related methods
# Check for any potential transcript-related method calls
echo "Checking for transcript method usage patterns..."
rg -A 2 "transcript|Transcript" --type js
# Check for any potential intelligence v2 API usage
echo "Checking for intelligence v2 API usage patterns..."
rg -B 2 "intelligence\.v2" --type js
Length of output: 300
Script:
#!/bin/bash
# Let's try a different approach to search for transcript-related functionality
# Search for transcript-related methods in the components directory
echo "Searching for transcript-related methods in components..."
rg -l "transcripts?\(" components/
# Look for files containing 'transcript' case-insensitive
echo "Searching for transcript-related files..."
fd -i transcript
# Check the specific file content
echo "Checking the twilio app file content..."
cat components/twilio/twilio.app.mjs
# Search for intelligence API usage
echo "Searching for intelligence API usage..."
rg "intelligence" components/
Length of output: 51508
components/twilio/actions/check-verification-token/check-verification-token.mjs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @michelle0927, LGTM! Ready for QA!
Resolves #14695
Summary by CodeRabbit
Release Notes
New Features
includeTranscriptsproperty to retrieve call recording transcripts.getTranscriptfor fetching specific transcripts by ID.formatTimeElapsedfor formatting durations.Bug Fixes
Version Updates