callWebHook
The callWebHook
function allows you to send data to external systems using webhooks. It's commonly used to post notifications to communication platforms like Microsoft Teams or Slack, but can be used with any system that accepts webhook requests.
Syntax
app.callWebHook(url, message);
Parameters
-
url (string): The webhook URL of the target system (Teams, Slack, or any other webhook-enabled service).
- For Microsoft Teams, see the video guide: https://youtu.be/HhvS3Gbuaxg
- For Slack, visit their incoming webhooks documentation
-
message (object): The payload to be sent to the webhook. The structure depends on the service:
- For simple messages, use
{ text: "Your message" }
- For advanced formatting, use the specific JSON schema required by the service
- For simple messages, use
Return Value
Returns a Promise that resolves to the fetch response object.
Example Usages
Basic Text Message
Send a simple text message to any webhook endpoint:
app.callWebHook(myUrl, {
text: "Hello World"
});
Advanced Microsoft Teams Message
Create a rich card with interactive elements in Microsoft Teams:
app.callWebHook(teamsWebhookUrl, {
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "006E7E",
"summary": "A new message from brixxbox",
"sections": [{
"activityTitle": "A new message from brixxbox",
"activitySubtitle": "Customer Notification",
"activityImage": "https://example.com/images/notification.png",
"facts": [{
"name": "Assigned to",
"value": app.userId
}, {
"name": "Status",
"value": "New"
}],
"markdown": true
}],
"potentialAction": [{
"@type": "ActionCard",
"name": "Add a comment",
"inputs": [{
"@type": "TextInput",
"id": "comment",
"isMultiline": false,
"title": "Add a comment here"
}],
"actions": [{
"@type": "HttpPOST",
"name": "Add comment",
"target": "https://example.com/api/comments"
}]
}, {
"@type": "ActionCard",
"name": "Set status",
"inputs": [{
"@type": "MultichoiceInput",
"id": "list",
"title": "Select a status",
"isMultiSelect": "false",
"choices": [{
"display": "In Progress",
"value": "1"
}, {
"display": "Completed",
"value": "2"
}]
}],
"actions": [{
"@type": "HttpPOST",
"name": "Save",
"target": "https://example.com/api/status"
}]
}]
});
Slack Message with Attachments
Send a formatted message to Slack:
app.callWebHook(slackWebhookUrl, {
"text": "New support ticket created",
"attachments": [
{
"color": "#36a64f",
"pretext": "Ticket requires immediate attention",
"author_name": "Support System",
"title": "Ticket #1234",
"title_link": "https://example.com/tickets/1234",
"fields": [
{
"title": "Priority",
"value": "High",
"short": true
},
{
"title": "Customer",
"value": "ACME Inc.",
"short": true
}
],
"footer": "brixxbox Notification System",
"ts": Math.floor(Date.now() / 1000)
}
]
});
Notes
- The webhook URL contains authentication information, so handle it securely
- Format your message according to the receiving system's requirements
- For Microsoft Teams advanced formatting, see the official documentation
- For Slack message formatting, see the Slack API documentation