Messaging

Every application has a built-in inbox for receiving messages and an outbox for sending messages. This allows users and applications to send data between each other knowing nothing than the other user’s DID and application name.

Learn more about the messaging architecture.

Open messagingarrow-up-right

You can simply open the messaging capabilities for the currently connected application context as follows:

const messaging = await context.getMessaging()

Fetching messages (Inbox)arrow-up-right

Get messagesarrow-up-right

You can retrieve the 20 most recent messages:

const messages = await messaging.getMessages()

Alternatively, specify optional filter and options parameters:

const filter = {
    type: 'inbox/dataRequest'
}
const options = {
  limit: 20,
  skip: 0,
  sort: [{ sentAt: 'desc' }]
}
const messages = await messaging.getMessages(filter, options)

Listen for messagesarrow-up-right

Your application can register a callback function to listen for new inbox messages:

The inboxEntry object utilizes the inbox/entry schemaarrow-up-right. The two most important properties are:

You can stop listening:

Sending messages (Outbox)arrow-up-right

Your application can send messages to other accounts on the Verida network.

This example sends a contact record to a user’s Verida Wallet:

This could be used in two scenarios:

  • A user sending their own data from one application they control to another

  • A user sending data to another user within the same application

circle-info

The Verida account must have already logged in and created the application context before you can send it an inbox message. For example, assume you are sending an inbox message to an application context called “Verida: Documents”. If the recipient account has never logged into that context the inbox message will fail because that account has no inbox available.

Opening your apparrow-up-right

It can be helpful if the Wallet opens your application in a web browser after the user accepts a message. You can enable this by providing an optional parameter to the config.

ie:

Setting avatar and namearrow-up-right

When sending an inbox message, the sender avatar and name are automatically loaded from the public profile of the sending Verida Account. You will need to set these for your account so they can be loaded by applications across the network (including the Verida Wallet).

You could add your Verida Account to the Verida Wallet and use the mobile app to set a profile avatar and name. This will then be the default for every application used by the sending Verida Account. Alternatively, you could manually set the profile information for the application context sending the inbox message. See Account Profiles for more information on how to achieve this.

Built-in Message Typesarrow-up-right

See core schemas repositoryarrow-up-right for details on each supported inbox message type.

Sending dataarrow-up-right

Data can be sent to an account (see Outbox example above)

Requesting dataarrow-up-right

Data can be requested from an account:

Options:

  • filter: A JSON filter to apply to the search when locating suitable data to share

  • userSelect: Boolean value indicating if the user can select the data to be returned. If false all matching data will be returned.

  • userSelectLimit: Integer limiting how many records a user can select.

Last updated

Was this helpful?