API Reference
This document provides information on how to use the Messaging APIs to retrieve and display inbox views in your application.
getInboxUI
The getInboxUI method retrieves a flow of InboxUIState for the provided surface. The InboxUIState represents the current state of the inbox (Loading, Success, or Error) and includes the inbox template and content cards to be rendered using the AepInbox composable.
Calling this API will not download the inbox configuration or content cards from Adobe Journey Optimizer; it will only retrieve the data that is already downloaded and cached by the Messaging extension. You must call updatePropositionsForSurfaces API from the AEPMessaging extension with the desired surfaces prior to calling this API.
Syntax
Copied to your clipboardfun getInboxUI(): Flow<InboxUIState>
refresh
The refresh method refreshes the Inbox content by fetching new inbox and content cards propositions from the device cache and updating the flow returned by getInboxUI. This will cause all collectors of the flow to receive the updated inbox state.
getInboxUI automatically loads initial content when first collected, so this method is only needed for manual refresh operations (e.g., pull-to-refresh or refresh button).
Syntax
Copied to your clipboardsuspend fun refresh()
Example
Copied to your clipboardimport androidx.lifecycle.ViewModelimport androidx.lifecycle.viewModelScopeimport com.adobe.marketing.mobile.Messagingimport com.adobe.marketing.mobile.aepcomposeui.components.AepInboximport com.adobe.marketing.mobile.aepcomposeui.state.InboxUIStateimport com.adobe.marketing.mobile.messaging.InboxEventObserverimport com.adobe.marketing.mobile.messaging.MessagingInboxProviderimport com.adobe.marketing.mobile.messaging.Surfaceimport kotlinx.coroutines.flow.SharingStartedimport kotlinx.coroutines.flow.StateFlowimport kotlinx.coroutines.flow.stateInimport kotlinx.coroutines.launchprivate val inboxSurface = Surface("inbox")// Prefetch (e.g. on login or before opening the inbox screen)Messaging.updatePropositionsForSurfaces(listOf(inboxSurface))class InboxViewModel : ViewModel() {val inboxProvider = MessagingInboxProvider(inboxSurface)val observer = InboxEventObserver(inboxProvider)val inboxUIState: StateFlow<InboxUIState> = inboxProvider.getInboxUI().stateIn(scope = viewModelScope,started = SharingStarted.WhileSubscribed(5000),initialValue = InboxUIState.Loading)fun refresh() {viewModelScope.launch {Messaging.updatePropositionsForSurfaces(listOf(inboxSurface))inboxProvider.refresh()}}}@Composablefun InboxScreen(viewModel: InboxViewModel = viewModel()) {val inboxUIState by viewModel.inboxUIState.collectAsState()MaterialTheme {AepInbox(uiState = inboxUIState,observer = viewModel.observer)}}
