- Products
- Solutions Use casesBy industry
- Developers
- Resources Connect
- Pricing
Creating calendar events is important, but having people attend those events is even more important. And most of the time, people just forget about the events because they are not reminded of them. Creating event notifications is a great way to improve attendance. The Nylas Ruby SDK offers three ways of reminding people about important events by using notifications, and in this blog post, we’re going to review them one by one.
If you already have the Nylas Ruby SDK installed and your environment is configured, then process with the blog, otherwise, I would recommend you to read the post How to Send Emails with the Nylas Ruby SDK where everything is clearly explained.
When we first create an event, the participant or participants will receive an email that they can accept or reject in order to let the organizer know that they are planning to attend the event. But it doesn’t guarantee that they will remember to attend the event. Sending event notifications using Ruby and Nylas is a great way to ensure that the participant will not forget about the event.
The most simple method is to send an event reminder email. So let’s grab our favorite code editor and create a file called EmailReminderEvent.rb
Keep in mind that if we run this script after 1:30pm it’s not going to work. Add a couple of hours to your current time before running it.
#!/usr/bin/env ruby # Import your dependencies require 'dotenv/load' require 'nylas' require 'date' # Initialize your Nylas API client nylas = Nylas::API.new( app_id: ENV["CLIENT_ID"], app_secret: ENV["CLIENT_SECRET"], access_token: ENV["ACCESS_TOKEN"] ) today = Date.today start_time = Time.local(today.year, today.month, today.day, 13, 0, 0).strftime("%s") end_time = Time.local(today.year, today.month, today.day, 13, 30, 0).strftime("%s") event = nylas.events.create(title: "Let's learn some Nylas Ruby API!", location: "Blag's Den", calendar_id: ENV["CALENDAR_ID"], when: { start_time: start_time, end_time: end_time }, notifications: [{type: "email", minutes_before_event: "10",subject: "Ruby Workshop Alert", body: "Ruby Workshop starts in 10 minutes!"}], participants: [{"name": "Blag", "email": "[email protected]"}]) if event.id puts 'Event created successfully' else puts 'There was an error creating the event' end
We can execute this script from the terminal by typing:
$ ruby EmailReminderEvent.rb
Let’s check the event invitation
And 10 minutes before the event starts, the attendee will get a reminder.
Nice and simple.
Webhooks can be used to send event reminders for Slack and Microsoft Teams. We’re going to review how to do that for Slack.
First, we need to have an Slack account. As we’re in a testing phase, it would be better to create a new and separate workspace where we can work without disrupting anyone else. So, we can go to Add Workspaces → Create a new workspace.
We will need to enter our email address for validation.
We will receive a security code, so we need to check our inbox.
This will open Slack with the new workspace option.
Here we can choose an appropriate name.
We’re just testing, so no need to invite anyone else. Simply skip this step.
Again, we can write something appropriate here.
Slack really wants us to collaborate, but let’s just skip this.
Can’t blame them for trying ????. We can just skip it again.
And that’s it.
Now comes the interesting part. Let’s create a new Slack application. We’re going to use the “From scratch” option.
We need to choose a name for our application and also a workspace to work with. We’re using our newly created workspace.
Once we created the application, we will be presented with some options to add features and functionality. Let’s choose Incoming Webhooks.
It will be off by default, so we just need to activate it.
Next, we need to add it to our workspace.
Slack needs to know where the messages from the Webhook are going to be posted, so let’s choose the channel that we created in a previous step.
Now, we can use the webhook address in our Ruby script.
So, let’s create the script and call it WebhookReminderEvent.rb
Keep in mind that if we run this script after 12:00pm it’s not going to work. Add a couple of hours to your current time before running it.
#!/usr/bin/env ruby # Import your dependencies require 'dotenv/load' require 'nylas' require 'date' # Initialize your Nylas API client nylas = Nylas::API.new( app_id: ENV["CLIENT_ID"], app_secret: ENV["CLIENT_SECRET"], access_token: ENV["ACCESS_TOKEN"] ) # Get today’s date today = Date.today # Today’s date at 11:30:00 am start_time = Time.local(today.year, today.month, today.day, 13, 0, 0).strftime("%s") # Today’s date at 12:00:00 am end_time = Time.local(today.year, today.month, today.day, 12, 0, 0).strftime("%s") # Create the event event = nylas.events.create(title: "Let's learn some Nylas Ruby API!", location: "Blag's Den", calendar_id: ENV["CALENDAR_ID"] , when: { start_time: start_time, end_time: end_time }, notifications: [{type: "webhook", minutes_before_event: "10", url: "<your_slack_webhook>", payload: {text: "Ruby Workshop starts in 10 minutes!"}.to_json}], participants: [{"name": "Blag", "email": ENV["RECIPIENT_ADDRESS"] }], notify_participants: true) # Everything went Ok if event.id puts 'Event created successfully' # Something went wrong else puts 'There was an error creating the event' end
We can run this script from the terminal by typing:
$ ruby WebhookReminderEvent.rb
Ten minutes prior to the event, we will get a notification on Slack.
Using event notifications using the Nylas Ruby SDK is fast and easy.
For more information, don’t forget to visit our Documentation page.
Blag aka Alvaro Tejada Galindo is a Senior Developer Advocate at Nylas. He loves learning about programming and sharing knowledge with the community. When he’s not coding, he’s spending time with his wife, daughter and son. He loves Punk Music and reading all sorts of books.