Back to APIs

Cal.com

cal.com

Manage your own / your teams bookings and calendars.

Using the Cal.com API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Cal.com background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using Cal.com

Below are some working code examples of how you can use Cal.com with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, verifyRequestSignature } from "@trigger.dev/sdk";
2
import { Slack } from "@trigger.dev/slack";
3
4
const dateFormatter = new Intl.DateTimeFormat("en-US", {
5
dateStyle: "medium",
6
timeStyle: "short",
7
});
8
9
const timeFormatter = new Intl.DateTimeFormat("en-US", {
10
timeStyle: "short",
11
});
12
13
const slack = new Slack({ id: "slack" });
14
15
// Create an HTTP Endpoint, with the cal.com details
16
const caldotcom = client.defineHttpEndpoint({
17
id: "cal.com",
18
source: "cal.com",
19
icon: "caldotcom",
20
verify: async (request) => {
21
return await verifyRequestSignature({
22
request,
23
headerName: "X-Cal-Signature-256",
24
secret: process.env.CALDOTCOM_SECRET!,
25
algorithm: "sha256",
26
});
27
},
28
});
29
30
// This job sends a Slack message when meetings are booked or canceled
31
client.defineJob({
32
id: "http-caldotcom",
33
name: "HTTP Cal.com",
34
version: "1.0.0",
35
enabled: true,
36
// Create a trigger from the HTTP endpoint
37
trigger: caldotcom.onRequest(),
38
integrations: {
39
slack,
40
},
41
run: async (request, io, ctx) => {
42
const body = await request.json();
43
await io.logger.info(`Body`, body);
44
45
const attendees = body.payload.attendees
46
.map((attendee: any) => attendee.email)
47
.join(", ") as string[];
48
49
const startTime = dateFormatter.format(new Date(body.payload.startTime));
50
const endTime = timeFormatter.format(new Date(body.payload.endTime));
51
52
switch (body.triggerEvent) {
53
case "BOOKING_CREATED": {
54
await io.slack.postMessage("booking-created", {
55
channel: process.env.SLACK_CHANNEL!,
56
text: `Meeting booked:\n ${attendees} \n ${startTime}${endTime}`,
57
});
58
break;
59
}
60
case "BOOKING_CANCELLED": {
61
await io.slack.postMessage("booking-cancelled", {
62
channel: process.env.SLACK_CHANNEL!,
63
text: `Meeting canceled:\n ${attendees} \n ${startTime}${endTime}`,
64
});
65
break;
66
}
67
}
68
},
69
});