import { Morph } from "@runmorph/cloud";
// Initialize morph client
const morph = new Morph({
publicKey: "pk_live_xxxxxxx",
secretKey: "sk_live_xxxxxxx",
});
// Initialize the connection client for a connector and customer / user
const connection = morph.connections({
connectorId: "hubspot",
ownerId: "demo",
});
// Subscribe to contact and opportunity events
const { error } = await connection.webhooks().subscribe({
events: [
"genericContact::created",
"genericContact::updated",
"crmOpportunity::created",
],
});
// Register an event handler to process webhook events in real-time
morph.webhooks().onEvents({
events: ["genericContact::created", "genericContact::updated"],
handler: ({ event, data }) => {
console.log({ event, data });
},
});