recursive.codes


The Personal Blog of Todd Sharp

Sending Push Notifications from Oracle Notification Service with Oracle Functions and Pushover

Posted By: Todd Sharp on 4/6/2021 1:00 GMT
Tagged: Cloud, Cloud, JavaScript, JavaScript

The Oracle Notification Service is an extraordinary service. I’ve blogged about it in the past (see the Complete Guide to the Oracle Notification Service), but there’s one piece of the puzzle missing today: push notifications. I’m sure some day this will be rectified, but until then I decided to tackle the issue with a third-party solution. In this post, I’ll show you how to send push notifications to a mobile device from Oracle Notification Service via Oracle Functions and Pushover.

Before you get started, head over to Pushover and sign up for a free account. All set? Great, let’s get started!

Here's a quick table of contents for easy navigation:

Create Pushover App

The first step is to create an application on Pushover. When you’re logged in, scroll down to ‘Your Applications’ and click on ‘Create an Applciation/API Token’.

Give it a name and description (and an icon, if you want) and click ‘Create Application’.

Icon: Push Notification by Federica Sala from the Noun Project

Next, copy the new application’s API key and save it locally.

Now you’ll need to download and install the Pushover app on mobile.  You can find it in your favorite App Store. When you’ve installed it, you’ll receive a “user key”. Copy  this key to your local machine as well.

Create A Serverless Application

Now we’ll create a simple serverless application with Oracle Functions that will handle sending the push notification. Using the fn CLI, create a new application.

Before you get started, it's a good idea to always make sure you're running the latest version of the fn CLI. Check what the latest release is on GitHub, then check your version with:

If you're not running the latest, you can update with:

Or, download and install the latest binary from GitHub.

Create Application

Create Function

Right. Next, create a serverless function. I’m using Node.JS here for simplicity, but this code easily be a Java or Python app - whatever you’re comfortable with!

Set Application Config Vars

We need to set our Application and User keys into the serverless config so that we can access them from our function later on.

Populate Function

Before we edit the function, modify package.json to include the dependency on the pushover library.

Now edit func.js to send the notification.

Deploy the Function

Deploy the function with:

Testing the Function

Before we integrate with ONS, let’s test out the function invocation and make sure it sends the notification.

As you can see, I received a push notification on my mobile device.

Clicking on the notification takes me to a detailed view.

 

Heads Up! Pushover has a ton of support for various languages. Checkout the list of libraries available and use the one that matches your favorite language!

Create a Subscription in ONS

Now it’s just a matter of creating a subscription in ONS that will invoke the function when a message is received.

Click on ‘Publish Message’ to test it out.

The push notification will be received just as it was when we manually invoked the function!

Summary

In this post, we looked at how to send push notifications from Oracle Notification Service via Oracle Functions with Pushover. If you have any questions or would like to see something else covered here on the developer blog, leave a comment below!

If you'd like to learn more about notifications, check out the following links.

Image by mohamed Hassan from Pixabay 



Related Posts

Running Database Queries With REST via a Database Tools Connection (IE: The Super Easy Way)

Running Database Queries With REST via a Database Tools Connection (IE: The Super Easy Way)

I recently blogged about a brand-new service in the Oracle Cloud - Database Tools. It's a safe, secure way to store your database credentials in the...

Easy and Secure Oracle Database Connections With Database Tools

Easy and Secure Oracle Database Connections With Database Tools

There's a brand new tool in town, and it's ready to make your life a whole lot easier if you work with Oracle DB in the cloud. It's called "Database Tools...

Securely Connecting to Autonomous DB Without a Wallet (Using TLS)

Securely Connecting to Autonomous DB Without a Wallet (Using TLS)

I talk to a lot of developers in my job as a Developer Advocate. Sometimes they've been using the products in the Oracle Cloud for a long time, and sometimes...

Note: Comments are currently closed on this blog. Disqus is simply too bloated to justify its use with the low volume of comments on this blog. Please visit my contact page if you have something to say!