Skip to main content

lightyear.definewebhook

Home > @runlightyear/lightyear > defineWebhook

defineWebhook() function

Define a Webhook

Signature:
declare function defineWebhook(props: DefineWebhookProps): string;

Parameters

ParameterTypeDescription
propsDefineWebhookProps
Returns:

string

Example 1

Basic webhook

import { defineWebhook } from "@runlightyear/lightyear";

defineWebhook({
name: "basicWebhook",
title: "Basic Webhook",
});

Example 2

Webhook with variables

import { defineWebhook } from "@runlightyear/lightyear";

defineWebhook({
name: "webhookWithVariables",
title: "Webhook with Variables",
variables: [
"var1",
"var2?",
{
name: "var3",
description: "Required variable 3",
},
{
name: "var4?",
description: "Optional variable 4",
},
],
});

Example 3

Webhook with secrets

import { defineWebhook } from "@runlightyear/lightyear";

defineWebhook({
name: "webhookWithSecrets",
title: "Webhook with Secrets",
secrets: [
"secret1",
"secret2?",
{
name: "secret3",
description: "Required secret 3",
},
{
name: "secret4?",
description: "Optional secret 4",
},
],
});

Example 4

With subscription

defineWebhook({
name: "subscriptionWebhook",
title: "Subscription Webhook",
subscribeProps: () => {
// returns the props to be passed into subscribe
// represents essential parameters to create the subscription
},
subscribe: ({ subscribeProps }) => {
// runs after a change in subscribeProps is detected
// code to create subscription using subscribe props
// return value becomes unsubscribeProps for unsubscribe
// for example: hook id returned by rest api call
},
refreshSubscription: ({ refreshSubscriptionProps }) => {
// runs when a subscription is close to expiring
},
unsubscribe: ({ unsubscribeProps }) => {
// if subscribed, runs after a change in subscribeProps is detected
// code to unsubscribe using unsubscribe props
},
})