From cba4437eef83a31bfeb26a291d873f7aed7fda9f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:03:50 +0000 Subject: [PATCH 1/4] Initial plan From 0dacfe2e1d0caa6c161c675af497effe937afa82 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:07:36 +0000 Subject: [PATCH 2/4] Initial exploration of Content API structure and existing examples Co-authored-by: tiwarishubham635 <59199353+tiwarishubham635@users.noreply.github.com> --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 80b2e0069..827b4e549 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,6 @@ require ( ) retract ( - v1.25.0 // Contains build issue - v1.22.0 // Contains known bug + v1.25.0 // Contains build issue + v1.22.0 // Contains known bug ) From f7cbf3c8bf953c9271f926cab113a45c814220c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:12:08 +0000 Subject: [PATCH 3/4] Add comprehensive Content API examples with all major content types Co-authored-by: tiwarishubham635 <59199353+tiwarishubham635@users.noreply.github.com> --- advanced-examples/content.md | 507 ++++++++++++++++++++++++++++++++++- 1 file changed, 494 insertions(+), 13 deletions(-) diff --git a/advanced-examples/content.md b/advanced-examples/content.md index a0d285c5f..00558d77d 100644 --- a/advanced-examples/content.md +++ b/advanced-examples/content.md @@ -1,3 +1,9 @@ +# Twilio Content API Examples + +This document provides comprehensive examples for using Twilio's Content API with different content types. The Content API allows you to create, manage, and send structured content templates with various interactive elements. + +## Basic Setup + ```go package main @@ -10,30 +16,505 @@ import ( content "github.com/twilio/twilio-go/rest/content/v1" ) -func createContent(client *twilio.RestClient) { - twilioText := &content.TwilioText{Body: "Hello World"} +func main() { + accountSid := os.Getenv("TWILIO_ACCOUNT_SID") + authToken := os.Getenv("TWILIO_AUTH_TOKEN") + + client := twilio.NewRestClientWithParams(twilio.ClientParams{ + Username: accountSid, + Password: authToken, + }) + + // Examples of different content types + createTextContent(client) + createMediaContent(client) + createCardContent(client) + createListPickerContent(client) + createCallToActionContent(client) + createQuickReplyContent(client) + createCarouselContent(client) + createLocationContent(client) + + // Examples of other operations + listContent(client) + fetchContent(client, "your-content-sid") // Replace with actual SID +} +``` + +## 1. Text Content (twilio/text) + +Simple text-based content for basic messaging. + +```go +func createTextContent(client *twilio.RestClient) { + fmt.Println("Creating Text Content...") + + twilioText := &content.TwilioText{ + Body: "Hello! Welcome to our service. We're excited to help you today.", + } + contentType := &content.Types{TwilioText: twilioText} - createContentRequest := &content.ContentCreateRequest{Language: "en", Types: *contentType} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Welcome Message", + Language: "en", + Types: *contentType, + Variables: map[string]string{ + "1": "customer_name", + }, + } + params := &content.CreateContentParams{} params.SetContentCreateRequest(*createContentRequest) resp, err := client.ContentV1.CreateContent(params) if err != nil { - fmt.Println("Error creating content: " + err.Error()) + fmt.Println("Error creating text content: " + err.Error()) } else { response, _ := json.Marshal(*resp) - fmt.Println("Response: " + string(response)) + fmt.Println("Text Content Response: " + string(response)) } } +``` -func main() { - accountSid := os.Getenv("TWILIO_ACCOUNT_SID") - authToken := os.Getenv("TWILIO_AUTH_TOKEN") +## 2. Media Content (twilio/media) - client := twilio.NewRestClientWithParams(twilio.ClientParams{ - Username: accountSid, - Password: authToken, - }) - createContent(client) +Content with image, video, or document attachments. + +```go +func createMediaContent(client *twilio.RestClient) { + fmt.Println("Creating Media Content...") + + twilioMedia := &content.TwilioMedia{ + Body: "Check out our latest product catalog!", + Media: []string{ + "https://example.com/product-image.jpg", + "https://example.com/product-video.mp4", + }, + } + + contentType := &content.Types{TwilioMedia: twilioMedia} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Product Catalog", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating media content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Media Content Response: " + string(response)) + } +} +``` + +## 3. Card Content (twilio/card) + +Structured card with title, subtitle, media, and action buttons. + +```go +func createCardContent(client *twilio.RestClient) { + fmt.Println("Creating Card Content...") + + cardActions := []content.CardAction{ + { + Type: content.CARDACTIONTYPE_URL, + Title: "View Details", + Url: "https://example.com/product/123", + }, + { + Type: content.CARDACTIONTYPE_PHONE_NUMBER, + Title: "Call Support", + Phone: "+1234567890", + }, + } + + twilioCard := &content.TwilioCard{ + Title: "Premium Wireless Headphones", + Subtitle: "High-quality sound with noise cancellation", + Media: []string{ + "https://example.com/headphones.jpg", + }, + Actions: cardActions, + } + + contentType := &content.Types{TwilioCard: twilioCard} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Product Card", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating card content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Card Content Response: " + string(response)) + } +} +``` + +## 4. List Picker Content (twilio/list-picker) + +Interactive menu with selectable options. + +```go +func createListPickerContent(client *twilio.RestClient) { + fmt.Println("Creating List Picker Content...") + + listItems := []content.ListItem{ + { + Id: "support", + Item: "Customer Support", + Description: "Get help with your account", + }, + { + Id: "billing", + Item: "Billing Information", + Description: "View and manage your billing", + }, + { + Id: "products", + Item: "Our Products", + Description: "Browse our product catalog", + }, + } + + twilioListPicker := &content.TwilioListPicker{ + Body: "How can we help you today? Please select an option:", + Button: "Select Option", + Items: listItems, + } + + contentType := &content.Types{TwilioListPicker: twilioListPicker} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Help Menu", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating list picker content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("List Picker Content Response: " + string(response)) + } +} +``` + +## 5. Call to Action Content (twilio/call-to-action) + +Content with action buttons for URLs, phone calls, etc. + +```go +func createCallToActionContent(client *twilio.RestClient) { + fmt.Println("Creating Call to Action Content...") + + ctaActions := []content.CallToActionAction{ + { + Type: content.CALLTOACTIONACTIONTYPE_URL, + Title: "Visit Website", + Url: "https://example.com", + }, + { + Type: content.CALLTOACTIONACTIONTYPE_PHONE_NUMBER, + Title: "Call Now", + Phone: "+1234567890", + }, + { + Type: content.CALLTOACTIONACTIONTYPE_COPY_CODE, + Title: "Copy Discount Code", + Code: "SAVE20", + }, + } + + twilioCallToAction := &content.TwilioCallToAction{ + Body: "Special offer just for you! Get 20% off your next purchase.", + Actions: ctaActions, + } + + contentType := &content.Types{TwilioCallToAction: twilioCallToAction} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Discount Offer", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating call to action content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Call to Action Content Response: " + string(response)) + } +} +``` + +## 6. Quick Reply Content (twilio/quick-reply) + +Content with quick reply buttons for easy user responses. + +```go +func createQuickReplyContent(client *twilio.RestClient) { + fmt.Println("Creating Quick Reply Content...") + + quickReplyActions := []content.QuickReplyAction{ + { + Type: content.QUICKREPLYACTIONTYPE_QUICK_REPLY, + Title: "Yes", + Id: "yes", + }, + { + Type: content.QUICKREPLYACTIONTYPE_QUICK_REPLY, + Title: "No", + Id: "no", + }, + { + Type: content.QUICKREPLYACTIONTYPE_QUICK_REPLY, + Title: "Maybe", + Id: "maybe", + }, + } + + twilioQuickReply := &content.TwilioQuickReply{ + Body: "Are you interested in receiving updates about our new products?", + Actions: quickReplyActions, + } + + contentType := &content.Types{TwilioQuickReply: twilioQuickReply} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Product Updates Survey", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating quick reply content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Quick Reply Content Response: " + string(response)) + } +} +``` + +## 7. Carousel Content (twilio/carousel) + +Multiple cards in a horizontally scrollable format. + +```go +func createCarouselContent(client *twilio.RestClient) { + fmt.Println("Creating Carousel Content...") + + carouselCards := []content.CarouselCard{ + { + Title: "Premium Headphones", + Body: "High-quality audio experience", + Media: "https://example.com/headphones.jpg", + Actions: []content.CarouselAction{ + { + Type: content.CAROUSELACTIONTYPE_URL, + Title: "View Details", + Url: "https://example.com/product/headphones", + }, + }, + }, + { + Title: "Wireless Speaker", + Body: "Portable sound for everywhere", + Media: "https://example.com/speaker.jpg", + Actions: []content.CarouselAction{ + { + Type: content.CAROUSELACTIONTYPE_URL, + Title: "Learn More", + Url: "https://example.com/product/speaker", + }, + }, + }, + { + Title: "Smart Watch", + Body: "Stay connected on the go", + Media: "https://example.com/watch.jpg", + Actions: []content.CarouselAction{ + { + Type: content.CAROUSELACTIONTYPE_QUICK_REPLY, + Title: "Add to Cart", + Id: "add_watch", + }, + }, + }, + } + + twilioCarousel := &content.TwilioCarousel{ + Body: "Check out our featured products:", + Cards: carouselCards, + } + + contentType := &content.Types{TwilioCarousel: twilioCarousel} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Featured Products Carousel", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating carousel content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Carousel Content Response: " + string(response)) + } +} +``` + +## 8. Location Content (twilio/location) + +Share location information with recipients. + +```go +func createLocationContent(client *twilio.RestClient) { + fmt.Println("Creating Location Content...") + + twilioLocation := &content.TwilioLocation{ + Latitude: 37.7749, // San Francisco latitude + Longitude: -122.4194, // San Francisco longitude + Label: "Twilio Headquarters", + Address: "375 Beale St, San Francisco, CA 94105", + Id: "twilio-hq", + } + + contentType := &content.Types{TwilioLocation: twilioLocation} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Office Location", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Println("Error creating location content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Location Content Response: " + string(response)) + } +} +``` + +## 9. List Content + +Retrieve all content templates for your account. + +```go +func listContent(client *twilio.RestClient) { + fmt.Println("Listing Content...") + + params := &content.ListContentParams{ + PageSize: &[]int{20}[0], // Get 20 items per page + Limit: &[]int{100}[0], // Maximum 100 items total + } + + resp, err := client.ContentV1.ListContent(params) + if err != nil { + fmt.Println("Error listing content: " + err.Error()) + } else { + fmt.Printf("Found %d content items\n", len(resp)) + for i, content := range resp { + fmt.Printf("Content %d: SID=%s, Name=%s\n", + i+1, + *content.Sid, + *content.FriendlyName) + } + } +} +``` + +## 10. Fetch Content + +Retrieve a specific content template by its SID. + +```go +func fetchContent(client *twilio.RestClient, contentSid string) { + fmt.Printf("Fetching Content with SID: %s\n", contentSid) + + resp, err := client.ContentV1.FetchContent(contentSid) + if err != nil { + fmt.Println("Error fetching content: " + err.Error()) + } else { + response, _ := json.Marshal(*resp) + fmt.Println("Fetched Content: " + string(response)) + } +} +``` + +## Content Types Overview + +The Content API supports various content types, each with specific use cases: + +- **twilio/text**: Plain text messages +- **twilio/media**: Messages with media attachments (images, videos, documents) +- **twilio/card**: Rich cards with titles, subtitles, media, and action buttons +- **twilio/list-picker**: Interactive menus with selectable options +- **twilio/call-to-action**: Messages with action buttons (URLs, phone calls, etc.) +- **twilio/quick-reply**: Messages with quick response buttons +- **twilio/catalog**: Product catalog displays +- **twilio/carousel**: Multiple cards in a scrollable format +- **twilio/location**: Location sharing +- **whatsapp/card**: WhatsApp-specific card format +- **whatsapp/authentication**: WhatsApp authentication templates + +## Variables and Personalization + +You can use variables in your content to personalize messages: + +```go +Variables: map[string]string{ + "1": "customer_name", + "2": "order_number", + "3": "delivery_date", +} +``` + +These variables can be replaced with actual values when sending the content. + +## Error Handling + +Always implement proper error handling when working with the Content API: + +```go +resp, err := client.ContentV1.CreateContent(params) +if err != nil { + // Handle specific error types + if strings.Contains(err.Error(), "authentication") { + fmt.Println("Authentication failed") + } else if strings.Contains(err.Error(), "validation") { + fmt.Println("Content validation failed") + } else { + fmt.Println("Unexpected error: " + err.Error()) + } + return } ``` From b0bc9d85e16d2d6c2e28fef682a6f7e808a27ab8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 Aug 2025 18:14:29 +0000 Subject: [PATCH 4/4] Add simple runnable example and documentation for Content API Co-authored-by: tiwarishubham635 <59199353+tiwarishubham635@users.noreply.github.com> --- advanced-examples/content.md | 2 + advanced-examples/content_api_README.md | 97 ++++++++++++++ advanced-examples/content_api_example.go | 163 +++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 advanced-examples/content_api_README.md create mode 100644 advanced-examples/content_api_example.go diff --git a/advanced-examples/content.md b/advanced-examples/content.md index 00558d77d..9e6593fea 100644 --- a/advanced-examples/content.md +++ b/advanced-examples/content.md @@ -2,6 +2,8 @@ This document provides comprehensive examples for using Twilio's Content API with different content types. The Content API allows you to create, manage, and send structured content templates with various interactive elements. +> **Quick Start**: For a simple runnable example, see [content_api_example.go](content_api_example.go) or the [Content API README](content_api_README.md). + ## Basic Setup ```go diff --git a/advanced-examples/content_api_README.md b/advanced-examples/content_api_README.md new file mode 100644 index 000000000..8aa062df6 --- /dev/null +++ b/advanced-examples/content_api_README.md @@ -0,0 +1,97 @@ +# Content API Examples + +This directory contains comprehensive examples for using Twilio's Content API with the twilio-go SDK. + +## Quick Start + +### 1. Simple Runnable Example + +For a quick introduction, run the standalone example: + +```bash +export TWILIO_ACCOUNT_SID=your_account_sid +export TWILIO_AUTH_TOKEN=your_auth_token +go run content_api_example.go +``` + +This example shows the basics: +- Creating text, media, and card content +- Listing existing content +- Handling responses and errors + +### 2. Comprehensive Examples + +See [content.md](content.md) for detailed examples covering all content types: + +- **twilio/text** - Simple text messages +- **twilio/media** - Messages with images/videos/documents +- **twilio/card** - Rich cards with action buttons +- **twilio/list-picker** - Interactive selection menus +- **twilio/call-to-action** - Action buttons (URLs, phone calls, etc.) +- **twilio/quick-reply** - Quick response buttons +- **twilio/carousel** - Multiple cards in scrollable format +- **twilio/location** - Location sharing + +## Content Types Overview + +| Content Type | Use Case | Key Features | +|-------------|----------|--------------| +| `twilio/text` | Simple messaging | Plain text with variable substitution | +| `twilio/media` | Rich media | Images, videos, documents + optional text | +| `twilio/card` | Product showcases | Title, subtitle, media, action buttons | +| `twilio/list-picker` | Menu selection | Interactive list with descriptions | +| `twilio/call-to-action` | Action prompts | Multiple action buttons | +| `twilio/quick-reply` | Quick responses | Fast reply options | +| `twilio/carousel` | Product catalogs | Multiple cards in horizontal scroll | +| `twilio/location` | Location sharing | Coordinates with address/label | + +## Key Concepts + +### Variables and Personalization +```go +Variables: map[string]string{ + "1": "customer_name", + "2": "order_number", +} +``` +Use `{{1}}`, `{{2}}` etc. in your content text to substitute variables. + +### Action Types +Content can include interactive elements: +- **URL** - Open web links +- **PHONE_NUMBER** - Initiate phone calls +- **QUICK_REPLY** - Send predefined responses +- **COPY_CODE** - Copy codes to clipboard + +### Error Handling +Always check for errors when making API calls: +```go +resp, err := client.ContentV1.CreateContent(params) +if err != nil { + // Handle authentication, validation, or network errors + fmt.Printf("Error: %s\n", err.Error()) + return +} +``` + +## Authentication + +Set your Twilio credentials as environment variables: +```bash +export TWILIO_ACCOUNT_SID=your_account_sid +export TWILIO_AUTH_TOKEN=your_auth_token +``` + +Or pass them directly: +```go +client := twilio.NewRestClientWithParams(twilio.ClientParams{ + Username: "your_account_sid", + Password: "your_auth_token", +}) +``` + +## Additional Resources + +- [Twilio Content API Documentation](https://www.twilio.com/docs/content) +- [Content Types Overview](https://www.twilio.com/docs/content/content-types-overview) +- [twilio-go SDK Documentation](https://github.com/twilio/twilio-go) \ No newline at end of file diff --git a/advanced-examples/content_api_example.go b/advanced-examples/content_api_example.go new file mode 100644 index 000000000..4f5f84be5 --- /dev/null +++ b/advanced-examples/content_api_example.go @@ -0,0 +1,163 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/twilio/twilio-go" + content "github.com/twilio/twilio-go/rest/content/v1" +) + +// Simple example showing the most common Content API usage patterns +func main() { + accountSid := os.Getenv("TWILIO_ACCOUNT_SID") + authToken := os.Getenv("TWILIO_AUTH_TOKEN") + + if accountSid == "" || authToken == "" { + fmt.Println("Please set TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables") + fmt.Println("Example usage:") + fmt.Println(" export TWILIO_ACCOUNT_SID=your_account_sid") + fmt.Println(" export TWILIO_AUTH_TOKEN=your_auth_token") + fmt.Println(" go run content_api_example.go") + return + } + + client := twilio.NewRestClientWithParams(twilio.ClientParams{ + Username: accountSid, + Password: authToken, + }) + + fmt.Println("=== Twilio Content API Examples ===\n") + + // Example 1: Create simple text content + fmt.Println("1. Creating text content...") + createSimpleTextContent(client) + + // Example 2: Create media content + fmt.Println("\n2. Creating media content...") + createSimpleMediaContent(client) + + // Example 3: Create interactive card + fmt.Println("\n3. Creating card content...") + createSimpleCardContent(client) + + // Example 4: List existing content + fmt.Println("\n4. Listing content...") + listExistingContent(client) + + fmt.Println("\n=== Examples completed ===") + fmt.Println("For more advanced examples, see: advanced-examples/content.md") +} + +func createSimpleTextContent(client *twilio.RestClient) { + twilioText := &content.TwilioText{ + Body: "Hello {{1}}! Welcome to our service.", + } + + contentType := &content.Types{TwilioText: twilioText} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Simple Welcome Message", + Language: "en", + Types: *contentType, + Variables: map[string]string{ + "1": "customer_name", + }, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Printf(" Error: %s\n", err.Error()) + } else { + fmt.Printf(" ✓ Created content with SID: %s\n", *resp.Sid) + fmt.Printf(" ✓ Friendly name: %s\n", *resp.FriendlyName) + } +} + +func createSimpleMediaContent(client *twilio.RestClient) { + twilioMedia := &content.TwilioMedia{ + Body: "Check out this image!", + Media: []string{ + "https://picsum.photos/800/600", // Random placeholder image + }, + } + + contentType := &content.Types{TwilioMedia: twilioMedia} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Simple Media Content", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Printf(" Error: %s\n", err.Error()) + } else { + fmt.Printf(" ✓ Created media content with SID: %s\n", *resp.Sid) + fmt.Printf(" ✓ Friendly name: %s\n", *resp.FriendlyName) + } +} + +func createSimpleCardContent(client *twilio.RestClient) { + cardActions := []content.CardAction{ + { + Type: content.CARDACTIONTYPE_URL, + Title: "Learn More", + Url: "https://www.twilio.com", + }, + } + + twilioCard := &content.TwilioCard{ + Title: "Twilio Communications", + Subtitle: "APIs for SMS, Voice, Video & more", + Actions: cardActions, + } + + contentType := &content.Types{TwilioCard: twilioCard} + createContentRequest := &content.ContentCreateRequest{ + FriendlyName: "Simple Card Content", + Language: "en", + Types: *contentType, + } + + params := &content.CreateContentParams{} + params.SetContentCreateRequest(*createContentRequest) + + resp, err := client.ContentV1.CreateContent(params) + if err != nil { + fmt.Printf(" Error: %s\n", err.Error()) + } else { + fmt.Printf(" ✓ Created card content with SID: %s\n", *resp.Sid) + fmt.Printf(" ✓ Friendly name: %s\n", *resp.FriendlyName) + } +} + +func listExistingContent(client *twilio.RestClient) { + params := &content.ListContentParams{ + PageSize: &[]int{5}[0], // Get just 5 items for this example + } + + resp, err := client.ContentV1.ListContent(params) + if err != nil { + fmt.Printf(" Error: %s\n", err.Error()) + } else { + fmt.Printf(" ✓ Found %d content items\n", len(resp)) + for i, content := range resp { + fmt.Printf(" %d. %s (SID: %s)\n", i+1, *content.FriendlyName, *content.Sid) + } + + if len(resp) > 0 { + // Show details of the first content item + fmt.Printf("\n Example content details:\n") + firstContent := resp[0] + contentJson, _ := json.MarshalIndent(firstContent, " ", " ") + fmt.Printf(" %s\n", string(contentJson)) + } + } +} \ No newline at end of file