Skip to content

Class: DynamicTrigger<TUpdateData, TSchema> ​

Represents a dynamic trigger created on the fly by an app: a command, a keyword, a Twitch reward, an interval… to which you attach a callback executed on each trigger.

Remarks ​

You don't instantiate this class directly: it is returned by k.dynamicTriggers.create(...) or k.dynamicTriggers.createFromConfig(...) (available only in an app, not in a widget).

Example ​

ts
const trigger = await k.dynamicTriggers.create({
    type: 'CHATCMD',
    title: 'Greet',
    keyword: 'hello',
});

trigger.onTrigger(async (t, request, resolve) => {
    k.chat.say(`Hi ${request.setter.display_name}!`);
    await resolve();
    return 'ok';
});

Type Parameters ​

TUpdateData ​

TUpdateData extends | DynamicTriggerCreateData | DynamicTriggerConfig = DynamicTriggerCreateData

TSchema ​

TSchema extends | DynamicTriggerArgumentSchema | undefined = undefined

Properties ​

authorization_level? ​

ts
optional authorization_level?: KappappsRoleType;

Minimum role required to trigger (e.g. 'mod').


color? ​

ts
optional color?: string;

Color associated with the trigger.


cooldown? ​

ts
optional cooldown?: number;

Global cooldown (in seconds) between two triggers.


cost? ​

ts
optional cost?: number;

Cost in internal currency to trigger.


description? ​

ts
optional description?: string;

Displayed description of the trigger.


id ​

ts
id: number;

Unique identifier of the trigger.


interval_duration? ​

ts
optional interval_duration?: number;

Interval duration (in seconds) for a trigger of type INTERVAL.


keyword? ​

ts
optional keyword?: string;

Keyword / command that activates the trigger (depending on the type).


max_per_player_per_stream? ​

ts
optional max_per_player_per_stream?: number;

Maximum number of triggers per player per stream.


max_per_stream? ​

ts
optional max_per_stream?: number;

Maximum number of triggers per stream.


needs_input? ​

ts
optional needs_input?: boolean;

Whether a Twitch reward asks Twitch to collect user input. Ignored by dashboard triggers.


prompt? ​

ts
optional prompt?: string;

Prompt text shown to the user when input is required.


title ​

ts
title: string;

Displayed title of the trigger.


type ​

ts
type: DynamicTriggerType;

Trigger type (chat command, keyword, regex, Twitch reward, interval…).


user_cooldown? ​

ts
optional user_cooldown?: number;

Cooldown (in seconds) applied per user.

Methods ​

assignFromData() ​

ts
assignFromData(data): void;

Updates the instance's local properties from new data.

Parameters ​

data ​

DynamicTriggerData

The trigger data to copy onto the instance.

Returns ​

void

Remarks ​

This only refreshes the in-memory object; it makes no network call. To persist a change on the server side, use update.


onTrigger() ​

ts
onTrigger(call): void;

Registers a callback executed on each trigger of this trigger.

Parameters ​

call ​

DynamicTriggerCallFunction<TSchema, TUpdateData>

Function called with the trigger, the trigger data, and two helpers resolve / reject to accept or reject the request (useful when a currency cost is involved).

Returns ​

void

Example ​

ts
trigger.onTrigger(async (t, request, resolve, reject) => {
    if (!partieEnCours) {
        await reject('The game is over');
        return 'rejected';
    }
    await resolve();
    return 'ok';
});

rejectRequest() ​

ts
rejectRequest(trigger_request, reason?): Promise<void>;

Rejects a trigger: refunds the user and notifies the rejection.

Parameters ​

trigger_request ​

Pick<TriggerRequestData, "id">

The trigger to reject.

reason? ​

string = null

Reason for the rejection, shown to the user.

Returns ​

Promise<void>

A promise resolved once the rejection has been sent to the server.

Default Value ​

null

See ​

resolveRequest to accept the trigger instead.


remove() ​

ts
remove(): Promise<void>;

Permanently deletes this dynamic trigger on the server side.

Returns ​

Promise<void>

A promise resolved once the deletion has been performed.


resolveRequest() ​

ts
resolveRequest(trigger_request): Promise<void>;

Accepts a trigger (confirms the currency spend if applicable).

Parameters ​

trigger_request ​

Pick<TriggerRequestData, "id">

The trigger to confirm.

Returns ​

Promise<void>

A promise resolved once the confirmation has been sent to the server.

See ​

rejectRequest to reject the trigger.


update() ​

ts
update(data): Promise<void>;

Updates this trigger on the server side with new data.

Parameters ​

data ​

TUpdateData

The new trigger data — see DynamicTriggerCreateData.

Returns ​

Promise<void>

A promise resolved once the update has been performed.

Remarks ​

A trigger returned by create() keeps the historical partial PATCH /trigger/v1/{id} contract and accepts DynamicTriggerCreateData. A trigger returned by createFromConfig() expects the complete DynamicTriggerConfig of the same immutable type and uses PUT /trigger/v2/{id}. If the trigger has an argument schema, omit arguments to preserve it or repeat the same schema. Changing/removing it is rejected by the backend; recreate the trigger to change its argument contract.

See ​

assignFromData to refresh only the in-memory object.