Unlimited Flexibility: Custom messages enable you to create any type of content beyond standard text, image, video, and file messages. Use structured JSON data to build polls, location sharing, interactive cards, booking widgets, and any specialized content your application requires.

Custom Message Overview

Custom messages provide unlimited flexibility for creating specialized content types using structured JSON data. Perfect for building interactive elements, complex data visualization, and application-specific functionality.

Flexible Structure

JSON-based data format
  • Free-form JSON object structure
  • Support for nested objects and arrays
  • Complex data type handling
  • Schema validation capabilities

Interactive Content

Rich user experiences
  • Surveys
  • Location sharing and maps
  • Booking and reservation widgets
  • Custom UI components

Implementation Guide

Simple custom data structuresCreate custom messages with structured JSON data for various use cases and interactive content.

Required Parameters

ParameterTypeDescription
subChannelIdStringTarget subchannel identifier for the custom message
dataObject/JSONFree-form JSON object containing your custom data structure

Optional Parameters

ParameterTypeDescription
tagsArray<String>Message categorization and filtering tags
parentIdStringParent message ID for threaded conversations
metadataObjectAdditional properties for extended functionality

Code Examples

// Basic custom message with simple data
let pollData: [String: Any] = [
    "type": "poll",
    "question": "What's your favorite programming language?",
    "options": [
        ["id": "swift", "text": "Swift", "votes": 0],
        ["id": "kotlin", "text": "Kotlin", "votes": 0],
        ["id": "typescript", "text": "TypeScript", "votes": 0],
        ["id": "python", "text": "Python", "votes": 0]
    ],
    "multiple_choice": false,
    "expires_at": "2024-01-20T23:59:59Z"
]

let options = AmityCustomMessageCreateOptions(
    subChannelId: "subChannel-123",
    data: pollData,
    tags: ["poll", "survey", "team"],
    parentId: nil
)

do {
    let message = try await messageRepository.createCustomMessage(options: options)
    print("Custom poll message sent: \(message.messageId)")
    
    // Access custom data
    if let customData = message.data as? [String: Any] {
        print("Poll question: \(customData["question"] ?? "")")
    }
} catch {
    print("Failed to send custom message: \(error)")
}
JSON Structure: Custom message data supports any valid JSON structure including nested objects, arrays, and primitive types. Design your data schema to match your UI requirements.

Custom Message Use Cases

Best Practices

Implementation Strategy: Start with simple custom message types like polls or location sharing, then progressively build more complex interactive content. Always validate your data schema and implement proper error handling for the best user experience.