Versions
2.17.1
Describe the issue:
I want to send webhooks to our Rocket.Chat, but OpenSearch send html body, not json
Configuration:
{
"start_index" : 0,
"total_hits" : 1,
"total_hit_relation" : "eq",
"config_list" : [
{
"config_id" : "Ip75-5IBkTxtk5bkXEfE",
"last_updated_time_ms" : 1730808888085,
"created_time_ms" : 1730804276420,
"config" : {
"name" : "Rocket",
"description" : "",
"config_type" : "webhook",
"is_enabled" : true,
"webhook" : {
"url" : "https://rocket.domain/hooks/**webhook**",
"header_params" : {
"Content-Type" : "application/json"
},
"method" : "PUT"
}
}
}
]
}
In tcpdump i see, that request contain HTML (line based text data), not json
So
I just resolve it on Rocket.Chat server side:
- in integration enable script
- add script in text field
class Script {
/**
* @params {object} request
*/
process_incoming_request({ request }) {
// The incoming request content from OpenSearch is in request.content
// OpenSearch might send a specific JSON structure or an HTML snippet (as noted in search results).
// You need to inspect the payload structure to parse it correctly.
// A common approach is to extract key information and format it:
const alertMessage = request.content_raw; // Assuming OpenSearch sends text in a 'text' field
// Format the message using Rocket.Chat's message structure (e.g., using attachments for rich messages)
const rocketChatPayload = {
text: `:alarm: *OpenSearch Alert Notification*`,
attachments: [
{
title: "Alert Details",
text: alertMessage || "No detailed message provided.",
color: "#FF0000" // Red color for alerts
}
]
};
// Return the formatted content
return {
content: rocketChatPayload
};
}
}
After that OpenSearch will deliver notification to Rocket.Chat