Skip to main content
This page contains Flutter SDK code examples for Security extensions. For feature documentation, setup instructions, and extension settings, see Security Extensions.

How to Use Extensions with SDK

1

Enable in Dashboard

Login to CometChat Dashboard, select your app, then go to Chat & Messaging → Features and enable the extension.
2

Implement SDK methods

Use the code examples below to schedule messages for automatic deletion.
3

Build your UI

Update your UI to indicate which messages will disappear and when.

Disappearing Messages

Send messages that automatically disappear after a specified time interval.

Schedule Message for Deletion

// First, send the message
TextMessage textMessage = TextMessage(
  text: 'This message will disappear!',
  receiverUid: 'cometchat-uid-1',
  receiverType: CometChatReceiverType.user,
);

CometChat.sendMessage(textMessage,
  onSuccess: (BaseMessage message) {
    // Now schedule it for deletion
    Map<String, dynamic> body = {
      'msgId': message.id,
      'timeInMS': DateTime.now().millisecondsSinceEpoch + 60000, // 1 minute from now
    };

    CometChat.callExtension('disappearing-messages', 'DELETE', '/v1/disappear', body,
      onSuccess: (Map<String, dynamic> response) {
        debugPrint('Message scheduled for deletion');
      },
      onError: (CometChatException e) {
        debugPrint('Error scheduling deletion: ${e.message}');
      }
    );
  },
  onError: (CometChatException e) {
    debugPrint('Error sending message: ${e.message}');
  }
);
The value of timeInMS should be less than 1 year from the current time.