Integration
This page shows how to load BotProt on your page, get a final token and send it to the Shop API.
Smallest integration
Load botprot.js and call createBotProt with the shop's GUID. No skin and no options are needed:
<script src="https://lobby.openticket.tech/botprot.js"></script>
<script>
const shopGuid = 'your-shop-guid';
async function start(OT) {
const token = await OT.createBotProt(shopGuid);
// Send the token in the x-botprot-verification header, see Use the token.
}
if (window.OpenTicket?.createBotProt) {
start(window.OpenTicket);
} else {
document.addEventListener('BotProt:Client:Ready', (e) => start(e.detail), { once: true });
}
</script>
When the shop has no steps the visitor solves, the visitor sees nothing. Depending on the shop's setup, the token arrives right away or takes a moment, because BotProt runs steps that finish by themselves. Either way, wait for it before the first reservation. If the shop has a safety net, it can send the visitor to a waiting room when traffic peaks. BotProt brings them back to this page afterwards, and the code above continues the run when the page loads.
When steps the visitor solves are added to the shop later, this code keeps working. BotProt then renders the steps in a plain element at the bottom of the page and removes it when it is done. For a proper look, use a skin or your own element, as below.
With a skin or your own element
BotProt with the reference skin shows the steps in a dialog:
<script src="https://lobby.openticket.tech/botprot.js"></script>
<script src="https://lobby.openticket.tech/skins/reference.js"></script>
<script>
// Resolves to window.OpenTicket once it has `member`: right away, 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 });
}
});
}
async function start() {
const OT = await ready('createBotProt', 'BotProt:Client:Ready');
await ready('createBotProtReferenceSkin', 'BotProt:Skin:reference:Ready');
try {
const token = await OT.createBotProt('your-shop-guid', OT.createBotProtReferenceSkin());
// Verified: continue with the token.
console.log('BotProt token:', token);
} catch (error) {
// For developers: error.message and error.code (see botprot.d.ts).
console.error(error);
}
}
start();
</script>
You can also load it inside a provided element without using a skin:
<div id="botprot-container"></div>
<script src="https://lobby.openticket.tech/botprot.js"></script>
<script>
const identifier = 'your-shop-guid';
const options = {
show() {
return document.getElementById('botprot-container');
},
};
async function start(OT) {
try {
const token = await OT.createBotProt(identifier, options);
// Verified: continue with the token.
console.log('BotProt token:', token);
} catch (error) {
// For developers: error.message and error.code (see botprot.d.ts).
console.error(error);
}
}
if (window.OpenTicket?.createBotProt) {
start(window.OpenTicket);
} else {
document.addEventListener('BotProt:Client:Ready', (e) => start(e.detail), { once: true });
}
</script>
Using the final token
Send the token in the x-botprot-verification header on every reservation and order request to the
Shop API. Use the shop's GUID as identifier, because the token only works for that shop:
const token = await OT.createBotProt(shopGuid, OT.createBotProtReferenceSkin());
const response = await fetch(`https://shop.api.openticket.tech/${shopGuid}/reserve/ticket/${ticketGuid}`, {
headers: { 'x-botprot-verification': token },
});
See Reservations and Creating orders for the requests and the errors they return.
Types
Download botprot.d.ts into your project for typings of the window.OpenTicket global. Each skin has its own, skins/{name}.d.ts next to skins/{name}.js save it as well.
These are your own copies: the scripts update at their URL, the copies do not. Download them again now and then, such as when you work on your integration, to keep them up to date.
The types live in the global OpenTicket namespace, so a script without imports can use them, e.g. in JSDoc: /** @type {OpenTicket.BotProtOptions} */. A TypeScript module can import them as well: import type { BotProtOptions } from './botprot.d.ts';.
- VS Code picks it up automatically when it is covered by a
jsconfig.json/tsconfig.json. Without one, add/// <reference path="./botprot.d.ts" />to the top of the file using the global. - WebStorm picks it up when it is in the project. Alternatively, attach it to the JavaScript library downloaded from the script tag (Settings → Languages & Frameworks → JavaScript → Libraries).