A developer tutorial application demonstrating how to integrate Shopify webhooks, the Hookdeck Event Gateway, and Ably to display real-time purchase notifications in a Shopify online store with festive animations.
This is an example/tutorial app that shows developers how to:
- Receive Shopify order webhooks reliably through the Hookdeck Event Gateway
- Process webhook events in a Remix-based Shopify app
- Forward events to Ably for real-time pub/sub messaging
- Display live notifications in a Shopify storefront using theme app extensions
- Create interactive UI elements with holiday-themed animations
Note: This is a demonstration app for learning purposes, not a production-ready application for merchants to install.
The complete data flow works as follows:
1. Order Created in Shopify
↓
2. Shopify triggers orders/create webhook
↓
3. Event Gateway receives and queues the webhook at the Source
↓
4. Event Gateway delivers webhook to app webhook handler
(app/routes/webhooks.orders.create.tsx)
↓
5. App processes event and publishes to Event Gateway queue
(app/helpers/webhooks.ts)
↓
6. Event Gateway queues and forwards event to Ably via REST API
↓
7. Ably broadcasts to all connected clients
↓
8. Storefront receives event via Ably Realtime
(extensions/live-notifications/assets/notifications.js)
↓
9. Notification displayed with snowflake animation
(extensions/live-notifications/blocks/notifications.liquid)
This project contains both a Shopify app and a theme app extension:
- Shopify App: The backend Remix application that handles webhooks, manages data, and provides an admin interface. It runs on a server and integrates with Shopify's Admin API.
- Theme App Extension: Frontend components that appear in the merchant's online store. Extensions add blocks, sections, or functionality directly to the storefront without modifying theme code.
app/routes/webhooks.orders.create.tsx- Webhook endpoint that receives order creation events from Shopify via the Event Gatewayapp/helpers/webhooks.ts- Helper functions for managing webhooks, including:- Publishing events to the Event Gateway queue
- Managing webhook subscriptions via Shopify Admin GraphQL API
- Note: Connection setup should be handled by a setup script (see Setup Instructions)
extensions/live-notifications/blocks/notifications.liquid- Theme app extension block with festive holiday lights and snowfall animationsextensions/live-notifications/assets/notifications.js- Client-side JavaScript that:- Connects to Ably Realtime
- Subscribes to notification events
- Creates snowflake animations
- Handles interactive elements (clickable lights and snowflakes)
extensions/live-notifications/src/notifications.scss- Source SCSS styles (compiled tonotifications.css)extensions/live-notifications/assets/notifications.css- Compiled CSS (generated from SCSS, not manually edited)
shopify.app.toml- Shopify app configuration including:- Webhook subscriptions for
orders/create - Required OAuth scopes (
read_products,read_orders) - App authentication settings
- Webhook subscriptions for
package.json- Dependencies including:@shopify/shopify-app-remix- Shopify app framework- Ably client library (loaded via CDN in storefront)
- Note: The
@hookdeck/sdkdependency is deprecated and should be removed
Before setting up this app, you'll need:
- Node.js (v18.20+, v20.10+, or v21.0.0+)
- Shopify Partner Account - Create one here
- Shopify Development Store - Create from your Partner Dashboard
- Hookdeck Account - Sign up at hookdeck.com for the Event Gateway
- Hookdeck CLI - Install globally with
npm install -g @hookdeck/cli - Ably Account - Sign up at ably.com
Create a .env file in the root directory with the following variables:
# Shopify App Credentials
SHOPIFY_API_KEY=your_shopify_api_key
SHOPIFY_API_SECRET=your_shopify_api_secret
# Hookdeck Configuration
HOOKDECK_API_KEY=your_hookdeck_api_key
# Ably Configuration
ABLY_API_KEY=your_ably_api_key
# Database
DATABASE_URL=file:./dev.sqliteHookdeck API Key:
- Log in to your Hookdeck Dashboard
- Navigate to Settings → API Keys
- Create or copy your API key
Ably API Key:
- Log in to your Ably Dashboard
- Navigate to your app → API Keys
- Create a new key or use the default root key
- Copy the full API key (format:
appId.keyId:keySecret)
Shopify Credentials:
- Created automatically when you run
npm run devfor the first time - Or manually create an app in your Partner Dashboard
git clone https://github.com/hookdeck/shopify-festive-notifications.git
cd shopify-festive-notifications
npm installThe Hookdeck CLI is required for this demo application to receive webhooks locally and will be used by the setup script.
-
Install Hookdeck CLI globally:
npm install -g @hookdeck/cli
-
Login to Hookdeck:
hookdeck login
This authenticates the CLI with your Hookdeck account.
npm run devThis will:
- Create a tunnel for local development (using Cloudflare)
- Prompt you to create/select a Shopify app
- Install the app on your development store
- Start the development server
Note on Tunneling:
- The Cloudflare tunnel created by
npm run devis required for Shopify to communicate with your local app (OAuth, app embeds, admin interface) - The Hookdeck CLI is used to receive webhooks locally and provides better debugging capabilities
- Both run simultaneously: Cloudflare tunnel for the app, Hookdeck CLI for webhooks
Benefits of Hookdeck CLI for webhooks:
- Real-time webhook inspection and debugging
- Replay webhooks during development
- Test different payloads easily
- View webhook history and errors
- No need to trigger real Shopify events repeatedly
Start the Hookdeck CLI to forward webhooks to your local server:
hookdeck listen 3000 shopify-webhooksThis creates a webhook URL that forwards to localhost:3000. Keep this terminal running.
Note: The setup script (to be created) will use the Hookdeck CLI to create Event Gateway connections.
Important: Event Gateway connections should be set up statically using a setup script, not dynamically created during app install/uninstall (as Shopify app install/uninstall callbacks can be unreliable).
Create connections in the Event Gateway for each shop:
- Source: Receives webhooks from Shopify
- Name:
{shopId}_order-created - URL: Will be the webhook endpoint from Shopify
- Name:
- Destination: Forwards to Ably REST API
- Name:
{shopId}_ably - URL:
https://rest.ably.io/channels/{shopId}/messages - Auth Method: Bearer token with your Ably API key
- Name:
TODO: Create a setup script (using Hookdeck CLI) to automate Event Gateway connection creation.
- Go to your Shopify admin → Online Store → Themes
- Click "Customize" on your active theme
- Navigate to any page in the theme editor
- Click "Add section" or "Add block"
- Look for "Festive Notifications" under App blocks
- Add it to your theme (typically in the theme layout or header)
- Save and publish
Edit extensions/live-notifications/assets/notifications.js and replace the hardcoded API key on line 45 with your Ably API key:
const ably = new Ably.Realtime("YOUR_ABLY_API_KEY");Note: In production, this should be handled more securely, potentially using token authentication.
TODO: Add detailed testing instructions including:
- Step-by-step guide to creating a test order
- How to verify webhook delivery in app logs (with expected log output)
- How to check Event Gateway dashboard for event processing
- How to open storefront and verify notification appears
- Troubleshooting common issues
- Shopify triggers webhook: When an order is created, Shopify sends an
orders/createwebhook to the Event Gateway Source - Event Gateway receives and queues: The Event Gateway reliably receives and queues the webhook with automatic retries
- App processes webhook: The Event Gateway delivers the webhook to
webhooks.orders.create.tsx, which processes the event - Event publication: The app publishes the processed event back to the Event Gateway queue (intended functionality - may not be fully implemented yet)
- Event Gateway forwarding: The Event Gateway queues and forwards the event to Ably's REST API
- Pub/Sub broadcast: Ably broadcasts the event to all subscribed clients
- Storefront receives: The JavaScript in
notifications.jsreceives the event via Ably Realtime - UI update: The notification is displayed with festive animations
The Shopify theme app extension consists of:
- Liquid template: Defines the HTML structure and holiday light animations
- JavaScript: Handles Ably connection, event subscriptions, and snowflake animations
- CSS: Compiled from SCSS, provides styling for animations and layout
npm run devThis starts:
- Remix development server
- Shopify CLI tunnel
- SASS compiler for extension styles
npm run buildnpm run deployThis deploys your app extensions to Shopify.
live-notifications/
├── app/
│ ├── routes/
│ │ ├── webhooks.orders.create.tsx # Order webhook handler
│ │ ├── app._index.tsx # App home page
│ │ └── ...
│ ├── helpers/
│ │ └── webhooks.ts # Hookdeck/webhook utilities
│ └── shopify.server.ts # Shopify app configuration
├── extensions/
│ └── live-notifications/
│ ├── blocks/
│ │ └── notifications.liquid # Theme block template
│ ├── assets/
│ │ ├── notifications.js # Client-side logic
│ │ └── notifications.css # Compiled styles
│ └── src/
│ └── notifications.scss # Source styles
├── prisma/
│ └── schema.prisma # Database schema
├── shopify.app.toml # App configuration
└── package.json # Dependencies
- Remix - Full-stack web framework
- Shopify App Remix - Shopify app framework for Remix
- Hookdeck Event Gateway - Webhook infrastructure for reliable delivery and event routing
- Ably - Real-time pub/sub messaging platform
- Prisma - Database ORM
- Shopify Theme App Extensions - Storefront integration
- Shopify App Development
- Shopify Webhooks
- Shopify Theme App Extensions
- Shopify Admin GraphQL API
- Hookdeck Event Gateway Documentation
- Ably Documentation
- Remix Documentation
- Shopify App Tutorial
- Webhooks Best Practices
- Theme App Extension Tutorial
- Hookdeck Event Gateway Guide
- Ably Realtime Guide
- Security: The Ably API key is currently hardcoded in the client-side JavaScript. For production, implement token authentication
- Error Handling: Basic error handling is implemented; production apps should include comprehensive error handling and monitoring
- Scalability: This demo uses a simple SQLite database; production apps should use PostgreSQL or MySQL
- Shop-specific channels: The current implementation creates shop-specific Ably channels to isolate events between stores
This is a demonstration/tutorial project for educational purposes.
leggetter
Questions or Issues? This is a tutorial app - refer to the official documentation links above for detailed guidance on each technology used.