> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Event Extension Files and Code ## Article: Event Extension Files and Code ## Article Link: https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/events/event-extension-files-and-code.md ## Article Content: # Event Extension Files and Code When you generate an event extension, the CLI adds the following files to your project: - `.extension.ts`: Builds the [event](#event-builder). - `.ts`: Defines the [event handler logic](#event-handler). ## Event builder The `.extension.ts` file contains an event extension's builder configuration. The event builder is defined using the following schema, shown here as a TypeScript type: ```ts import { extensions } from '@wix/astro/builders'; export default extensions.event({ id: string, source: string, }); ``` Here's an example builder definition: ```ts import { extensions } from '@wix/astro/builders'; export default extensions.event({ id: '9912811d-5f5b-41f9-b4d6-ef4163b714a7', source: './extensions/backend/events/my-event/my-event.ts', }); ``` ### Builder fields The following fields can be used in the configuration object: | Field | Type | Description | |-------|------|-------------| | `id` | string | Event extension ID as a ([GUID](https://en.wikipedia.org/wiki/Universally_unique_identifier)). The ID is automatically generated and must be unique across all extensions in the project. | | `source` | string | Path to the event handler file that contains the event logic. |
**Important:** You can't have 2 event extensions listening to the same event in your app. Each event can only have one handler. This includes extensions added to your app in the [app dashboard](https://manage.wix.com/account/custom-apps), not only those in the local files for your project.
## Event handler The `.ts` file contains an event extension's handler logic. This file contains: - The relevant import statement for the event. - An event function where you can implement your custom logic. Wix calls this function when the given event occurs, passing the event object and its metadata. Event functions are documented in their module in the [JavaScript SDK reference](https://dev.wix.com/docs/sdk.md). The generated `.ts` file will contain example code for an event. The `.ts` file must be in the following format: ```ts import { } from '@wix/'; export default .((event) => { // Add your logic here }); ``` Here's an example `my-event.ts` file for the Wix CRM [onContactCreated()](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts/contact-v4/contact-created.md) event: ```ts import { contacts } from '@wix/crm'; export default contacts.onContactCreated((event) => { // Add your logic here }); ```