Skins

BotProt renders its steps into one element on your page. A skin decides where that element is, and what visitors see around it while BotProt checks them, when it succeeds and when it fails.

What a skin is

A BotProt step on its own is a bare challenge or loading state, without context. A skin puts it somewhere on your page and handles the end of the check. It cleans up after a token, and tells the visitor when something went wrong.

A barebones skin needs a show() call to provide an element to render its steps into. Some other options of createBotProt are:

There are three ways to get these options:

// OT is window.OpenTicket, once botprot.js and the skin are loaded (see Loading a skin).

// Reference skin: BotProt in a dialog, nothing to set up.
const token = await OT.createBotProt(identifier, OT.createBotProtReferenceSkin());

// Shop skin: the landing page in the look of the shop, in your element.
const skin = await OT.createBotProtShopSkin(identifier, { whitelabel: 'openticket.tech', show, final, fail });
const token = await OT.createBotProt(identifier, skin);

// Roll your own: no skin, your own element and callbacks.
const token = await OT.createBotProt(identifier, { show, final, fail });

Choosing a skin

Reference skin Shop skin Roll your own
Script skins/reference.js skins/shop.js None
Your work None Pass the shop's GUID, the whitelabel and show Write show and optionally final, fail
Renders in A dialog over the page Your element Your element
Looks like A plain white dialog The shop, in the whitelabel's style Your page
On failure BotProt's message, in the dialog Its own failure text and a "Try again" button Whatever your fail does
On final Closes the dialog Closes the landing page Whatever your final does

Loading a skin

botprot.js only adds createBotProt. Each skin is a script of its own, next to botprot.js at skins/{name}.js, so a page only loads the skin it uses. Its types are next to it, at skins/{name}.d.ts. Roll your own needs no skin script at all.

A skin adds its function to window.OpenTicket, named createBotProt{Name}Skin, and then fires BotProt:Skin:{name}:Ready on the document, with the global as its detail. That works like BotProt:Client:Ready for botprot.js. The scripts can load in any order, so wait for both:

<script src="https://lobby.openticket.tech/botprot.js"></script>
<script src="https://lobby.openticket.tech/skins/reference.js"></script>
<script>
  // Resolves with window.OpenTicket once it has `member`, now or when `event` fires.
  function ready(member, event) {
    return new Promise((resolve) => {
      if (window.OpenTicket?.[member]) {
        resolve(window.OpenTicket);
      } else {
        document.addEventListener(event, (e) => resolve(e.detail), { once: true });
      }
    });
  }

  Promise.all([
    ready('createBotProt', 'BotProt:Client:Ready'),
    ready('createBotProtReferenceSkin', 'BotProt:Skin:reference:Ready'),
  ]).then(async ([OT]) => {
    const token = await OT.createBotProt('my-identifier', OT.createBotProtReferenceSkin());
    // Verified: continue with the token.
  });
</script>

Load each skin once. A skin's function cannot be redefined, so a second copy of the same script throws an error.

Reference skin

If you want the most basic BotProt on your page. Load skins/reference.js next to botprot.js. createBotProtReferenceSkin() takes no arguments and returns the options createBotProt needs:

const token = await OT.createBotProt(identifier, OT.createBotProtReferenceSkin());
// Verified: continue with the token.

What it does:

The dialog is a <dialog class="ot-botprot-dialog">, at most 400px wide, white, rounded and with a shadow. BotProt renders into #ot-botprot-dialog__content inside it. The skin's styles have zero specificity, so any rule on your page for .ot-botprot-dialog wins:

/* Any selector beats the skin's own styles. */
.ot-botprot-dialog {
  width: min(560px, calc(100vw - 2rem));
  border-radius: 0;
  font-family: inherit;
}

If you want anything else custom, you can always opt to roll your own.