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 webhook.
Preamble
- A webhook is a method that allows an application to be informed immediately when a particular event occurs in another application, rather than constantly asking this application if something new has happened (what is called "polling").
- 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.
- It is not possible to import the history of the discussions from another application (Slack, Teams, Jabber, etc.) or from another Organization.
Access the webhooks kChat interface
Prerequisites
- Don't be an external user (this one won't see the menu Integrations).
To configure a webhook, find self-hosted or third-party applications and integrations:
- Click here to access the kChat Web app (online service) kchat.infomaniak.com) or open the kChat desktop app (desktop application on macOS / Windows / Linux).
- Click on the New icon ‍ to the name of your organization kChat.
- Click Integrations.
- Access the categories:
Example of integration
Create a simple incoming webhook
To this end:
- Click on the incoming Webhooks category.
- Click 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 get the URL (not to be publicly disclosed); example
https://your-server-kchat.xyz/hooks/xxx-key-generated-xxx
”.
Using the webhook
On the application that must post on kChat:
Adjust the code below based on the URL obtained:
POST /hooks/xxx-key-generated-xxx HTTP/1.1 Host: your-server-kchat.xyz Content-Type: application/json Content-Length: 63 { "text": "Hello, text1 Text2." }
- Use the same query, but in curl (to test from a Terminal on macOS e.g.):
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "Hello, text1 Text2."}' https://your-server-kchat.xyz/hooks/xxx-key-generated-xxx
If no header Content-Type is defined, the body of the request must be preceded by payload= Like this:
payload={"text": "Hello, text1 Text2."}
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 have 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 URL of the webhook.
Parameters
In addition to the field text
, here is the complete list of supported parameters:
Parameter | Description | Required |
---|---|---|
text | Message in Markdown format to be displayed in the publication. To trigger notifications, use @<username> | If attachments is not defined, yes |
channel | Replaces the channel in which the message is posted. Use the name of the channel, not the name of the display, use e.g. town square, not town square. Use "@" followed by a username to send a direct message. By default, use the channel set when creating the webhook. The webhook can post in any public and private channel where the creator of the webhook is present. Publications in direct messages will appear in the direct message between the target user and the webhook creator. | No |
username | Replaces the user name under which the message is posted. By default, use the user name set when creating the webhook; if no user name was set when creating, use webhook .The configuration parameter Allow integrations to replace usernames must be enabled for the user name replacement to take effect. | No |
icon_url | Replaces the profile image with which the message is posted. By default, use the URL set when creating the webhook; if no icon was set when creating, the standard webhook icon (‍) is displayed. The configuration parameter Allow integrations to replace profile photo icons must be activated for the icon replacement to take effect. | No |
icon_emoji | Replaces profile image and parameter icon_url .By default, nothing is set when creating the webhook. The expected value is the name of an emoji as it is typed in a message, with or without two points ( : ).The configuration parameter Allow integrations to replace profile photo icons must be activated for the replacement to take effect. | No |
attachments | Attachments to the message used for richer formatting options. | If text is not defined, yes |
type | Defines type publication, mainly for use by plugins.If it is not empty, must start with " custom_ ". | No |
Example code with parameters
Here's how to generate a more complete message with parameters, some of which can replace parameters already established when creating the webhook (user name, preferred channel, avatar...) as indicated in the table above:
POST /hooks/xxx-clé-générée-xxx HTTP/1.1
Host: votre-serveur-kchat.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": "#### RĂ©sultats des tests pour le 27 juillet 2023
@channel veuillez vérifier les tests échoués.
| Composant | Tests effectués | Tests échoués |
|:-----------|:-----------:|:-----------------------------------------------|
| Serveur | 948 | 0 |
| Client Web | 123 | 2 [(voir détails)](https://linktologs) |
| Client iOS | 78 | 3 [(voir détails)](https://linktologs) |"
}
This will result in the display of this message in the channel kchatemp of the organization: