Using Inbox Service

Inbox Service is responsible for managing messages in the Inbox. The inbox is a simple one way delivery system that allows you to deliver messages to the user.

Note: Before using Inbox Service, you need to have a PowerAuthSDK object available and initialized with a valid activation. Without a valid PowerAuth activation, service will return an error.

Creating an Instance

Factory Extension With SSL Validation Strategy

Convenience factory method that will return a new instance. A new OkHttpClient will be created based on the chosen SSLValidationStrategy in the last parameter.

fun PowerAuthSDK.createInboxService(appContext: Context, baseURL: String, strategy: SSLValidationStrategy): IInboxService
  • appContext - application context
  • baseURL - address, where your operations server can be reached
  • strategy - strategy used when validating HTTPS requests. Following strategies can be used:
    • SSLValidationStrategy.default
    • SSLValidationStrategy.noValidation
    • SSLValidationStrategy.sslPinning

Optional parameters:

  • userAgent - Optional default user agent used for each request

Factory Extension With OkHttpClient

Convenience factory method that will return a new instance with provided OkHttpClient that you can configure on your own.

fun PowerAuthSDK.createInboxService(appContext: Context, baseURL: String, httpClient: OkHttpClient): IInboxService
  • appContext - application context
  • baseURL- address, where your operations server can be reached
  • httpClient - OkHttpClient instance used for API requests

Optional parameters:

  • userAgent - Optional default user agent used for each request

Inbox Service Usage

Get Number of Unread Messages

To get the number of unread messages, use the following code:

inboxService.getUnreadCount { 
    it.onSuccess {
        if (it.countUnread > 0) {
            print("There are ${it.countUnread} new message(s) in your inbox")
        } else {
            print("Your inbox is empty")
        }
    }.onFailure {
        // Process error
    }
}

Get List of Messages

The Inbox Service provide a paged list of messages:

// First page is 0, next 1, etc...
inboxService.getMessageList(pageNumber = 0, pageSize = 50, onlyUnread = false) {
    it.onSuccess { messages ->
        if (messages.count < 50) {
            // This is the last page
        }
        // Process messages    
    }.onFailure {
        // Process error
    }
}

To get the list of all messages, call:

inboxService.getAllMessages {
    it.onSuccess { messages ->
        print("Inbox contains the following message(s):")
        for (msg in messages) {
            print(" - ${msg.subject}")
            print("   * ID = ${msg.id}")
        }
    }.onFailure {
        // Process error
    }
}

Get Message Detail

Each message has its unique identifier. To get the body of message, use the following code:

let messageId = messagesList.first!.id
inboxService.getMessageDetail(messageId) {
    it.onSuccess {
        print("Received message:")
        print("${it.subject}")
        print("${it.body}")
    }.onFailure {
        // Process error
    }
}

Set Message as Read

To mark message as read by the user, use the following code:

let messageId = messagesList.first!.id
inboxService.markRead(messageId: messageId) {
    it.onSuccess {
        // OK
    }.onFailure {
        // Process error
    }
}

Alternatively, you can mark all messages as read:

inboxService.markAllRead {
    it.onSuccess {
        // OK
    }.onFailure {
        // Process error
    }
}

Error handling

Every error produced by the Inbox Service is of a WMTError type. For more information see detailed error handling documentation.

Last updated on Jan 03, 2023 (12:44) Edit on Github Send Feedback
Search

1.7.x

Mobile Token SDK for Android