Lecca.io LogoLecca.io
TriggersPolling strategy

Create Item Based Trigger

We are working on a CLI to make this easier

Only use this trigger type if you cannot use the Time Based trigger. Timestamps are a more reliable way of determining new data, but if all you have is a unique identifier, then this trigger should work fine. Just make sure that the data you retrieve can be returned in a consistent order every time.

Create triggers folder

Locate the your app folder in the apps directory and add a new triggers folder if it doesn't exist already.

new-trigger.trigger.ts
your-new-app.app.ts

Create trigger file

Create a new file within your app's trigger folder. Call it something like new-trigger.trigger.ts. Make sure it ends with .trigger.ts.

Add your own values. We provided mock data to help initialize the process.

import { createItemBasedPollTrigger } from "@lecca-io/toolkit";
 
export const newSheet = createItemBasedPollTrigger({
  id: "your-new-app_trigger_new-trigger",
  name: "",
  description: "",
  inputConfig: [
    //Add a configuration to display the form
  ],
  run: async ({ connection, configValue }) => {
    //This must return an array in descending order. Newest items first.
    return [];
  },
  mockRun: async () => {
    return [
      //Must return an array descending order. Newest items first
    ];
  },
  extractItemIdentifierFromResponse(args) {
    //Each element in the array response must have some sort of unique identifier.
    //This method should extract that identifier.
    //If the response does not have a unique id, then you cannot use the item based trigger
    return args.response.some - identifier;
  },
});
  1. export const newTrigger = createTrigger

    • replace newTrigger with the name of your trigger.
  2. Add an id: your-new-app_trigger_new-trigger

    • Make sure the id follows the format <app-id>_trigger_<trigger-name-in-kebab-case>
  3. Add a name for your trigger

  4. Add a brief one sentence description

  5. Add an Input Config

    This is used to generate the form for the UI to configure this action.

    Read more about the Input Config

  6. Define the run method.

    This method will run every time the trigger polls.

    The common arguments used by this method are configValue and connection.

    1. configValue represents the Input Config that was used when the user configured this trigger.

    2. connection is the decrypted connection properties of the connection selected by the user when configuring this trigger.

      If using an oauth2 connection, do not worry about handling refresh tokens, that is handled by the engine. Just make the api call assuming the access token is valid.

    Return an array of items in descending order. The newest items first.

    It is very important that you return an array of items with the newest items first in the array. The engine saves the newest item's id, and every time it polls, it finds the index of that id in the newly polled data. If that id doesn't exist in the new data, all the items are ran because they are considered new. If the id does exist, then it grabs all the items that are earlier in the array from the matching index. The id (acting as a pointer), is then updated to the newest id.

  7. Define the mock method.

    The mock method is used by users when they want to generate a mock output instead of making an real api call to their third party integration.

    Ouput data is used to map to other nodes in the workflow builder. This is done by clicking Save & Test in the configuration form.

  8. Define the extractItemIdentifierFromResponse method.

    Each result returned from the run method must have some sort of unique identifier that this method can extract and return.

Add new trigger to the app's triggers property

your-new-app.app.ts
import { createApp } from "@lecca-io/toolkit";
 
export const yourNewApp = createApp({
  ...
  actions: [],
  triggers: [newTrigger], 
  connections: [],
});

On this page