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:
- Sorting the messages in order of campaign expiration
- 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 accept5 * an array of in-app messages and return a single in-app message.6 */7const myConflictHandler = (messages) => {8 // Return a random message9 const randomIndex = Math.floor(Math.random() * messages.length);10 return messages[randomIndex];11};12
13setConflictHandler(myConflictHandler);