createMessageNotification method

NotificationPayload createMessageNotification({
  1. required String id,
  2. required String senderName,
  3. required String message,
  4. String? senderAvatar,
  5. String? conversationId,
  6. String? threadIdentifier,
  7. Map<String, dynamic>? data,
})

Creates a message notification template for chat applications.

Implementation

NotificationPayload createMessageNotification({
  required String id,
  required String senderName,
  required String message,
  String? senderAvatar,
  String? conversationId,
  String? threadIdentifier,
  Map<String, dynamic>? data,
}) {
  return NotificationPayload(
    id: id,
    title: senderName,
    body: message,
    data: <String, dynamic>{
      'type': 'message',
      'conversationId': conversationId,
      'senderId': senderName,
      ...?data,
    },
    largeIcon: senderAvatar,
    threadIdentifier: threadIdentifier ?? conversationId,
    importance: NotificationImportance.high,
    priority: NotificationPriority.high,
    category: 'msg',
    actions: const <NotificationAction>[
      NotificationAction(
        id: 'reply',
        title: 'Reply',
        inputs: <NotificationActionInput>[
          NotificationActionInput(
            id: 'reply_text',
            title: 'Reply',
            placeholder: 'Type your reply...',
          ),
        ],
      ),
      NotificationAction(id: 'mark_read', title: 'Mark as Read'),
    ],
  );
}