-
-
Notifications
You must be signed in to change notification settings - Fork 30
[SDK] Webhooks
FTCHD edited this page Sep 8, 2024
·
2 revisions
FrameTrain has an integrated API for triggering Webhooks.
You can specify an array of events
in your template's index.ts
file, and trigger those events in your handlers
.
export default {
name: 'Lu.ma',
...
events: ['register'],
} satisfies BaseTemplate
Users that are subscribed to Webhooks from their Frames will receive a POST
request with the event and data specified by the template creator (you).
To trigger a Webhook for one of your template's events, simply return a webhooks
object in your handler
.
Returning the webhooks
field is not exclusive, i.e. it does not interfere with the other metadata of the Frame (buttons
, image
, etc), you can return both at the same time!
import type { BuildFrameData, FramePayloadValidated } from '@/lib/farcaster'
export async function myHandler({
config,
body,
storage,
}: {
config: Config
body: FramePayloadValidated
storage: Storage
}): Promise<BuildFrameData> {
// 1. do your usual handling
return {
// 2. return the usual Frame fields
buttons: [
{
label: 'Back',
},
{
label: 'Create Your Own',
action: 'link',
target: 'https://frametra.in',
},
],
component: SuccessView(config.event.title),
handler: 'success',
// 3. return a webhooks array with the event that has been triggered and its data.
webhooks: [
{
event: 'register',
data: {
email,
eventId,
ticketTypeId,
eventSlug: config.event.id,
ticket: response.data.tickets[0],
},
},
],
}
}