How to implement an event handler

Step 1 - Initial Functions setup

If you don’t have a nango-integrations folder yet, follow the initial Functions setup guide first. Otherwise, you can skip to the next step.

Step 2 - Create your event function file

Create a new file in your integration’s folder, which should be nested unser your nango-integrations folder. For example, if you want to react to an event in your salesforce integration, your folder structure should look like this:
nango-integrations/
├── .nango
├── .env
├── index.ts
├── package.json
└── salesforce # this is the integration id and must match an integration id in your Nango dashboard
    └── setup.ts # your new event handler function
Paste the following scaffold into the file:
setup.ts
import { createOnEvent } from 'nango';

export default createOnEvent({
    description: "<description of your event handler>",
    event: 'post-connection-creation' | 'pre-connection-deletion' | 'validate-connection', // event to trigger on
    exec: async (nango) => {
        // Your integration code goes here.
    }
});
The exec function kicks off when the associated event occurs. Also import your new event file in your index.ts file:
index.ts
import './salesforce/setup';

Step 3 - Implement the event function

Implement your handler logic in the exec function. The following can help you with your implementation:

Step 4 - Deploy your integrations

To run your event function in Nango, you need to deploy it to an environment in your Nango account. To deploy all integrations in your nango-integrations folder, run:
nango deploy dev # dev is the name of the environment to which you are deploying
Currently it’s not possible to deploy specific event functions, or to test the them locally.
Questions, problems, feedback? Please reach out in the Slack community.