Project Overview
To enhance the efficiency of a bustling kitchen environment, I implemented a real-time notification system for incoming WooCommerce orders. The aim was to instantly inform chefs of new orders via OneSignal push notifications, all orchestrated through a seamless integration with the Kasera API.This project underscores a meticulous application of modern web technologies to solve a practical business challenge, emphasizing real-time communication, dependable architecture, and improved service delivery in the food industry.
Architecture
- WooCommerce: Triggers order events and dispatches Webhook notifications to Hookdeck.
- Hookdeck: Serves as a conduit for WooCommerce events, providing a robust platform for managing and monitoring webhook events, crucial for the real-time notifications system.
- Kasera Express.js: Acts as the operational core, processing Hookdeck's webhook notifications and interfacing with OneSignal to deliver push notifications to the chefs' devices while updating the Kasera dashboard.
- OneSignal: Responsible for the actual push notifications sent to chefs, prompted by the WooCommerce order events as relayed through Kasera Express.js.
Code Functionality:
Webhooks Endpoint Handler:
-
The Express.js router is configured to manage POST requests to the /woocommerce-webhooks-endpoint.
- Employs bodyParser.raw for the raw JSON data parsing from incoming requests.
- Verifies the presence of customer_id in the request body, utilizing the value to invoke the enviarNotificacionOneSignal function, thereby issuing a customized OneSignal notification.
- Logs and informs if the customer_id is missing from the Webhook data.
- Acknowledges the successful reception of the Webhook request from WooCommerce.
-
OneSignal Notification Dispatcher:
- Utilizes the axios library for HTTP POST requests and the dotenv library for environment variable management.
- Crafts HTTP headers for OneSignal authentication with API keys and application IDs.
- Constructs the notification payload with user identification and personalized messages.
- Handles successful OneSignal responses and potential errors, ensuring reliable delivery of notifications.
Operational Flow:
Upon an order placement on WooCommerce, the system instantly captures the event via a Webhook. Hookdeck receives and forwards this event to the Kasera API. The custom Express.js server processes the event, sending out real-time, targeted notifications to chefs through OneSignal. Chefs are promptly alerted on their devices, ensuring immediate attention to new orders.
Benefits & Impact:
- Efficiency: Chefs receive instant updates, reducing response time and increasing kitchen productivity.
- Reliability: The intermediate layers provide stability and comprehensive event tracking, facilitating smooth operational flow.
- Scalability: The modular architecture allows for easy expansion, such as integrating additional notification channels or supporting more complex order handling scenarios.
- User Experience: The direct communication loop significantly improves the overall service speed and quality for end customers.