Skip to content

Getting started

The Kappapps SDK is loaded automatically by the platform into every app and every widget. By the time your code runs, the SDK is already up and every service is available through the global k object.

App or widget?

AppWidget
NatureAn interactive game or tool, with a lifecycleA triggered overlay element (media, announcement, short script)
SDK classAppliWidget
Extra servicespreferences, dataStorage, userDataStorage, logsStorage, dynamicTriggers, dynamicContent, rewards, plugin

Both extend the abstract App class, which carries the shared set of services (chat, users, media, overlay…).

The global k / kapp object

Everywhere in your code, two globals point to the current app/widget instance:

ts
k;     // shorthand
kapp;  // identical alias

It is your entry point to every service:

ts
await k.chat.say('Hey chat!');
const viewer = await k.users.get('toto');
await k.medias.playAudio('https://.../win.mp3', 80);

Available services

A few of the most used ones (full list in the API Reference):

AccessServiceRole
k.chatChatSend messages, listen to messages & commands
k.usersUsersFetch viewers, currency, roles, moderation
k.mediasMediaPlay sounds / videos / images on the overlay
k.announcesAnnouncementsComposed announcements (chat + TTS + screen)
k.overlayOverlayCommunicate with the overlay core
k.apiAPIAuthenticated HTTP calls to the backend
k.twitch / k.streamTwitch / StreamInfo about the ongoing stream
k.dataStorage (app)StoragePersist the app's state
k.preferences (app)PreferencesRead/write the app's config

Global helpers

Beyond k, the SDK exposes a few global shortcuts:

ts
text('welcome');                  // resolves a textset key (i18n / editable text)
text('welcome', { name: 'Bob' }); // with interpolation
await wait(2000);                 // 2 s pause (Promise)
prefs;                            // the app's preferences object (shortcut for k.preferences)

Lifecycle

An app/widget goes through these stages — bootstrapping (execute) is handled by the platform; you mostly drive the end and the display.

ts
k.display();    // show the app on the overlay
k.undisplay();  // hide it
await k.finish(); // finish cleanly (sends out rewards for an app)
await k.abort('reason'); // interrupt

Hooking code before exit

ts
k.onBeforeFinish(async () => {
    // final save, goodbye message…
    await k.chat.say('Game over!');
});

k.onBeforeAbort(() => {
    // cleanup on interruption
});

k.onBeforeExit('*', () => {
    // runs in both cases (finish or abort)
});

A first complete example

A tiny app that reacts to the !hello command and rewards the viewer:

ts
k.chat.onCommand('hello', async (user, event) => {
    await k.chat.say(`Welcome ${user.display_name} 👋`);
    await k.users.currency.add(user, 100);
});

// Show the app, then finish it after one minute
k.display();
await wait(60_000);
await k.finish();

What's next?

Everything is in the API Reference: every service is documented method by method, with examples. Use the search box (top right) to find a specific function.

Last updated: