Skip to main content
Essential Communication: Text messages form the foundation of chat communication, enabling users to send up to 10,000 characters of rich text content with support for mentions, tags, metadata, and real-time delivery across all platforms.

Text Messaging Overview

Text messages provide the core communication functionality in social.plus Chat, supporting plain text, rich formatting, and advanced features like mentions and threading.

Rich Text Support

Flexible content formatting
  • Up to 10,000 characters per message
  • Unicode and emoji support
  • Mention functionality
  • Custom metadata attachment

Real-Time Delivery

Instant communication
  • Immediate local display
  • Background synchronization
  • Delivery status tracking
  • Cross-platform compatibility

Implementation Guide

  • Basic Text Messages
  • Enhanced Text Messages
  • Threaded Replies
Simple text message sendingSend plain text messages with essential parameters for immediate communication.

Required Parameters

ParameterTypeDescription
textStringThe text content to send (max 10,000 characters)
subChannelIdStringIdentifier for the subchannel where the message will be sent

Optional Parameters

ParameterTypeDescription
tagsArray<String>Arbitrary strings for message categorization and querying
metadataObjectAdditional custom properties for extended functionality
parentIdStringParent message ID for creating threaded replies

Code Examples

// Basic text message creation
let options = AmityTextMessageCreateOptions(
    subChannelId: "subChannel-123", 
    text: "Hi Amity!", 
    tags: nil, 
    parentId: nil, 
    metadata: nil, 
    mentioneesBuilder: nil
)

do {
    let message = try await messageRepository.createTextMessage(options: options)
    // Message sent successfully
    print("Message ID: \(message.messageId)")
} catch {
    // Handle error here
    print("Failed to send message: \(error)")
}
Character Limit: Text messages are limited to 10,000 characters. Messages exceeding this limit will return an error and will not be sent.

Text Message Features

Rich text capabilities and content handlingCharacter Support
  • Unicode Support: Full international character support including emojis
  • Special Characters: Support for symbols, mathematical notation, and special formatting
  • Line Breaks: Proper handling of multiline text content
  • Whitespace: Preserved spacing and formatting
Content Validation
  • Length Limits: 10,000 character maximum per message
  • Content Filtering: Automatic screening for prohibited content
  • Encoding: UTF-8 encoding for universal compatibility
  • Sanitization: Protection against malicious content injection
Example: Content Validation
function validateTextMessage(text: string): { valid: boolean; error?: string } {
  if (text.length === 0) {
    return { valid: false, error: 'Message cannot be empty' };
  }
  
  if (text.length > 10000) {
    return { valid: false, error: 'Message exceeds 10,000 character limit' };
  }
  
  // Additional validation logic
  return { valid: true };
}
Message organization and filtering capabilitiesTag Usage Patterns
  • Content Categories: Organize messages by topic or type
  • Priority Levels: Mark urgent or important messages
  • Department/Team: Route messages to specific groups
  • Message Types: Distinguish between announcements, questions, updates
Tag Best Practices
  • Use consistent naming conventions across your application
  • Implement tag validation to prevent typos and inconsistencies
  • Create predefined tag sets for common use cases
  • Enable tag-based filtering and search functionality
Example Tag Strategies
Tag Categories
{
  "content_type": ["announcement", "question", "update", "reminder"],
  "priority": ["low", "normal", "high", "urgent"],
  "department": ["engineering", "marketing", "sales", "hr"],
  "project": ["proj_alpha", "proj_beta", "maintenance"]
}
Extended functionality through custom dataMetadata Applications
  • Message Context: Store additional information about message purpose
  • Workflow Integration: Connect messages to external systems and processes
  • Analytics Tracking: Capture data for usage analytics and insights
  • Custom Features: Enable application-specific functionality
Structured Metadata Examples
Common Metadata Patterns
{
  "ui_settings": {
    "background_color": "#f0f0f0",
    "text_style": "bold",
    "highlight": true
  },
  "integration_data": {
    "ticket_id": "TICKET-123",
    "external_reference": "EXT-456",
    "workflow_step": "approval_pending"
  },
  "analytics": {
    "message_source": "mobile_app",
    "user_action": "quick_reply",
    "engagement_context": "onboarding"
  }
}
Metadata Best Practices
  • Keep metadata focused and purposeful
  • Use consistent schema across your application
  • Consider metadata size impact on message payload
  • Implement metadata validation for data integrity
Efficient text message handlingMessage Composition
  • Draft Management: Save and restore message drafts locally
  • Auto-Save: Implement periodic saving for longer messages
  • Validation: Perform client-side validation before sending
  • Compression: Consider text compression for very long messages
Network Optimization
  • Batching: Group multiple messages when appropriate
  • Retry Logic: Implement smart retry mechanisms for failed sends
  • Offline Queuing: Queue messages when connection is unavailable
  • Sync Status: Provide clear feedback on message delivery status
Memory Management
  • Message Caching: Implement efficient caching strategies
  • History Limits: Manage memory usage with message history limits
  • Cleanup: Remove old messages from local storage periodically
  • Lazy Loading: Load message content on demand for better performance
Example: Draft Management
class MessageDraftManager {
    private let userDefaults = UserDefaults.standard
    
    func saveDraft(for channelId: String, text: String) {
        userDefaults.set(text, forKey: "draft_\(channelId)")
    }
    
    func loadDraft(for channelId: String) -> String? {
        return userDefaults.string(forKey: "draft_\(channelId)")
    }
    
    func clearDraft(for channelId: String) {
        userDefaults.removeObject(forKey: "draft_\(channelId)")
    }
}
Implementation Strategy: Start with basic text messaging, then progressively add features like tags for organization, metadata for custom functionality, and threading for organized conversations. Always validate content length and implement proper error handling.