MessageService
Service handling Message calls.
Method Summary
Public Methods | ||
public |
getConversations(): Promise<Message[]> Retrieves the list of all conversations. |
|
public |
getMessages(id: String | Number): Promise<Message[]> Fetches all messages for a conversation and marks the messages as read on next call. |
|
public |
sendMessage(message: Object): Promise Sends a message to recipients. |
Public Methods
public getConversations(): Promise<Message[]> source
Retrieves the list of all conversations.
Throw:
If missing token |
Example:
import { messageService } from 'clinical6';
messageService.getConversations().then(messages => console.log(messages));
public getMessages(id: String | Number): Promise<Message[]> source
Fetches all messages for a conversation and marks the messages as read on next call.
Throw:
If missing token or missing required parameters |
Example:
import { messageService } from 'clinical6';
messageService.getMessages(20).then(messages => console.log(messages));
{
"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"
}
public sendMessage(message: Object): Promise source
Sends a message to recipients.
Params:
Name | Type | Attribute | Description |
message | Object |
|
Object including the following message-based fields: |
message.subject | String |
|
The subject of the message. |
message.body | String |
|
The body of the message. |
message.recipients | Array<String> |
|
Recipients of the message. |
message.attachment | Object |
|
Attachment included in the message. |
message.attachment.file_data | String |
|
File data for the attachment. |
message.attachment.content_type | String |
|
Content type of the attachment. |
message.attachment.file_name | String |
|
File name of hte attachment. |
Throw:
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
}
{
"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"
}
{
"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"
}
{
"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"
}
{
"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:
- [unit] MessageService.sendMessage should exist
- [unit] MessageService.sendMessage should throw an error when there is no message
- [unit] MessageService.sendMessage should throw an error when there is no subject attribute in message
- [unit] MessageService.sendMessage should return a promise
- [unit] MessageService.sendMessage should successfully create a message with a message object