Chris Hansen
Chris Hansen

Reputation: 8653

How to send a notification to attendees using google calendar nodejs api?

I have the following code

    let calendar = google.calendar({
        version: "v3",
        auth: oauth2Client,
    });

    let resource = {
        summary: process.env.SITE_NAME + " 1-1 Session",
        location: options.comments,
        description: "";
        start: {
            dateTime: new Date(options.startDate),
            timeZone: "utc",
        },
        end: {
            dateTime: new Date(options.endDate),
            timeZone: "utc",
        },
        attendees: [
            {
                email: options.user.email,
            },
            {
                email: options.mentor.email,
            },
        ],
        reminders: {
            useDefault: false,
            overrides: [
                {
                    method: "email",
                    minutes: 15,
                },
                {
                    method: "email",
                    minutes: 60,
                },
                {
                    method: "popup",
                    minutes: 10,
                },
            ]
        },
        colorId: 4,
        sendUpdates: "all",
        status: "confirmed",
    };

I want to send a google notification to attendees when they book an appointment. How can I do so using the code above?

Upvotes: 0

Views: 734

Answers (1)

Tanaike
Tanaike

Reputation: 201358

I believe your goal is as follows.

  • When an event is created, you want to send a notification email.
  • You want to achieve this using googleapis for Node.js.

In this case, how about the following sample script?

In this case, I think that resource is not required to be modified. Please modify the script for requesting Calendar API as follows.

Sample script:

calendar.events.insert({
  calendarId,
  resource,
  sendNotifications: true, // <--- Please add this.
})
.then(({ data }) => console.log(data))
.catch(({ errors }) => console.log(errors));

Reference:

Upvotes: 1

Related Questions