Master Notifications With ChatGPT, React and NodeJS 🧨
In this tutorial, you'll learn how to build a web application that allows you to send notifications generated by ChatGPT to your users, using React and NodeJS.

Intro
I have built many products in my life.In all of them I had to send notifications to the user in some form.
It could be a “Welcome Email” or informing the users they haven’t paid their last invoice 😅
But one thing was sure. I am a programmer, not a copywriter.So how do I come up with the right message for my notifications?

I was playing with GPT+3, more than a year ago, the results were nice, but not something I could use in production with automation.
But ChatGPT changed the game.
What is ChatGPT?
ChatGPT is an AI language model trained by OpenAI to generate text and interact with users in a human-like conversational manner. It is worth mentioning that ChatGPT is free and open to public use.
Users can submit requests and get information or answers to questions from a wide range of topics such as history, science, mathematics, and current events in just a few seconds.
ChatGPT performs other tasks, such as proofreading, paraphrasing, and translation. It can also help with writing, debugging, and explaining code snippets. Its wide range of capabilities is the reason why ChatGPT has been trending.
The main problem is that it’s not yet available to use with an API.
But that won’t stop us 😈
Novu – the first open-source notification infrastructure
Just a quick background about us. Novu is the first open-source notification infrastructure. We basically help to manage all the product notifications. It can be In-App (the bell icon like you have in Facebook – Websockets), Emails, SMSs and so on.

I would be super happy if you could give us a star! And let me also know in the comments ❤️ https://github.com/novuhq/novu
Limitation with ChatGPT
As I mentioned before, ChatGPT is not available as a public API.So, to use it, we have to scrape our way in.It means we will perform a full browser automation where we log in to the OpenAI website, solve their captcha (for that, you can use 2captcha), and send an API request with the OpenAI cookies.
Fortunately, somebody already built a public library that can do all of that here.
FYI this is not an API, and you will hit a hard limitation if you try to make many requests, and of course, you won’t be able to use it for live requests.
If you want to use it, use a queue and do background processing. If you want to know how to do it, write me in the comments, and I will write another article about it.
Project Set up
Here, I’ll guide you through creating the project environment for the web application. We’ll use React.js for the front end and Node.js for the backend server.
Create the project folder for the web application by running the code below:
Setting up the Node.js server
Navigate into the server folder and create a package.json file.
Install Express, Nodemon, and the CORS library.
ExpressJS is a fast, minimalist framework that provides several features for building web applications in Node.js, CORS is a Node.js package that allows communication between different domains, and Nodemon is a Node.js tool that automatically restarts the server after detecting file changes.
Create an index.js file – the entry point to the web server.
Set up a Node.js server using Express.js. The code snippet below returns a JSON object when you visit the http://localhost:4000/api in your browser.
Install the ChatGPT API library and Puppeteer. The ChatGPT API uses Puppeteer as an optional peer dependency to automate bypassing the Cloudflare protections.
To use the ChatGPT API within the server/index.js, you need to configure the file to use both the require and import keywords for importing libraries.
Therefore, update the server/package.json to contain the type keyword.
Add the code snippet below at the top of the server/index.js file.
Once you have completed the last two steps, you can now use ChatGPT within the index.js file.
Configure Nodemon by adding the start command to the list of scripts in the package.json file. The code snippet below starts the server using Nodemon.
Congratulations! You can now start the server by using the command below.
Setting up the React application
Navigate into the client folder via your terminal and create a new React.js project.
Install React Router – a JavaScript library that enables us to navigate between pages in a React application.
Delete the redundant files, such as the logo and the test files from the React app, and update the App.js file to display “Hello World” as below.
Navigate into the src/index.css file and copy the code below. It contains all the CSS required for styling this project.
Update the App.js file to render a Home component as below:
From the code snippet above, I imported the Home component. Create a components folder containing the Home.js file as done below:
Copy the code snippet below into the Home.js file:
How to add Novu to a React and Node.js application
We will be using Novu to send In-App notifications, but if you want to build your on in-app notifications, feel free to skip this step.
Adding Novu to a React application
Create a Novu project by running the code below within the client folder.
You will need to sign in with Github before creating a Novu project. The code snippet below contains the steps you should follow after running npx novu init.
Visit the demo web page http://localhost:52685/demo, copy your subscriber ID from the page, and click the Skip Tutorial button. We’ll be using it later in this tutorial.
Install Novu Notification package as a dependency in your React project.
Update the components/Home.js file to contain Novu and its required elements from the documentation.
The code snippet above adds Novu’s notification bell icon to the navigation bar, enabling us to view all the app notifications.
The NovuProvider component requires your Subscriber ID – copied earlier from http://localhost:52685/demo and your application ID available in the Settings section under API Keys on the Novu Manage Platform.
Next, let’s create the notification workflow and template for the application.
Open the Novu Manage Platform in your browser and create a notification template.
Select the template, click on Workflow Editor, and ensure the workflow is as below:
Click on the In-App step and edit the template to contain a message variable, as done below. The message variable will contain the notifications generated by ChatGPT.
Save the template by clicking Update button.
Adding Novu to a Node.js application
Navigate into the server folder and install the Novu SDK for Node.js.
Import Novu from the package and create an instance using your API Key.
Congratulations! You’ve successfully added Novu to your web application. In the upcoming section, you’ll learn how to send AI-generated notifications to your users via Novu.
How to send ChatGPT notifications to your users via Novu
In this section, I’ll guide you through generating notifications from ChatGPT for different use cases and sending them to your Novu subscribers.The application will allow you to specify the type of notification you want and select a subscriber that will receive the message.We’ve created a form field within the Home.js. Next, let’s fetch the list of subscribers and display them within the component.
Getting and displaying your Novu subscribers
Add a route within the index.js file that gets the list of subscribers from Novu.
Create a function that sends a request to the /subscribers endpoint and displays the subscribers on page load within the React application.
Update the select tag within the Home component to render the list of subscribers as below:
Generating the notifications from ChatGPT
Create a route within index.js that accepts the notification title and subscriber from the user.
Next, let’s submit the form details to the /notify route on the server. Create a function that makes a POST request to the endpoint when the form is submitted.
Update the /notify route to pass the necessary variables into another function.
Create the chatgptFunction as done below:
Finally, let’s send the notification to the subscriber via the ID. Create another function that accepts the notificationString and subscriberId and sends the notification.
Congratulations!🎉 You’ve completed the project for this tutorial.
Conclusion
So far, we have covered
- what ChatGPT is,
- how to communicate with it in a Node.js application, and
- how to send ChatGPT-generated notifications to users via Novu in a React and Node.js application.
This tutorial walks you through an example of an application you can build using Novu and ChatGPT. ChatGPT can be seen as the ultimate personal assistant, very useful in various fields to enable us to work smarter and better.
The source code for this tutorial is available here: https://github.com/novuhq/blog/tree/main/sending-chatgpt-notifications-with-novu
Thank you for reading!
Help me out!
If you feel like this article helped you understand WebSockets better! I would be super happy if you could give us a star! And let me also know in the comments ❤️ https://github.com/novuhq/novu