# Message Code

## Basic Concept

Message module maintains all system back-end messages which will be thrown out under certain circumstances. Centralized maintenance of all system messages in the back end helps the standardization of message body formats, paves the way for quick changes, and facilitates flexible multi-language transactions. 

## User Scenario

It is for anybody who wants to use our platform to maintain message codes.

## Composition of Message

When talking about message definition, we should first differentiate two types of system message:

* UI message or front-end message: It's not really a message but more like a UI label. Its maintenance is configured via i18n translation module instead of message module.

* System message or back-end message: Only back-end system message is maintained, such as rule message and system exception message. 

Message types are various, such as endorsement message, issuance message, and validation message. Some messages are universally applicable to all products while others are product-specific.

Message is widely used in our rule configuration and system programming. If checking rules fail, the system will take messages from the message module and then prompt front users to take corresponding actions.

In all use cases, a message code is a unique identifier to determine a message. Therefore, we must keep it unique.  

The message maintenance module also allows users to group and manage all system messages required by the system. 


## Message UI Operation Guide

<div class="docs-caution"><span class="docs-admonitions-text">caution</span>

*  All operations in this text need to be performed in the portal master configuration environment (MC env). They are not allowed in other environments unless for troubleshooting purposes.
*  Please make sure you have all read and write authority to make the operation beforehand.

</div> 

The following is a typical process of claim massage maintenance. 

1. Select **Module** and **Group** to search for existing data. The field below is where you can add or modify the data. 

![context](./image/context/context05.jpg)

2. Select **Message Level** as required. 
    
   By default, any new message addition will go with the 1st level message prefix "TENANT" which is a neutral term and can be reused among multiple tenants. If users want to adopt other prefix, they can override `messageCode.prefix` in **SystemConfigTable** of **Global Parameter**.

![context](./image/context/context06.jpg)

3. Available languages will be displayed according to the global language setting. See [Language Setting](https://docs.insuremo.com/ics/app_framework/publanguage) for more details.

  If selected language content is not set, the system will get **Content** for languages.
   
![context](./image/context/context07.jpg)


## Q&A

### How to display a message containing multiple variables?

Sometimes you want to display a message containing variables such as age and product. Take "Not reach minimum age(18) to be included, now age is 2 and product is TBTI, need underwriting! Send to underwriting or not?" as an example.

Basically, you can define in the message module to pass the variables in the {} format: "Not reach minimum age(18) to be included, now age is {} and product is {}, need underwriting!".

Then in the rule script, you can define the message as an object: `uwResult("MO-PA-UW-BLIMITAGE18"`, `[age, Policy().ProductCode.val] as Object[])`.


### How to Display Transactions via APIs?

There are multiple ways to display transactions via APIs and we recommend the following methods:

1. API request header: `x-mo-lang-id`

User can add `x-mo-lang-id` in the API request headers and the system will automatically convert the message language. This is the most recommended method.

2. API request parameter: `langId`

If there are specific needs, user can extend the API by adding `langId` as a parameter via BFF. However, this is less recommended than the first method. 

3. Default language for the token user

If no parameter related to language IDs is passed via API, system will see the token user default language. It's very useful for application system messages that are displayed depending on users' favorite setting.


