Zum Hauptinhalt springen

Synology Chat Smart-Home-Integration, kostenlos und Open Source

Synology Chat-Integration für Gladys Assistant

Unofficial: send Synology Chat messages from scenes, start scenes from the chat.

Info

Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfügbar.

Unofficial external integration, not affiliated with Synology. It does two things:

  • Gladys → chat: your scenes post a message in a Synology Chat channel, through an incoming webhook of the NAS;
  • chat → Gladys: a message typed in Synology Chat (trigger word of an outgoing webhook, slash command or message to a bot) starts a Gladys scene. This direction goes through the Gladys Plus webhooks: without Gladys Plus, only sending works, and the status of the integration says so.

Written after the official Synology help "Using Integration in Synology Chat". It has never been tested with a real NAS: only against a fake server that follows this help. Your feedback is welcome.

1. Sending messages from scenes​

  1. In Synology Chat, click your profile picture > Integration > Incoming Webhooks > Create, pick the channel, then copy the Webhook URL. It looks like https://nas:5001/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22…%22.
  2. In Gladys, on the integration page, paste it in Incoming webhook URL. This URL lets anyone who knows it post in the channel: it is kept by Gladys in its database, never shown again, sent only to your NAS, and the integration writes it in no log nor status.
  3. Click Send a test message.
  4. In a scene, add the action Send a Synology Chat message and write the text; scene variables ({{…}}) are allowed.

Sending rules:

  • At most 2000 characters (beyond, the text is cut and ends with "…"); control characters are removed; links follow the Synology Chat syntax (<https://example.com|click here>).
  • One message at a time, at least one second between two; at most 10 messages waiting. A message that could not leave within 15 seconds is dropped ("Nothing sent").
  • When the NAS answers HTTP 429 or 5xx, no message is sent for 1 minute, then 2, 4… up to 1 hour when it happens again (longer when the NAS asks for it with Retry-After, 6 hours at most). This pause is kept in /data and survives a restart; the test button waits for it too. A message accepted resets it, and a new URL or a new fingerprint lifts it (it was the previous target's). After a 5xx the publication is not confirmed: a proxy (502, 504) may answer so after the message was posted.
  • The integration never sends a message twice. When the NAS does not answer after receiving the request, the scene action fails with "Message sent, without confirmation": look at the channel before sending it again.
  • A redirection of the NAS is never followed (the URL holds the token): use the address and port Synology Chat shows.

Certificate of the NAS​

The URL normally starts with https://. Before writing a single byte (the path of the request holds the token), the integration checks the certificate the NAS shows:

  • certificate signed by an authority (a free certificate DSM obtained for your domain name) and valid for the name of the URL: nothing to do, leave Certificate fingerprint empty;
  • self-signed certificate (the default of a NAS reached by its IP address): the first try fails with "Nothing sent", and the status shows the SHA-256 fingerprint the NAS presented. Check it in DSM (Control Panel > Security > Certificate, certificate details), then copy it in Certificate fingerprint. From then on, only this certificate is accepted.

A fingerprint typed is the only reference: when the NAS shows another certificate (renewed, or another machine), nothing is sent and the status shows the new fingerprint, to check then type. The integration never learns a certificate by itself.

Allow HTTP (off by default) accepts an http:// URL (port 5000): the token and the messages then cross your network in clear.

2. Starting a scene from the chat (Gladys Plus)​

  1. Link Gladys Plus to your Gladys and paste your Open API key in the Gladys Plus webhooks block of the integration page: Gladys shows a public URL for the webhook "Synology Chat outgoing webhook".
  2. In Synology Chat > Integration, create an outgoing webhook (a channel and/or trigger words), a slash command or a bot, with this URL as its outgoing URL.
  3. Copy the token Synology Chat shows for this webhook (or command, or bot) in Outgoing webhook token(s) (up to 5, separated by spaces). It is kept by Gladys in its database, never shown again, never sent anywhere by the integration. The messages typed in the chat (and this token, which comes with them) go through the Gladys Plus gateway before they reach your Gladys.
  4. In a scene, pick the trigger Synology Chat command received.

The trigger can filter on the command (the message without the trigger word, spaces collapsed), the trigger word, the user name and the channel. Filters are exact, case included: with the trigger word gladys, the message gladys lights off gives the command lights off. Variables: whole message, command, trigger word, user name and id, channel and its id, source (channel for a channel outgoing webhook, direct for a slash command or a bot).

Security and limits:

  • A request whose form field token is not one of the tokens typed is ignored; with no token typed, every request is ignored. The token is never read from the URL.
  • Gladys never answers in the chat by itself: the webhook answers empty, and nothing is sent in reaction to a received message. When a scene started by a command sends a message that starts with the trigger word, that message, if it comes back within a minute through the outgoing webhook with exactly the same text, is recognised and ignored. Were Synology Chat to change the text (links, special characters), only the limit of 20 requests a minute would slow the loop: pick a trigger word the answers of your scenes do not repeat.
  • At most 20 requests a minute; the same message (post_id) is handled once while the integration runs; a message dated more than 10 minutes away from the clock of Gladys is ignored.
  • Bot messages with buttons (interactive actions) are not read.

Status​

The integration page shows: ready to send, or what blocks (URL missing or unreadable, http:// without the option, invalid fingerprint, certificate to confirm with its fingerprint, pause of the NAS, last failure), then the state of the chat commands (active, without Gladys Plus, token missing or unreadable). The last failure clears with the first message accepted, or when the URL, the fingerprint or the HTTP option change.

Data kept​

/data/synology-chat-state.json only keeps the end of the pause the NAS asked for and its level. Never the URL, a token nor a message. A file that cannot be read is never overwritten.

Konfigurationseinstellungen​

Diese Einstellungen fragt Synology Chat in seinem Konfigurationsbildschirm in Gladys ab.

EinstellungTypPflichtfeldBeschreibung
Sending messagessectionNeinUnofficial connector, not affiliated with Synology. In Synology Chat, open your profile picture > Integration > Incoming Webhooks, create one for the channel, and copy its URL below. Your scenes then use the action "Send a Synology Chat message". If the NAS shows a self-signed certificate, click "Send a test message": the status shows its fingerprint, to check in DSM and copy below.
Incoming webhook URLsecretJaThe whole URL shown by Synology Chat (…/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming…&token=…). It lets anyone post in the channel: kept by Gladys in its database, never shown again, sent only to your NAS.
Certificate fingerprint (SHA-256)stringNeinOnly for a NAS with a self-signed certificate. Empty: the certificate must be signed by an authority for the name in the URL. Typed: only that certificate is accepted.
Allow HTTP (no TLS)booleanNeinAccept an http:// URL: the token of the webhook and the messages then cross your network in clear. Off by default.
Commands from the chat (Gladys Plus)sectionNeinTo start a scene from a message, link Gladys Plus and paste your Open API key in the "Gladys Plus webhooks" block: Gladys shows a public URL. In Synology Chat, create an outgoing webhook (or a slash command, or a bot) with that URL, then copy its token below. Your scenes use the trigger "Synology Chat command received". Without Gladys Plus, only sending works. Gladys never answers in the chat by itself.
Outgoing webhook token(s)secretNeinThe token shown by Synology Chat for the outgoing webhook, slash command or bot (up to 5, separated by spaces). A request without one of them is ignored; none typed: every request is ignored. Kept by Gladys in its database, never shown again, never sent anywhere.

So installierst du Synology Chat in Gladys​

  1. Öffne in Gladys Integrationen: Synology Chat erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
  2. Klicke auf Installieren. Gladys lädt das Docker-Image (ghcr.io/lm1lc3n7/gladys-synology-chat:0.1.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die Oberfläche der Integration (Geräte, Erkennung und Konfiguration).
  3. Öffne den Bildschirm Konfiguration der Integration, fülle die Einstellungen aus und speichere.
  4. Du kannst sie auch direkt über die URL ihres Repositorys installieren: https://github.com/LM1LC3N7/gladys-synology-chat.

Synology Chat benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stündlich aktualisiert, eine neue Version ist also spätestens eine Stunde nach ihrer Veröffentlichung verfügbar.

Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.

Über externe Integrationen​

Synology Chat ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und führt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LM1LC3N7 veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.

Abonniere den Newsletter von Gladys Assistant

Ein paar E-Mails im Monat zu neuen Releases und Neuigkeiten aus dem Projekt. Verschickt von Pierre-Gilles Leymarie, dem Gründer des Projekts. Jederzeit abbestellbar 🙂