1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Connect External Applications to kChat
This guide allows you to manage external applications with kChat using webhooks.
Introduction
- A webhook is a method that allows an application to be notified immediately when a particular event occurs in another application, rather than constantly asking that application if something new has happened (known as "polling").
- It is not possible to import chat history from another application (Slack, Teams, Jabber, etc.) or from another organization.
- Outgoing webhook: kChat communicates information to other apps when an event occurs in kChat.
- Incoming webhook: kChat receives information from other apps to trigger actions in kChat.
Accessing the kChat Webhooks Interface
Prerequisites
- Must not be an external user (they will not see the Integrations menu).
To configure a webhook, find applications and self-hosted or third-party integrations:
- Open the kChat app (on your device or from a browser at the URL kchat.infomaniak.com).
- Click on the chevron next to your kChat organization name.
- Click on Integrations
- Access the categories:
Integration Example
Create a Simple Incoming Webhook
To do this:
- Click on the category Incoming Webhooks.
- Click on the blue button Add Incoming Webhooks
- Add a name and description (max 500 characters) for the webhook.
- Select the channel that will receive the messages.
- Save to obtain the URL (do not disclose publicly) of type:
https://your-kchat-server.xyz/hooks/xxx-generated-key-xxx
Using the Webhook
On the application that needs to post to kChat:
Adjust the code below according to the obtained URL:
POST /hooks/xxx-generated-key-xxx HTTP/1.1 Host: your-kchat-server.xyz Content-Type: application/json Content-Length: 63 { "text": "Hello, this is a text\nThis is another text." }
- Optionally use the same request but in curl (to test from a Terminal on macOS, for example):
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "Hello, this is a text\nThis is another text."}' https://your-kchat-server.xyz/hooks/xxx-generated-key-xxx
If no Content-Type header is set, the body of the request must be preceded by payload= like this:
payload={"text": "Hello, this is a text\nThis is another text."}
A successful request will receive the following response:
HTTP/1.1 200 OK
Content-Type: application/json
X-Version-Id: 4.7.1.dev.12799dvd77e172e8a2eba0f4041ec1471.false
Date: Sun, 01 Jun 2023 17:00:00 GMT
Content-Length: 58
{
"id":"x",
"create_at":1713198308869,
"update_at":1713198308869,
"delete_at":0,
"user_id":"x",
"channel_id":"x",
"root_id":"",
"original_id":"",
"participants":null,
"message":"test",
"type":"",
"props":{
"override_username":"webhook",
"override_icon_url":null,
"override_icon_emoji":null,
"webhook_display_name":"test",
"attachments":[
],
"card":null,
"from_webhook":"true"
},
"hashtags":null,
"metadata":{
"embeds":[
{
"type":"message_attachment"
}
],
"files":[
],
"reactions":[
]
},
"file_ids":null,
"has_reactions":false,
"edit_at":0,
"is_pinned":false,
"remote_id":null,
"reply_count":0,
"pending_post_id":null,
"is_following":false
}
If you want to receive the same response format as Slack:
HTTP/1.1 200 OK
Content-Type: text/plain
X-Request-Id: hoan69ws7rp5xj7wu9rmystry
X-Version-Id: 4.7.1.dev.12799dvd77e172e8a2eba0f4041ec1471.false
Date: Sun, 01 Jun 2023 17:00:00 GMT
Content-Length: 2
ok
You need to add ?slack_return_format=true
to the webhook URL.
Parameters
In addition to the text
field, here is the complete list of supported parameters:
Parameter | Description | Required |
---|---|---|
text | Message in Markdown format to display in the post. To trigger notifications, use @<username> , @channel , and @here as you would in other kChat messages. | If attachments is not set, yes |
channel | Overrides the channel in which the message is posted. Use the channel name, not the display name; use, for example, town-square , not Town Square .Use "@" followed by a username to send a direct message. By default, it uses the channel defined when creating the webhook. The webhook can post in any public and private channel where the webhook creator is present. Posts in direct messages will appear in the direct message between the targeted user and the webhook creator. | No |
username | Overrides the username under which the message is posted. By default, it uses the username defined when creating the webhook; if no username was defined during creation, it uses webhook .The configuration parameter Allow integrations to override usernames must be enabled for the username override to take effect. | No |
icon_url | Overrides the profile image with which the message is posted. By default, it uses the URL defined when creating the webhook; if no icon was defined during creation, the standard webhook icon () is displayed. The configuration parameter Allow integrations to override profile photo icons must be enabled for the icon override to take effect. | No |
icon_emoji | Overrides the profile image and the icon_url parameter.By default, nothing is set during the creation of the webhook. The expected value is the name of an emoji as it is typed in a message, with or without colons ( : ).The configuration parameter Allow integrations to override profile photo icons must be enabled for the override to take effect. | No |
attachments | Attachments to the message used for richer formatting options. | If text is not defined, yes |
type | Defines the type of post, mainly for use by plugins.If not empty, must start with " custom_ ". | No |
Code Example with Parameters
Here is how to generate a more complete message with parameters, some of which can override parameters already set during webhook creation (username, preferred channel, avatar...) as indicated in the table above:
POST /hooks/xxx-generated-key-xxx HTTP/1.1
Host: your-kchat-server.xyz
Content-Type: application/json
Content-Length: 630
{
"channel": "kchatemp",
"username": "test-automation",
"icon_url": "https://domain.xyz/wp-content/uploads/2023/06/icon.png",
"text": "#### Test Results for July 27, 2023\n@channel please check the failed tests.\n\n| Component | Tests Completed | Tests Failed |\n|:-----------|:-----------:|:-----------------------------------------------|\n| Server | 948 | 0 |\n| Web Client | 123 | 2 [(view details)](https://linktologs) |\n| iOS Client | 78 | 3 [(view details)](https://linktologs) |"
}
This will result in the display of this message in the kchatemp channel of the organization: