- 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. Events notifications can become your best ally.
The Nylas Python SDK offers three ways of reminding people about important events by sending events notifications, and in this blog post, we’re going to review them one by one.
If you feel more comfortable using Ruby, we have you covered How to send notifications for calendar events using the Nylas Ruby SDK.
If you already have the Nylas Python 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 Python 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 a reminder is a great way to at least make sure that the participant will not forget about the event.
This is the most simple method that we can use to send an event reminder. So let’s grab our favorite code editor and create a file called EmailReminderEvent.py
Keep in mind that if we run this script after 8:30am it’s not going to work. Add a couple of hours to your current time before running it.
# Load your env variables from dotenv import load_dotenv load_dotenv() # Import your dependencies import os import datetime from datetime import date from nylas import APIClient # Initialize your Nylas API client nylas = APIClient( os.environ.get("CLIENT_ID"), os.environ.get("CLIENT_SECRET"), os.environ.get("ACCESS_TOKEN") ) # Get today’s date today = date.today() # Today’s date at 7:15:00 am _START = int(datetime.datetime(today.year, today.month, today.day, 7, 15, 0).strftime("%s")) # Today’s date at 8:30:00 am _END = int(datetime.datetime(today.year, today.month, today.day, 8, 30, 0).strftime("%s")) # Draft the event event = nylas.events.create() # Define the event characteristics event.title = "Let's learn some Nylas Python API!" event.location = "Blag's Den!" event.when = {"start_time": START_TIME, "end_time": END_TIME} event.participants = [{"name": "<YOUR_NAME>", 'email': os.environ.get("RECIPIENT_ADDRESS")}] # It’s imperative to define the Calendar Id event.calendar_id = os.environ.get("CALENDAR_ID") # Email Reminder #We can add a reminder notification to the event invitation itself that will be sent to all participants event.notifications = [{"body": "Heads up! The Nylas Python Workshop is starting in 10 minutes. See you there!", \ "minutes_before_event": 10, "subject": "Nylas Python Workshop starts soon", "type": "email"}] # Create the event and send an email notification event.save(notify_participants=True) if event.id: print("Event created successfully") else: print("There was an error creating the event")
We can execute this script from the terminal by typing:
$ python3 EmailReminderEvent.py
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 notifications for Slack and Microsoft Teams. We’re going to review how to do that for Slack.
First, we need to have a 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 Python script.
So, let’s create the script and call it WebhookReminderEvent.py
Keep in mind that if we run this script after 1:00pm it’s not going to work. Add a couple of hours to your current time before running it.
# Load your env variables from dotenv import load_dotenv load_dotenv() # Import your dependencies import os import json import datetime from datetime import date from nylas import APIClient # Initialize your Nylas API client nylas = APIClient( os.environ.get("CLIENT_ID"), os.environ.get("CLIENT_SECRET"), os.environ.get("ACCESS_TOKEN"), ) # Get today’s date today = date.today() # Today’s date at 12:30:00 pm START_TIME = int(datetime.datetime(today.year, today.month, today.day, 12, 30, 0).strftime('%s')) # Today’s date at 13:00:00 pm END_TIME = int(datetime.datetime(today.year, today.month, today.day, 13, 0, 0).strftime('%s')) # Create event draft event = nylas.events.create() # Define event elements event.title = "Let's learn some Nylas Python API!" event.location = "Blag's Den!" event.when = {"start_time": START_TIME, "end_time": END_TIME} event.participants = [{"name": "Blag", 'email': os.environ.get("RECIPIENT_ADDRESS")}] event.calendar_id = "<your_calendar_id>" # Create notification event.notifications = [{"type": "webhook", "minutes_before_event": 10, "url": "<your_slack_webhook>","payload": json.dumps({"text": "Workshop starts in 10 minutes!"})}] # We would like to notify participants event.save(notify_participants=True) if event.id: print("Event created successfully") else: print("There was an error creating the event")
We can run this script from the terminal by typing:
$ python3 WebhookReminderEvent.py
Ten minutes prior to the event, we will get a notification on Slack.
Using event notifications using the Nylas Python SDK is fast and easy.
You can sign up Nylas for free and start building!
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.