googleapis / googleapis/google-api-nodejs-client

Google Calendar Webhooks with Node.js

Open
#3,158 2 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

### What you're trying to do
- the goal is listening to the customer event response
### What is happening
- I made one implementation of push notifications using the google calendar API,
but all events are triggered when I make an update only in one event

- I'm creating all events using a main account and putting the customer as attendees in the creation process, for each event I have only one customer as an attendee, the goal is listening to the customer event response but when some customer responds to the event all, other events are triggered too and my endpoint receives calls from all events that I already create

### Calendar event creation code:
```
async createCalendarEvent(params: CalendarProvider.CreateEventParams) {
if (!this.calendar) return
try {
const event = {
summary: params.summary,
description: buildDescription({
eventName: params.eventName,
sessionDuration: params.sessionDuration,
sessionLink: params.sessionLink
}),
location: params.location,
start: {
dateTime: params.startDate,
timeZone: params.timezone
},
end: {
dateTime: params.endDate,
timeZone: params.timezone
},
...(params.recurrence && {
recurrence: buildRecurrence(params.recurrence)
}),
attendees: params.participants
}

const calendarEvent = await this.calendar.events.insert({
calendarId: DEFAULT_CALENDAR_ID,
requestBody: event
})

const watch = await this.calendar.events.watch({
requestBody: {
id: uuid4(),
type: 'web_hook',
address: `${this.webhookBaseEndpoint}/${calendarEvent.data.id}`
},
calendarId: DEFAULT_CALENDAR_ID
})


return calendarEvent?.data
} catch (error) {
console.log(error.response.data.error)
console.log(error)
Sentry.captureException(error)
}
}
```

### webhook endpoint code:
```
router.post('/calendar-webhook/:eventid', async (req, res) => {
try {
const eventId = req.params.eventid

await makeSyncCalendarResponse().sync({ eventId })

return res.sendStatus(200)
} catch (err) {
Sentry.captureException(err)
}
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.