Using Inbox

WMTInbox 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 WMTInbox, you need to have a PowerAuth object available and initialized with a valid activation. Without a valid PowerAuth activation, the service will return an error.

WMTInbox communicates with the Mobile Token API.

Getting an Instance

The instance of the WMTInbox can be accessed after creating the main object of the SDK:

const mtoken = powerAuthInstance.createWultraMobileToken()
const inbox = mtoken.inbox

Inbox Usage

Get Number of Unread Messages

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

try {
    const resp = await this.mtoken.inbox.getUnreadCount()
    if (resp.responseObject) {
        console.log(`There are ${resp.responseObject.countUnread} unread messages.`)
    } else {
        // error    
    }
} catch (e) {
    // failure
}

Get a List of Messages

Get a paged list of messages:

try {
    //Get page 0 of size 50, not not exclude unread messages
    const resp = await this.mtoken.inbox.getMessageList(0, 50, false)
    if (resp.responseObject) {
        // process the message list
    } else {
        // error    
    }
} catch (e) {
    // failure
}

Get Message Detail

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

try {
    let messageId = messagesList[0].id
    const resp = await this.mtoken.getMessageDetail(messageId)
    if (resp.responseObject) {
        // process the message
    } else {
        // error    
    }
} catch (e) {
    // failure
}

Set Message as Read

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

try {
    let messageId = messagesList[0].id
    const resp = await this.mtoken.markRead(messageId)
    if (resp.status == "OK") {
        // the message was marked as read
    } else {
        // error    
    }
} catch (e) {
    // failure
}

Alternatively, you can mark all messages as read:

try {
    const resp = await this.mtoken.markAllRead()
    if (resp.status == "OK") {
        // all messages was marked as read
    } else {
        // error    
    }
} catch (e) {
    // failure
}
Last updated on Feb 19, 2025 (14:49) Edit on Github Send Feedback
Search

1.0.x

Mobile Token SDK JS