Manual Reference Source Test
import MessageService from 'clinical6/src/services/MessageService.js'
public class | source

MessageService

this class was deprecated.

Service handling Message calls.

Method Summary

Public Methods
public

Retrieves the list of all conversations.

public

Fetches all messages for a conversation and marks the messages as read on next call.

public

Sends a message to recipients.

Public Methods

public getConversations(): Promise<Message[]> source

Retrieves the list of all conversations.

Return:

Promise<Message[]>

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token

Example:

import { messageService } from 'clinical6';
messageService.getConversations().then(messages => console.log(messages));

Test:

public getMessages(id: String | Number): Promise<Message[]> source

Fetches all messages for a conversation and marks the messages as read on next call.

Params:

NameTypeAttributeDescription
id String | Number

ID of the conversation

Return:

Promise<Message[]>

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { messageService } from 'clinical6';
messageService.getMessages(20).then(messages => console.log(messages));
Failure, User Not Found
{
  "error_detail": {
    "conversation": "invalid_value"
  },
  "friendly_error": "Mobile User not found using the value:conversation",
  "internal_code": 50364,
  "more_info": "",
  "status": "fail",
  "message": "Mobile User not found using the value:conversation"
}

Test:

public sendMessage(message: Object): Promise source

Sends a message to recipients.

Params:

NameTypeAttributeDescription
message Object
  • nullable: false

Object including the following message-based fields:

message.subject String
  • nullable: false

The subject of the message.

message.body String
  • nullable: false

The body of the message.

message.recipients Array<String>
  • nullable: false

Recipients of the message.

message.attachment Object
  • optional

Attachment included in the message.

message.attachment.file_data String
  • optional

File data for the attachment.

message.attachment.content_type String
  • optional

Content type of the attachment.

message.attachment.file_name String
  • optional

File name of hte attachment.

Return:

Promise

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { messageService } from 'clinical6';
const message = {
  subject: 'blanditiis',
  body: '0i03jrgt8tinkt4tok5k3oc1w3y40auvi4g5fucxczu0plk6sz4olys2b4o9',
  recipients: ['67']
};
messageService.sendMessage(message);

// Returns
{
  "status": "ok",
  "conversation_id": 1
}
Failure, Missing Body
{
  "error_detail": {
    "body": [
      "missing_field"
    ]
  },
  "friendly_error": "No value found for body on the parameters list",
  "internal_code": 50362,
  "more_info": "",
  "status": "fail",
  "message": "No value found for body on the parameters list"
}
Failure, Missing Subject
{
  "error_detail": {
    "subject": [
      "missing_field"
    ]
  },
  "friendly_error": "No value found for subject on the parameters list",
  "internal_code": 50362,
  "more_info": "",
  "status": "fail",
  "message": "No value found for subject on the parameters list"
}
Failure, Missing Message
{
  "error_detail": {
    "message": [
      "missing_field"
    ]
  },
  "friendly_error": "No value found for message on the parameters list",
  "internal_code": 50362,
  "more_info": "",
  "status": "fail",
  "message": "No value found for message on the parameters list"
}
Failure, User Not Found
{
  "error_detail": {
    "[999]": "invalid_value"
  },
  "friendly_error": "Mobile User not found using the value:[999]",
  "internal_code": 50364,
  "more_info": "",
  "status": "fail",
  "message": "Mobile User not found using the value:[999]"
}

Test: