github nylas/nylas-nodejs v5.10.0

latest releases: v7.5.2, v7.5.1, v7.5.0...
2 years ago

This release of the Node SDK provides more new features with the addition of Event notifications, additional Scheduler functionality, and more Metadata support.

New Features

  • Event notification support
  • Expanded Metadata support for Calendar, Message and ManagementAccount
  • Support for remaining Scheduler endpoints

Using New Features

Event Notifications

To add notifications to an event:

const notificationEvent = nylas.events.build({
  ...
  notifications: [
  {
    body: 'Reminding you about our meeting.',
    minutes_before_event: 600,
    subject: 'Test Event Notification',
    type: 'email',
  },
  {
    type: 'webhook',
    minutes_before_event: 600,
    url: 'https://hooks.service.com/services/T01A03EEXDE/B01TBNH532R/HubIZu1zog4oYdFqQ8VUcuiW',
    payload: JSON.stringify({
      text: 'Your reminder goes here!',
    }),
  },
  {
    type: 'sms',
    minutes_before_event: 60,
    message: 'Test Event Notification',
  },
  ],
});

To retrieve event notification details of an event:

const event = await nylas.events.find("id");

const minutesBeforeEvent = event.notifications[0].minutesBeforeEvent
const type = event.notifications[0].type
const body = event.notifications[0].body
const url = event.notifications[0].url
const subject = event.notifications[0].subject
const payload = event.notifications[0].payload
const message = event.notifications[0].message

To update an event with a notification:

const event = await nylas.events.find("id");

event.notifications = [
  {
    body: 'Reminding you about our meeting.',
    minutes_before_event: 600,
    subject: 'Test Event Notification',
    type: 'email',
  }
];
event.save();

To delete a notification from an event:

const event = await nylas.events.find("id");

event.notifications = [];
event.save();

New Scheduler functionality

Checking Provider Availability

// Google Availability
const googleAvailability = await nylas.scheduler.getGoogleAvailability();

// Office 365 Availability
const o365Availability = await nylas.scheduler.getOffice365Availability();

Retrieve available time slots

const availabileTimeslots = await nylas.scheduler.getAvailableTimeslots('slug');

Book a time slot

const slot = new SchedulerSlot(nylas);
slot.accountId = 'test-account-id';
slot.calendarId = 'test-calendar-id';
slot.emails = ['recipient@example.com'];
slot.start = new Date("2021-08-24T15:05:48.000Z");
slot.end = new Date("2021-08-24T16:05:48.000Z");

const timeslotToBook = new SchedulerTimeslot(nylas);
timeslotToBook.additionalValues = {
  test: 'yes',
};
timeslotToBook.email = 'recipient@example.com';
timeslotToBook.locale = 'en_US';
timeslotToBook.name = 'Recipient Doe';
timeslotToBook.timezone = 'America/New_York';
timeslotToBook.slot = slot;

const availabileTimeslots = await nylas.scheduler.bookTimeslot('slug', timeslotToBook);

Confirm a booking

const bookingConfirmation = await nylas.scheduler.confirmBooking('slug', 'edit-hash');

Cancel a booking

await nylas.scheduler.cancelBooking('slug', 'edit-hash', 'reason');

Expanded Metadata support

Adding Metadata to a calendar

const calendar = nylas.calendars.create();
calendar.name = "My New Calendar";
calendar.description = "Description of my new calendar";
calendar.location = "Location description";
calendar.timezone = "America/Los_Angeles";
calendar.metadata = {
  test: "true",
};

calendar.save();

// Or you can update a calendar with metadata

const calendar = nylas.calendars.first();

calendar.metadata = {
  test: "true",
};

calendar.save();

Query Calendars by Metadata

const calendars = nylas.calendars.list({metadata_key: "test"});

Adding Metadata to an account

const account = Nylas.accounts.list();

account.metadata = {
  test: "true",
};

account.save();

Query Account by Metadata

const accounts = Nylas.accounts.list({metadata_key: "test"});

Adding Metadata to a message

const message = Nylas.messages.first();

message.metadata = {
  test: "true",
};

message.save();

Query Messages by Metadata

const messages = Nylas.messages.list({metadata_key: "test"});

Don't miss a new nylas-nodejs release

NewReleases is sending notifications on new releases.