Page updated Jan 16, 2024

Resolve conflicts

In the rare case where an event is sent and meets the criteria set forth by multiple in-app messages, the library needs to decide which message to return. If such a conflict should arise, In-App Messaging will choose a message by:

  1. Sorting the messages in order of campaign expiration
  2. Returning the top message sorted (the closest message to expiry)

However, this may not be how you wish to resolve such conflicts so you may want to set your own conflict handler.

1import { setConflictHandler } from 'aws-amplify/in-app-messaging';
2
3/**
4 * Regardless of your conflict resolution strategy the handler must always accept
5 * an array of in-app messages and return a single in-app message.
6 */
7const myConflictHandler = (messages) => {
8 // Return a random message
9 const randomIndex = Math.floor(Math.random() * messages.length);
10 return messages[randomIndex];
11};
12
13setConflictHandler(myConflictHandler);