bf75ab8982
Adds an `on-partner-application-created` logic function triggered on the `partner.created` database event. When the website application form creates a new Partner, it posts a rich embed to a Discord channel (applicant, company, country, languages, partner scope, skills) with a deep link to the record. ## How it works - Fires only on genuine form submissions — discriminates via `createdBy.source === 'APPLICATION'`, which excludes seed/import (`API`) and manual UI (`MANUAL`) creation. - Runs out-of-band on the worker (database event trigger), so it adds **no latency** to the applicant's submission, and the linked Person already exists by the time it runs. - Best-effort: a Discord failure never fails the trigger (wrapped in `try/catch`, 8s timeout). ## Configuration (per workspace — Settings → Apps → Twenty Partners → Variables) - `DISCORD_WEBHOOK_URL` (secret) — the incoming webhook URL. **The feature is a no-op when unset.** - `PARTNER_APP_FRONTEND_URL` — workspace front-end base URL for the record deep link (e.g. `https://partners.twenty.com`). ## Notes - New logic function + two application variables; version bumped to **0.4.0** (minor). - Unit tests cover the source-guard branches, the on/off switch, the embed contents/ordering, and best-effort failure handling. - The website and the existing `submit-partner-application` handler are untouched.
34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
import { defineApplication } from 'twenty-sdk/define';
|
|
|
|
import {
|
|
APP_DESCRIPTION,
|
|
APP_DISPLAY_NAME,
|
|
APPLICATION_UNIVERSAL_IDENTIFIER,
|
|
} from 'src/constants/universal-identifiers';
|
|
|
|
export default defineApplication({
|
|
universalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,
|
|
displayName: APP_DISPLAY_NAME,
|
|
description: APP_DESCRIPTION,
|
|
applicationVariables: {
|
|
PARTNER_APPLICATION_SECRET: {
|
|
universalIdentifier: '2026a052-9f01-4d18-b6a7-31c3a5b1c7d2',
|
|
description:
|
|
'Shared secret required in the X-Application-Secret header on POST /partner-applications. Must match the website route\'s PARTNER_APPLICATION_SECRET env var. Set per-workspace in Settings → Apps → Twenty Partners → Variables.',
|
|
isSecret: true,
|
|
},
|
|
DISCORD_WEBHOOK_URL: {
|
|
universalIdentifier: '7056c98a-e7e1-4dba-8a40-b578f30b3479',
|
|
description:
|
|
'Discord incoming webhook URL. When set, a notification is posted to this channel each time the application form creates a new Partner. Leave empty to disable. Set per-workspace in Settings → Apps → Twenty Partners → Variables.',
|
|
isSecret: true,
|
|
},
|
|
PARTNER_APP_FRONTEND_URL: {
|
|
universalIdentifier: '746e7bd8-8934-414e-95f5-cc266a624616',
|
|
description:
|
|
'Workspace front-end base URL (e.g. https://partners.twenty.com), used to build the clickable Partner record link in the Discord notification. Set per-workspace in Settings → Apps → Twenty Partners → Variables.',
|
|
isSecret: false,
|
|
},
|
|
},
|
|
});
|