Core module

Nabla React Native Messaging core module

📘

This guide is about the data/domain layer

This page describes how to to query the patient data, allowing you to build your own UI. If you'd rather use our built-in customisable UI components, check out the Messaging UI Components page.

Watch patient conversations list

You can watch the list of conversations a user has access to.
The successCallback will be called every time there's a change in those conversations and will always return all the data (you don't need to accumulate it in your own properties):

const subscription = NablaMessagingClient.getInstance().watchConversations(
  (error) => {
    // TODO: handle error
    subscription.remove();
  },
  (result: ConversationList) => {
    // You can update your UI with the list of conversations:
    const conversations = result.conversations;

    // If hasMore is true, more conversations are available, otherwise you already have all the conversations
    // To load more conversation, you can use `NablaMessagingClient.getInstance().loadMoreConversations`
    const hasMore = result.hasMore;
  }
);

Create a new conversation

If you want your user to be able to start a new conversation, you can allow to create it into your app directly:

NablaMessagingClient.getInstance().createConversation(
  (error) => {
    // TODO: Handle error
  },
  (conversationId) => {
    // Conversation is created, watchConversations will be called with that new conversation
  }
);

Watch a conversation

To watch the items (message and conversation activity) of a conversation, the same pagination principles applies:

const subscription =
  NablaMessagingClient.getInstance().watchItemsOfConversation(
    conversationId,
    (error) => {
      // TODO: handle error
      subscription.remove();
    },
    (conversationItems: ConversationItems) => {
      // You can update your UI with the list of messages
      const items = conversationItems.items;

      // If hasMore is true, more conversations are available, otherwise you already have all the conversations
      // To load more conversation, you can use `NablaMessagingClient.getInstance().loadMoreItemsInConversation`
      const hasMore = conversationItems.hasMore;
    }
  );

You can also watch for a conversation details update (like a Provider typing status):

const subscription = NablaMessagingClient.getInstance().watchConversation(
  conversationId,
  (error) => {
    // TODO: handle error
    subscription.remove();
  },
  (conversation: Conversation) => {
    // You can update your UI with the new data
  }
);

Send a new message

Creating and sending your message

The user can send a message in an existing conversation:

NablaMessagingClient.getInstance().sendMessage(
  (error) => {
    // TODO: handle error
  },
  () => {
    // Message has been sent successfully!
  },
  new TextMessageInput("Hello World!"),
  conversationId
);

📘

Message sending is asynchronous

Note that here you don't need to handle failure or success directly: As soon as you call sendMessage(..) the new message will be locally added to the conversation: its status will be SendStatus.Sending.

Different types of messages

You can send following types of messages:

  • Text
  • Image
  • Video
  • Document
  • Audio

Here is how to create each of them:

const textMessageInput = new TextMessageInput("Hello World!");

const imageMessageInput = new ImageMessageInput(
  "file:///uri/from/device/img.jpg",
  ImageMimeType.Jpeg,
  "File name"
);

const videoMessageInput = new VideoMessageInput(
  "file:///uri/from/device/video.mp4",
  VideoMimeType.mp4,
  "File name"
);

const documentMessageInput = new DocumentMessageInput(
  "file:///uri/from/device/document.pdf",
  DocumentMimeType.pdf,
  "File name"
);

const audioMessageInput = new AudioMessageInput(
  "file:///uri/from/device/audio.mpeg",
  AudioMimeType.mpeg,
  "File name"
);