HTML, embedded pages and files

A bot writes a rich answer once. Each chat system then shows what it can: the web chat draws the HTML, plays the video or shows the picture, and Slack, Google Chat and Microsoft Teams get the words you wrote for them. You never check the platform first, and you never write "open the web chat to see this".

HTML in the message

import { message } from "@wingman/core";

await conversation.reply(
  message("Our plans:").html(
    "<table><tr><th>Plan</th><th>Price</th></tr><tr><td>Pro</td><td>$20</td></tr></table>",
    "**Pro** costs $20 a month.",
  ),
);

The first argument is the HTML; the second is the fallback, in Markdown. On the web chat the HTML is drawn inside the reply, after it has been cleaned to a short list of safe elements — formatting, lists, tables, links, https: pictures. Scripts, event handlers, style, class and id are removed.

A page inside the message

await conversation.reply(
  message("Book a slot:").frame({ url: "https://calendar.example/acme", title: "Booking", height: 480 }),
);

A frame is a separate page running in a sandbox: it can run its own scripts but cannot reach the page around it. Give it url (an https: address) or html (a whole document of your own, with its scripts and styles). For a url frame the fallback defaults to a link to the page; an html frame must say what to show instead (fallback: "…").

A video or another page its provider can embed

import { embedLink, message } from "@wingman/core";

await conversation.reply(
  message("Here is the walkthrough:").block(await embedLink(videoUrl, conversation)),
);

embedLink asks the video's provider for its embeddable player (oEmbed) and remembers the answer in the bot's store. On the web chat the video plays in the message; everywhere else — and wherever the provider offers no player — it is the link, which Slack unfurls by itself.

Managing the fallback

The fallback is what most people in Slack, Google Chat and Teams will read, so write it as the answer in words:

Writing Instead of
**Pro** costs $20 a month, **Team** $15 per person. See the table in the web chat.
Book a slot at [our calendar](https://calendar.example/acme). (booking form)

Three rules keep it working:

  • Never check before sending. conversation.canSendHtml and conversation.canEmbedFrames exist only for composing something different on a surface that can draw it. The send itself always works: on a platform without HTML or frames, the block is swapped for its fallback before it is sent.
  • An empty fallback sends nothing for that block. If the HTML is the whole answer, its fallback must be the whole answer too.
  • What the AI and the logs read is the fallback, never the markup — so the fallback is also what the bot remembers it said.

Files

const reply = await conversation.replyWithFiles(
  message("Your invoice").attach({ name: "invoice.pdf", data: bytes, contentType: "application/pdf" }),
);
if (!reply.attached) {
  // The platform carries no files: they were listed by name in the message instead.
}

Slack and a web chat with a file store (CHAT_FILES) carry files. Google Chat and Teams cannot post one, so replyWithFiles lists the file in the message — a link for a file sent by address, its name for one sent as bytes — and answers attached: false. Check attached before telling anybody "here is the file".

In the web chat, pictures are shown as thumbnails of one height, as wide as their shape needs — above the message field while a visitor is attaching them, and in the conversation once sent. File names are never shown; any other file is a small tile naming its type (PDF, DOCX…), and clicking either downloads it.

When a person from your team writes

The operator console sends the same three things through the same path, so the same fallbacks apply:

  • Send HTML or a page opens a form: paste HTML or an https:// address, and optionally the words to show where neither can be drawn. An address is embedded as a page (a video plays where its provider allows); HTML is drawn in the message, or — when it carries a script or a style — run in a sandboxed frame. Left empty, the fallback is the link, or the HTML's own words.
  • The "+" in the message field attaches pictures, PDFs, text and Office files. It is offered only where the conversation's chat system carries files.

The console shows every message as the person saw it: their pictures, the bot's files and HTML, and the operator's own.

Related: Sending messages, Capabilities.

← CapabilitiesMentions and direct messages →