Mezon Development Team
April 21, 2025
The Mezon SDK provides developers with a simple and efficient way to interact with the Mezon platform. This document outlines the core functionalities of the SDK, focusing on client initialization, event listening, and channel object retrieval.
Note: Installation instructions will depend on the target environment (e.g., npm for Node.js, CDN for browser). Please refer to the specific installation guide for your platform.
The MezonClient
class is the entry point for interacting with the Mezon platform. To begin, you need
to instantiate a MezonClient
object with your authentication token.
const client = new MezonClient("your_authentication_token");
token
: A string representing your Mezon platform authentication token. This token is essential for
authenticating your application with the Mezon service.client
: An instance of the MezonClient
class, providing access to the SDK's
functionalities.
const apiKey = "abcdef1234567890";
const client = new MezonClient(apiKey);
console.log("Mezon Client initialized:", mezon);
await client.login();
The MezonClient
provides a mechanism to listen for various events emitted by the Mezon platform. The
onMessage
event listener allows you to handle incoming messages.
client.onChannelMessage = (event: ChannelMessage) => {
// Your message handling logic here
console.log("Received message:", event);
};
event
: An object of type Message
containing information about the received message.
The structure of the Message
object will depend on the specific event type. Common properties might
include:
data
: The payload of the message.senderId
: The ID of the entity that sent the message.timestamp
: The timestamp of when the message was sent.channelId
: The ID of the channel the message belongs to.type
: The type of the message.
client.onChannelMessage = (message) => {
console.log(`New message from channel ${message.channel_id}:`, message.content);
// Process the message data
if (message.content.t === 'hello') {
console.log(`Chat message content: ${message.content.t}`);
}
};
The channel
object provides methods for interacting with specific channels on the Mezon platform. The
Find
method allows you to retrieve a reference to a channel using its unique identifier.
const channel = client.channels.fetch(channel_id);
channel_id
: A string or number representing the unique identifier of the channel you want to
interact with.channel
: An object representing the specified channel. This object will likely have methods for
performing actions within the channel, such as sending messages, retrieving members, etc. The exact methods
available on the channel
object will be detailed in further documentation.
const myChannel = await client.channels.fetch(myChannelId);
console.log("Channel object:", myChannel);
// send message to myChannel
await myChannel.send({t: "Hello everyone!"});
The message
object provides methods for interacting with specific message on the Mezon platform. The
fetch
method allows you to retrieve a reference to a message using its unique identifier and the
channel it belongs to.
const channel = await client.channels.fetch(channel_id);
const message = await channel.messages.fetch(message_id);
message_id
: A string representing the unique identifier of the message you want to interact with.
message
: An object representing the specified message. This object will likely have methods for
performing actions within the message, such as reply, update, delete message, etc. The exact methods available on
the message
object will be detailed in further documentation.
const myChannelId = "group-chat-123";
const myChannel = await client.channels.fetch(myChannelId);
const myMessageId = "message-chat-123";
const myMessage = await channel.messages.fetch(myMessageId);
// reply a message
await myMessage.reply({t: "Hello everyone!"});
// update a message
await myMessage.update({t: "Hello everyone! (edited)"});
// delete a message
await myMessage.delete();
The user
object provides methods for interacting with specific user on the Mezon platform. The
fetch
method allows you to retrieve a reference to a user using its unique identifier and the clan user
belongs to.
const clan = await client.clans.fetch(clan_id ?? '0'); // '0' use for DM message
const user = await clan.users.fetch(user_id);
user_id
: A string representing the unique identifier of user you want to interact with.user
: An object representing the specified user. This object will likely have methods for
performing actions within the user, such as sendDM, sendToken, etc. The exact methods available on the
user
object will be detailed in further documentation.
const myClanId = "clan-chat-123";
const myClan = await client.clans.fetch(myClanlId);
const userId = "user-123";
const user = await clan.users.fetch(userId);
// send a DM message
await user.sendDM({t: "Hello!"});
Mezon also supports sending rich messages using an embedded format. This allows for structured messages with colors, titles, authors, descriptions, fields, images, and more. Below is the TypeScript interface defining the structure for an embedded message.
export interface IEmbedProps {
color?: string;
title?: string;
url?: string;
author?: {
name?: string;
icon_url?: string;
url?: string;
};
description?: string;
thumbnail?: {
url: string;
};
fields?: {
name: string;
value: string;
inline?: string;
};
images?: {
url: string;
width: string;
height: string;
};
timestamp?: string;
footer?: string;
}
const myChannelId = "group-chat-123";
const myChannel = await client.channels.fetch(myChannelId);
const embed = [{
color: #fff,
title: 'Message embed',
description: "Description message embed",
}];
await myChannel.send({embed});
Mezon supports receiving messages via webhooks. Below is an example of the expected format for a webhook payload sent to your registered webhook URL.
curl --location 'https://webhook.mezon.ai/webhooks/1839225926886363136/MTcyNzM0MDYyMTU2NTczNzQzMzoxODM5MjI1NzgyNjY1MjIwMDk2OjE4MzkyMjU5MjY4ODYzNjMxMzY.' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "hook",
"message": {
"t": "long@long 123456",
"mk": [
{
"type": "lk",
"s": 0,
"e": 22
}
],
"mk": [
{
"type": "pre",
"s": 0,
"e": 22
}
],
"mentions": [
{
"username":"nhan.nguyentran",
"user_id":"134221824",
"s": 0,
"e":17
}
],
"images": [
{
"fn":"thumbnail_dog1.jpg",
"sz":5620,
"url":"https://cdn.mezon.vn/0/1843962578301095936/1829065039080853500/95_0thumbnail_dog1.jpg",
"ft":"image/jpeg",
"w":275,
"h":183
}
]
}
}'
Clan hook
{
"content": "{\"t\": \"haha\"}",
"attachments": [
{
"filename": "bandicam 2024-11-19 11-10-14-507.mp4",
"size": 2671970,
"url": "https://cdn.mezon.vn/109056000/255856640/4198400/173_0bandicam_2024_11_19_11_10_14_507.mp4",
"filetype": "video/mp4",
"width": 1280,
"height": 724
}
]
}
The message
object within the webhook payload contains details about the received message, including
text, formatting, mentions, and attachments like images.
Mezon also supports sending rich messages using an embedded format. This allows for structured messages with colors, titles, authors, descriptions, fields, images, and more. Below is the TypeScript interface defining the structure for an embedded message.
export interface IEmbedProps
{
color?: string;
title?: string;
fields?: IField[];
}
export interface IField
{
name: string;
value: string;
inputs?: IInputs;
}
export interface IInputs
{
id: string;
type: 6 ;
component: IComponent;
}
export interface IComponent
{
url_image: string;
url_position: string;
pool: string[][];
repeat: number;
duration: number;
}
const embed: IEmbedProps = {
color: '#E67E22',
title: '🎰 Kết quả Slots 🎰',
fields: [
{
name: '',
value: '',
inputs: {
id: 'slots',
type: 6,
component: {
url_image: 'https://cdn.mezon.ai/...spritesheet.png',
url_position: 'https://cdn.mezon.ai/...spritesheet.json',
pool: [
['1.JPG', '2.JPG', ..., '14.JPG'],
['1.JPG', '2.JPG', ..., '10.JPG'],
['1.JPG', '2.JPG', ..., '11.JPG']
],
repeat: 6,
duration: 0.5
}
}
}
]
};