Function defineWebhookTrigger
- define
Webhook <Credential, RequestPayload>(): (<Name, InputParamsSchema, PayloadSchema, SubscriptionData>(definitionInput) => WebhookTriggerDefinition<Name, Credential, InputParamsSchema, PayloadSchema, RequestPayload, SubscriptionData>)Trigger Type Parameters
Credential extends AnyAppCredential
RequestPayload extends unknown
Returns (<Name, InputParamsSchema, PayloadSchema, SubscriptionData>(definitionInput) => WebhookTriggerDefinition<Name, Credential, InputParamsSchema, PayloadSchema, RequestPayload, SubscriptionData>)
- <Name, InputParamsSchema, PayloadSchema, SubscriptionData>(definitionInput): WebhookTriggerDefinition<Name, Credential, InputParamsSchema, PayloadSchema, RequestPayload, SubscriptionData>
Type Parameters
Name extends string
InputParamsSchema extends TObject<TProperties>
PayloadSchema extends AnyTriggerPayloadSchemaShape | TriggerPayloadSchemaFn<Credential, InputParamsSchema>
SubscriptionData extends {}
Parameters
definitionInput: WebhookTriggerDefinitionInput<Name, Credential, InputParamsSchema, PayloadSchema, RequestPayload, SubscriptionData>
Returns WebhookTriggerDefinition<Name, Credential, InputParamsSchema, PayloadSchema, RequestPayload, SubscriptionData>
See
Example
import {
defineTriggerPayloadSchema,
defineWebhookTrigger,
z,
} from "@rollout/framework";
import { MyAppCredential } from "./auth";
import { inputParamsSchema } from "./input";
import { payloadSchema } from "./payload";
type RequestPayload = {
webhookId: string;
body: unknown;
};
export const trigger = defineWebhookTrigger<MyAppCredential, RequestPayload>()({
name: "My Webhook Trigger",
inputParamsSchema,
payloadSchema,
async subscribe({ credential, inputParams }) {
// subscribe and return the `subscription`
},
async unsubscribe({ credential, subscription }) {
// `subscription.data` is whatever was returned from `subscribe()` above
// unsubscribe from the webhook
},
async handleEvent({ requestPayload }) {
// `handleEvent` is called from Connector's `http` handler
// via the `handleWebhookRequestJob()` function.
return {};
},
});
Used to define a Connector Webhook Trigger.