Chuyển tới nội dung chính

Channel Webhook

Mezon provides a feature that allows users to send messages to channels through corresponding created webhooks.

Creating a Channel Webhook

First, to work with channel webhooks, you need to make sure you are a member of a clan and have access to a channel.

Creating a webhook is a pretty straightforward process.

  1. Go to the channel you want to create a webhook for, right-click to bring up a popup of actions that can be performed on that channel.

    mezon-webhook-001

  2. Click on the Edit Channel option and then go to the Integrations tab.

    mezon-webhook-002

  3. Click on New Webhook to proceed with creating a new webhook.

    mezon-webhook-003

  • You will have one user (here named Spidey bot) and can customize this bot's name and avatar.

  • Click on Copy Webhook URL to get the webhook's endpoint, use it with the webhook payload to send messages to the channel.

Webhook Specification

Endpoint

The webhook is delivered via an HTTP POST request to a unique URL generated for each webhook integration.

URL Structure:

https://webhook.mezon.ai/webhooks/{channelId}/{token}

URL Parameters:

ParameterTypeDescription
channelIdstringA unique identifier for the channel.
tokenstringA security token for authenticating the request. It appears to be a base64 encoded string or a JSON Web Token (JWT) containing information for verifying the request's authenticity.

Request Header

HeaderValueDescription
Content-Typeapplication/jsonIndicates that the request body is in JSON format.

Request Body

The body of the request contains a JSON object with details of the message that triggered the webhook.

Root Object

FieldTypeRequiredDescription
typestringYesThe type of the webhook event. For this example, it is "hook".
messageobjectYesAn object containing the details of the message.

Message Formatting

This object encapsulates the content and metadata of the message.

FieldTypeRequiredDescription
tstringYesThe raw text content of the message.
mkarray of objectsNoAn array of objects describing markdown or special formatting applied to the message text. It's noteworthy that multiple mk arrays can be present. The possible values for type within this object could include lk (link) and pre (pre-formatted text).
mentionsarray of objectsNoAn array of objects, each representing a user mentioned in the message.
imagesarray of objectsNoAn array of objects, each representing an image attached to the message.

mk Object (markdown)

FieldTypeRequiredDescription
typestringYesThe type of formatting applied (e.g., "lk", "pre").
sintegerYesThe starting character index of the formatted segment in the t string.
eintegerYesThe ending character index of the formatted segment in the t string.

mentions Object

FieldTypeRequiredDescription
usernamestringYesThe username of the mentioned user.
user_idstringYesThe unique identifier of the mentioned user.
sintegerYesThe starting character index of the mention in the t string.
eintegerYesThe ending character index of the mention in the t string.

images Object

FieldTypeRequiredDescription
fnstringYesThe filename of the image.
szintegerYesThe size of the image in bytes.
urlstringYesThe public URL to access the image.
ftstringYesThe MIME type of the image (e.g., "image/jpeg").
wintegerYesThe width of the image in pixels.
hintegerYesThe height of the image in pixels.

Channel Webhook example

curl --location 'https://webhook.mezon.ai/webhooks/1840666462029615104/MTc2MDAzODcxNTU5NDU0OTgzNzoxODQwNjY2NDYyMDEyODM3ODg4OjE4NDA2NjY0NjIwMjk2MTUxMDQ6MTk3NjM3MTczNTI3MTgzNzY5Ng.zLl5tsGaFYnC3sPXgOhVlZoBNrVeoC8hD6oKv0hxavs' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "hook",
"message": {
"t": "[pre] Webhook message example: [lk] https://mezon.ai \n [mention] mezon.webhook@ncc.asia",
"mk": [
{
"type": "pre",
"s": 0,
"e": 30
},
{
"type": "lk",
"s": 36,
"e": 54
}
],
"mentions": [
{
"user_id": "1783755414765047808",
"s": 65,
"e": 88
}
],
"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
}
]
}
}

Result

mezon-webhook-004