> For the complete documentation index, see [llms.txt](https://docs.kuthulu.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kuthulu.xyz/contracts/messageformat.md).

# MessageFormat

The MessageFormat smart contract is a tool for organizing and formatting messages in KUTHULU. Its functionality ranges from grouping message details to integrating with other contracts for additional information retrieval.

### Table of Contents

1. [Public Functions](#public-functions)

***

## <mark style="color:purple;">Public Functions</mark>

### buildMsg

This function is used to build an array of message details by message ID. It formats message data, tags, postedBy, and other information into a string array that represents a comprehensive message object.

#### Parameters

| Name             | Type         | Details                                                                                         |
| ---------------- | ------------ | ----------------------------------------------------------------------------------------------- |
| `msgData`        | `uint256[]`  | An array of message data to format.                                                             |
| `message`        | `string`     | The body of the message.                                                                        |
| `postedBy`       | `address[2]` | An array of who posted the message. \[0] = Address of the poster / \[1] = proxy poster address. |
| `hashtags`       | `string[]`   | An array of hashtags in the message.                                                            |
| `taggedAccounts` | `address[]`  | An array of tagged accounts in the message.                                                     |
| `uri`            | `string`     | The URI added to a message (also used for attachments).                                         |
| `inGroups`       | `uint256[]`  | An array of group IDs that the message was posted into.                                         |
| `tipContract`    | `address`    | The contract address of the ERC20 token used for tipping.                                       |

#### Returns

| Name             | Type       | Details                                |
| ---------------- | ---------- | -------------------------------------- |
| `messageDetails` | `string[]` | An array of formatted message details. |

#### Example Usage

Using `ethers.js` to call the `buildMsg` function:

```javascript
const ethers = require('ethers');

let msgData = [0, 1612727763, 11782000, 10, 1, 0, 5, 2, 3, 0, 0, 0, 0, 100, 1];
let message = "Hello World";
let postedBy = [ethers.utils.getAddress('0xAddressOfPoster'), ethers.utils.getAddress('0xProxyAddress')];
let hashtags = ["#Polygon", "#smartcontract"];
let taggedAccounts = [ethers.utils.getAddress('0xAddressOfTaggedAccount1'), ethers.utils.getAddress('0xAddressOfTaggedAccount2')];
let uri = "https://example.com";
let inGroups = [1, 2, 3];
let tipContract = ethers.utils.getAddress('0xERC20TokenContractAddress');

let contract = new ethers.Contract(contractAddress, contractABI, signer);
let result = await contract.buildMsg(msgData, message, postedBy, hashtags, taggedAccounts, uri, inGroups, tipContract);
```
