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