-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: automatic no show #16727
Merged
Merged
feat: automatic no show #16727
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
08e5ff9
chore: save progress
Udit-takkar 529c8ef
feat: add webhook and trigger
Udit-takkar e4ab4e0
feat: add logic to trigger no show
Udit-takkar 7e35fca
fix: update code
Udit-takkar 32f3a5e
chore: rename and type error
Udit-takkar 2f68105
chore: err
Udit-takkar 03c9c8c
chore: type err
Udit-takkar b8d0015
fix: type errors
Udit-takkar 83c4490
fix: types
Udit-takkar 099650e
chore: use number type
Udit-takkar 0093e11
test: add units for triggerHostNoShow
Udit-takkar 2ccc2f3
refactor: improve code
Udit-takkar 5073ff7
fix: update test after refactor
Udit-takkar 5f2d5a8
Merge branch 'main' into feat/automatic-no-show
Udit-takkar e684fd8
chore: feedback
Udit-takkar 9f36c08
refactor: use scheduled webhook trigger events
Udit-takkar 6fb3e10
fix: type check
Udit-takkar c0210f1
chore: update test
Udit-takkar 6ecafb6
chore: update tests
Udit-takkar 9bc36c9
fix: type err
Udit-takkar 1e8ffb9
fix: missing prop
Udit-takkar 0b26b11
chore: missing user prop
Udit-takkar 9e72d6d
chore
Udit-takkar 7c0800e
Merge branch 'main' into feat/automatic-no-show
Udit-takkar c49b147
refactor: also update booking
Udit-takkar 14a9d5d
Merge branch 'main' into feat/automatic-no-show
emrysal 8d09596
Remove eventType.id from getBooking (we already have eventTypeId)
emrysal 7c9391b
Update packages/features/tasker/tasks/triggerNoShow/common.ts
PeerRich cb320f1
fix setting time and timeUnit value
f660095
Merge branch 'main' into feat/automatic-no-show
CarinaWolli 25db972
Adding back ' ' to remove change
emrysal cb0f050
delete webhookScheduledTriggers after webhook triggered
a2bd361
Merge branch 'main' into feat/automatic-no-show
zomars 58e9f56
Update packages/features/ee/workflows/components/WorkflowStepContaine…
zomars 61412ed
fix zod error
1aed734
fix deleting webhookScheduledTriggers
ae2ed1e
Merge branch 'main' into feat/automatic-no-show
emrysal f1384e5
perf: Query optimisation + add index on 'Webhook.active'
emrysal 4a9dd58
Merge branch 'main' into feat/automatic-no-show
zomars a321105
Update WorkflowStepContainer.tsx
zomars 7e1e89a
tasker improvements
zomars db38447
Cleanup
zomars dd43a52
Discard changes to packages/embeds/embed-core/src/embed.test.ts
zomars 6c1d987
Update triggerHostNoShow.test.ts
zomars eeb59be
Discard changes to packages/features/webhooks/lib/handleWebhookSchedu…
zomars 40c31e8
Update sendPayload.ts
zomars 8e5eb7d
Update getWebhooks.ts
zomars ccfae87
Update getWebhooks.ts
zomars 1d1577b
test fixes
zomars 56fdc97
Merge branch 'main' into feat/automatic-no-show
Udit-takkar c7dc695
fix: add missing migration
Udit-takkar e74154f
fix: user id
Udit-takkar b9f3774
Merge branch 'main' into feat/automatic-no-show
zomars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CronJob } from "cron"; | ||
|
||
async function fetchCron(endpoint: string) { | ||
const apiKey = process.env.CRON_API_KEY; | ||
|
||
const res = await fetch(`http://localhost:3000/api${endpoint}?${apiKey}`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
authorization: `Bearer ${process.env.CRON_SECRET}`, | ||
}, | ||
}); | ||
const json = await res.json(); | ||
console.log(endpoint, json); | ||
} | ||
|
||
try { | ||
console.log("⏳ Running cron endpoints"); | ||
new CronJob( | ||
// Each 5 seconds | ||
"*/5 * * * * *", | ||
async function () { | ||
await Promise.allSettled([ | ||
fetchCron("/tasks/cron"), | ||
// fetchCron("/cron/calVideoNoShowWebhookTriggers"), | ||
// | ||
// fetchCron("/tasks/cleanup"), | ||
]); | ||
}, | ||
null, | ||
true, | ||
"America/Los_Angeles" | ||
); | ||
} catch (_err) { | ||
console.error("❌ ❌ ❌ Something went wrong ❌ ❌ ❌"); | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import dayjs from "@calcom/dayjs"; | ||
import tasker from "@calcom/features/tasker"; | ||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks"; | ||
import { WebhookTriggerEvents } from "@calcom/prisma/enums"; | ||
|
||
type ScheduleNoShowTriggersArgs = { | ||
booking: { | ||
startTime: Date; | ||
id: number; | ||
}; | ||
triggerForUser: number | true | null; | ||
organizerUser: { id: number }; | ||
eventTypeId: number; | ||
teamId?: number | null; | ||
orgId?: number | null; | ||
}; | ||
|
||
export const scheduleNoShowTriggers = async (args: ScheduleNoShowTriggersArgs) => { | ||
const { booking, triggerForUser, organizerUser, eventTypeId, teamId, orgId } = args; | ||
// Add task for automatic no show in cal video | ||
const noShowPromises: Promise<any>[] = []; | ||
|
||
const subscribersHostsNoShowStarted = await getWebhooks({ | ||
userId: triggerForUser ? organizerUser.id : null, | ||
eventTypeId, | ||
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, | ||
teamId, | ||
orgId, | ||
}); | ||
|
||
noShowPromises.push( | ||
...subscribersHostsNoShowStarted.map((webhook) => { | ||
if (booking?.startTime && webhook.time && webhook.timeUnit) { | ||
const scheduledAt = dayjs(booking.startTime) | ||
.add(webhook.time, webhook.timeUnit.toLowerCase() as dayjs.ManipulateType) | ||
.toDate(); | ||
return tasker.create( | ||
"triggerHostNoShowWebhook", | ||
{ | ||
triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, | ||
bookingId: booking.id, | ||
// Prevents null values from being serialized | ||
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit }, | ||
}, | ||
{ scheduledAt } | ||
); | ||
} | ||
return Promise.resolve(); | ||
}) | ||
); | ||
|
||
const subscribersGuestsNoShowStarted = await getWebhooks({ | ||
userId: triggerForUser ? organizerUser.id : null, | ||
eventTypeId, | ||
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW, | ||
teamId, | ||
orgId, | ||
}); | ||
|
||
noShowPromises.push( | ||
...subscribersGuestsNoShowStarted.map((webhook) => { | ||
if (booking?.startTime && webhook.time && webhook.timeUnit) { | ||
const scheduledAt = dayjs(booking.startTime) | ||
.add(webhook.time, webhook.timeUnit.toLowerCase() as dayjs.ManipulateType) | ||
.toDate(); | ||
|
||
return tasker.create( | ||
"triggerGuestNoShowWebhook", | ||
{ | ||
triggerEvent: WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW, | ||
bookingId: booking.id, | ||
// Prevents null values from being serialized | ||
webhook: { ...webhook, time: webhook.time, timeUnit: webhook.timeUnit }, | ||
}, | ||
{ scheduledAt } | ||
); | ||
} | ||
|
||
return Promise.resolve(); | ||
}) | ||
); | ||
|
||
await Promise.all(noShowPromises); | ||
|
||
// TODO: Support no show workflows | ||
// const workflowHostsNoShow = workflows.filter( | ||
// (workflow) => workflow.trigger === WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW | ||
// ); | ||
// const workflowGuestsNoShow = workflows.filter( | ||
// (workflow) => workflow.trigger === WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW | ||
// ); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To assign participant user_id from our db.