Skip to content

Add comprehensive Content API examples with JSON payload demonstrations #758

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 20, 2025

The Content API was missing usage examples for creating message templates with JSON payloads. This was particularly challenging for developers because the API supports 13 different content types, each requiring specific JSON payload structures and different handling approaches.

This PR adds comprehensive examples demonstrating all Content API functionality:

New Files Added

examples/content_api_basic.rb

Basic content types for common messaging scenarios:

# Text content with variables
text_types = Twilio::REST::Content::V1::ContentList::Types.new({
  "twilio_text" => Twilio::REST::Content::V1::ContentList::TwilioText.new({
    "body" => "Hello {{1}}, this is a text message!"
  })
})

# Media content with attachments
media_types = Twilio::REST::Content::V1::ContentList::Types.new({
  "twilio_media" => Twilio::REST::Content::V1::ContentList::TwilioMedia.new({
    "body" => "Check out this amazing offer {{1}}!",
    "media" => ["https://example.com/image1.jpg"]
  })
})

examples/content_api_advanced.rb

Advanced interactive content types:

# Rich card layouts
card_types = Twilio::REST::Content::V1::ContentList::Types.new({
  "twilio_card" => Twilio::REST::Content::V1::ContentList::TwilioCard.new({
    "title" => "{{1}}",
    "subtitle" => "Special offer just for you!",
    "body" => "Get {{2}}% off your next purchase",
    "actions" => [/* action buttons */]
  })
})

# Product catalogs
catalog_types = Twilio::REST::Content::V1::ContentList::Types.new({
  "twilio_catalog" => Twilio::REST::Content::V1::ContentList::TwilioCatalog.new({
    "body" => "Browse our featured products:",
    "items" => [/* catalog items with pricing */]
  })
})

examples/content_api_whatsapp.rb

WhatsApp-specific content types and multi-language support:

# WhatsApp authentication templates
whatsapp_auth_types = Twilio::REST::Content::V1::ContentList::Types.new({
  "whatsapp_authentication" => Twilio::REST::Content::V1::ContentList::WhatsappAuthentication.new({
    "add_security_recommendation" => true,
    "code_expiration_minutes" => 10
  })
})

# Multi-language support
spanish_request = Twilio::REST::Content::V1::ContentList::ContentCreateRequest.new({
  "friendly_name" => "WhatsApp Greeting - Spanish",
  "language" => "es",
  "types" => spanish_types
})

examples/CONTENT_API.md

Comprehensive documentation covering:

  • All 13 content types with explanations
  • Usage instructions and setup guide
  • Variable handling and personalization
  • Multi-language template creation
  • Error handling best practices

Content Types Demonstrated

Twilio Content Types:

  • twilio/text - Simple text messages
  • twilio/media - Text with media attachments
  • twilio/location - Location sharing with coordinates
  • twilio/list-picker - Interactive selection menus
  • twilio/call-to-action - Action buttons (URL, phone)
  • twilio/quick-reply - Quick response buttons
  • twilio/card - Rich card layouts
  • twilio/catalog - Product catalogs with pricing
  • twilio/carousel - Horizontal scrolling cards
  • twilio/flows - Interactive conversation flows
  • twilio/schedule - Appointment scheduling

WhatsApp Content Types:

  • whatsapp/card - WhatsApp Business cards
  • whatsapp/authentication - OTP and authentication templates

Key Features

  • Complete JSON payload examples for each content type showing proper structure
  • Variable templating with {{1}}, {{2}} placeholder demonstration
  • Multi-language support with examples in English, Spanish, and French
  • Real-world scenarios including customer service, e-commerce, and appointment booking
  • Error handling patterns for common API issues
  • Both V1 and V2 API usage for creating and listing content

These examples directly address the challenge mentioned in the issue where developers needed guidance on handling different content types with their specific JSON payload requirements.

Fixes #757.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Author

Copilot AI commented Aug 20, 2025

@tiwarishubham635 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@Copilot Copilot AI changed the title [WIP] Content API examples missing Add comprehensive Content API examples with JSON payload demonstrations Aug 20, 2025
Copilot finished work on behalf of tiwarishubham635 August 20, 2025 18:15
@Copilot Copilot AI requested a review from tiwarishubham635 August 20, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content API examples missing
2 participants