Integration Tutorial ================= This tutorial covers integrating WTicket with external systems and custom applications. Objective --------- Learn how to integrate WTicket functionality into your existing applications. Embedding WTicket Widget ----------------------- Embed a simplified ticket creation widget in external pages. .. code-block:: html
Custom Data Fetching -------------------- Fetch ticket data for external dashboards. .. code-block:: javascript class WTicketClient { constructor(apiKey, bins) { this.baseUrl = 'https://api.jsonbin.io/v3'; this.apiKey = apiKey; this.bins = bins; } async get(endpoint) { const response = await fetch( `${this.baseUrl}/b/${this.bins[endpoint]}/latest`, { headers: { 'X-Master-Key': this.apiKey } } ); return (await response.json()).record; } async getStats() { const tickets = await this.get('tickets'); const users = await this.get('users'); const open = Object.values(tickets) .filter(t => t.status === 'open').length; const closed = Object.values(tickets) .filter(t => t.status === 'closed').length; return { openCount: open, closedCount: closed, totalCount: open + closed, userCount: Object.keys(users).length }; } } // Usage const client = new WTicketClient(API_KEY, BIN_IDS); const stats = await client.getStats(); console.log(stats); Webhook Notifications -------------------- Set up custom notifications when tickets are created. .. code-block:: javascript // Monitor for new tickets using polling class TicketWebhook { constructor(callback, interval = 5000) { this.callback = callback; this.interval = interval; this.lastTicketId = 0; } async check() { const tickets = await API.getOpenTickets(); const newest = Math.max(...tickets.map(t => t.id)); if (newest > this.lastTicketId) { this.lastTicketId = newest; const newTickets = tickets.filter(t => t.id > this.lastTicketId); newTickets.forEach(t => this.callback(t)); } } start() { this.check(); setInterval(() => this.check(), this.interval); } } // Usage const webhook = new TicketWebhook((ticket) => { console.log('New ticket:', ticket.title); // Send email, Slack notification, etc. }); webhook.start(); External Dashboard Integration ----------------------------- Create a custom admin dashboard. .. code-block:: javascript async function buildDashboard(containerId) { const container = document.getElementById(containerId); // Fetch data const stats = await API.getStats(); const openTickets = await API.getOpenTickets(); const closedTickets = await API.getClosedTickets(); // Build dashboard HTML container.innerHTML = `