Skip to content

Latest commit

 

History

History
123 lines (98 loc) · 2.96 KB

Using-Inbox.md

File metadata and controls

123 lines (98 loc) · 2.96 KB

Using Inbox

Introduction

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 = new WultraMobileToken(powerAuthInstance, "https://my-instance.mycompany.com/enrollment-server")
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.unreadCount()
    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.list(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.detail(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
}

Read Next