Saltar al contenido principal

Integración domótica Synology Chat, gratuita y de código abierto

Integración Synology Chat para Gladys Assistant

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

info

La documentación de esta integración la escribe su autor y, por ahora, solo está disponible en inglés.

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.

Parámetros de configuración​

Estos son los parámetros que Synology Chat te pide en su pantalla de configuración en Gladys.

ParámetroTipoObligatorioDescripción
Sending messagessectionNoUnofficial 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 URLsecretSíThe 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)stringNoOnly 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)booleanNoAccept 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)sectionNoTo 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)secretNoThe 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.

Cómo instalar Synology Chat en Gladys​

  1. En Gladys, abre Integraciones: Synology Chat aparece en el catálogo junto a las integraciones nativas, con una insignia de comunidad.
  2. Haz clic en Instalar. Gladys descarga la imagen Docker (ghcr.io/lm1lc3n7/gladys-synology-chat:0.1.1), la ejecuta en un entorno aislado del núcleo y genera la interfaz de la integración (dispositivos, descubrimiento y configuración).
  3. Abre la pantalla de Configuración de la integración, rellena los parámetros y guarda.
  4. También puedes instalarla directamente desde la URL de su repositorio: https://github.com/LM1LC3N7/gladys-synology-chat.

Synology Chat requiere Gladys >=5.1.0. El catálogo de Gladys se actualiza cada hora, así que una nueva versión está disponible como máximo una hora después de publicarse.

¿Todavía no usas Gladys? Es gratuito y de código abierto: sigue la guía de instalación para empezar.

Sobre las integraciones externas​

Synology Chat es una integración externa: una integración comunitaria empaquetada como contenedor Docker y publicada en GitHub. Gladys la instala con un clic y la ejecuta en un entorno aislado del núcleo. La publica y mantiene LM1LC3N7, no el equipo principal de Gladys.

Suscríbete a la newsletter de Gladys Assistant

Unos pocos correos al mes sobre nuevas versiones y novedades del proyecto. Enviados por Pierre-Gilles Leymarie, fundador del proyecto. Puedes darte de baja cuando quieras 🙂