Most Popular
We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.
Sign up
Product notifications keep users engaged and informed about important updates related to web and mobile applications. However, building an effective notification system for your app that sends timely and personalized messages can be challenging. Courier's development platform for notifications simplifies this process by consolidating various communication APIs, data, and development tools in one place.
With Courier, you can create a best-in-class notification system that works across product features and use cases to send notifications over email, push, Slack, MS Teams, a notification center in your web or mobile app — or any other channel
In this article, we'll guide you through using Python and Courier to create an automated notification system that sends real-time updates to users. Note that we’ll just be looking at a simple use case for this tutorial. However, this will establish the foundation for a notification system that can be used for virtually any scenario. Some of the features available include:
pip install trycourier
. You can find additional documentation for the package by following the link above.To connect your Python application to your Courier account, you need API keys.
Courier provides a convenient feature that enables you to create and customize notification content for email, SMS, push notifications, and chat apps such as Slack and Microsoft Teams.
The process of designing a custom notification using Courier is simple, making it easier for you to tailor your messages according to your audience and communication needs.
First let’s look at an example of how to send a simple notification using Python and Courier.
Create a file named app.py
and add the following code. You can find the default code snippet for your notification in the Send tab of the Courier notification designer.
1from trycourier import Courier23client = Courier(auth_token="API KEY GOES HERE") # Replace with production API key45resp = client.send_message(6message={7"template": "QJAQ20TN9TM90QNRWNE7TN1NHF8J", # Replace with the actual notification ID8"to": {9"email":"someone@example.com" # Replace with the recipient email address10},11}12)
This code imports the Courier library, initializes the client with your API key, and sends a message using a specified template to a recipient's email address. Replace the API key, notification ID, and email address with your own values.
You can send notifications to multiple recipients simultaneously using Courier client profiles. First, you should go through the process from step 3 again, in order to create a second notification, as this demo sends two notifications with a delay in between.
1from trycourier import Courier23client = Courier(auth_token="API KEY GOES HERE") # Replace with production API key45resp = client.profiles.add(6"PROFILE_ID", # Add an ID that can be used to uniquely identify the recipient7{8"email": "someone@example.com", # Replace with the email address of the recipient9"name": "Someone Name" # Replace with the name of the recipient10}11)
This code creates a new client profile in Courier using the profiles.add
method. You need to provide a unique profile ID, email address, and name to create the profile. For this tutorial, you will need to do this two times, for two separate users. You can, if you prefer, easily add a user directly from the Courier dashboard.
Now let’s use the client profile's ID as a recipient when sending notifications.
1from trycourier import Courier23client = Courier(auth_token="API KEY GOES HERE") # Replace with production API key45resp = client.automations.invoke(6automation={7'steps': [8{9# This notification will be sent to the email address of "PROFILE_ID_1"10"action": "send",11"template": "QJAQ20TN9TM90QNRWNE7TN1NHF8J", # Replace with your 1st actual notification ID12"recipient": "PROFILE_ID_1", # Replace with your actual PROFILE_ID13},14{15"action": "delay",16"duration": "1 minute",17},18{19# This notification will be sent to the email address of "PROFILE_ID_2"20"action": "send",21"template": "X0G40J35NP4MS0GRWD67Q0CTBJA0", # Replace with your 2nd actual notification ID22"recipient": "PROFILE_ID_2", # Replace with your actual PROFILE_ID23},24],25},26)
This code demonstrates how to invoke an automation with multiple steps using Courier's automations.invoke
method. The steps include sending a notification to two different recipients with unique profile IDs, and a delay of 1 minute between the notifications.
Next, we're going to demonstrate how to schedule a notification to be sent periodically using Courier's in-built scheduling functionality. If you want to know more about Courier Automations, check out this post.
To setup a scheduled notification using Courier, you will have to use the Courier Automations platform. Here is how to do it. \ Open Courier Automations in your Courier account from the dashboard.
invoke
tab to invoke the most recent published version of the automation template. For example:1curl --request POST \2--url https://api.courier.com/automations/81d5fdde-6f35-4932-b3ff-8c31e1a2b223/invoke \3--header 'Accept: application/json' \4--header 'Authorization: Bearer <YOUR_API_KEY>' \5--header 'Content-Type: application/json' \6--data '{}'
This setup will automate your notification. The notification(s) will be sent according to the schedule you have configured within Courier Automations.
When the application runs, it sends a request to Courier containing all the necessary information about the notification, including the content, recipient email details, additional data, routing options, and message delay duration. Courier processes the request and routes the notification to the appropriate channel — in this case, email. And while we’re showing this over email, it’s just as easy using Courier Automations to build a workflow that sequences the notification to a web and mobile notification center, Slack or MS Teams DM, push notification, etc, based on delivery status and timing rules so that users are more likely to get the notification.
To check the status of a notification, visit the Courier Logs page. You'll see a list of all notifications sent from your account and can click on any one to view more details.
The Courier Logs page automatically updates with the notification status, allowing you to check whether the notification was sent or not. You can also see the time when the recipient opened the notification. Or look into error details of notifications that aren’t delivered so you can quickly debug.
In this article, we've walked you through the process of creating an automated notification system using Python and Courier, a powerful combination that can streamline communication within your organization and elevate the user experience for your customers.
By following the steps we've outlined, you'll be well-equipped to create a customized notification system that meets your unique requirements. To learn more about the notification features available, check out Courier for free today or contact us if you want to talk through your unique requirements.
We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.
Sign up
How to Set Up Automatic Push Notifications Based on Segment Events
Push notifications have carved their own niche as a powerful tool for continuous user engagement. Regardless of whether an app is actively in use, they deliver your messages straight to your user's device. Two key players that can combine to enhance your push notification strategy are Segment and Courier. In this tutorial, we show you how to set up Courier to listen to your Segment events and then send push notifications to an Android device based on data from these events.
Sarah Barber
November 17, 2023
How to Send Firebase Notifications to iOS Devices Using Courier
This tutorial explains how to send push notifications to iOS devices from your iOS application code using Firebase FCM and Courier’s iOS SDK.
Martina Caccamo
November 01, 2023
Free Tools
Comparison Guides
Send up to 10,000 notifications every month, for free.
Get started for free
Send up to 10,000 notifications every month, for free.
Get started for free
© 2024 Courier. All rights reserved.