Javascript API - callbacks

Callbacks can be configured to let Candu content trigger actions with your own application.


Passing Callbacks in

Pass callbacks to Candu.init

Candu.init({
  clientToken: 'YOUR_CLIENT_TOKEN',
  userId: 'USER_ID_TO_TRACK',
  callbacks: { 
    triggerUpgrade: () => {
      myApp.triggerUpgradeModal();
    }
  }
});

Callback Data

callbacks functions have the following signature:

// A CanduNode contains either more nodes nested inside, or in the case of basic components like Buttons, a string child
interface CanduNode {
  type: string;
  nodes: string[];
  props: {
    children?: string;
    variant: string;
  }
}

interface CanduAction {
  category: string;
  eventName: string;
  handler: {
    name: string;
    type: 'callback';
  },
  trigger: string;
}

type Callback = (e: Event, node: CanduNode, action: CanduAction) => void;