@entrig/capacitor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntrigCapacitor.podspec +18 -0
- package/Package.swift +29 -0
- package/README.md +448 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/entrig/plugin/capacitor/EntrigPlugin.kt +176 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/bin/setup.js +291 -0
- package/dist/docs.json +240 -0
- package/dist/esm/definitions.d.ts +26 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +20 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +34 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +37 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/EntrigPlugin/EntrigPlugin.swift +169 -0
- package/ios/Tests/EntrigPluginTests/EntrigTests.swift +15 -0
- package/package.json +84 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'EntrigCapacitor'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.dependency 'EntrigSDK', '0.0.8-dev'
|
|
17
|
+
s.swift_version = '5.9'
|
|
18
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "EntrigCapacitor",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "EntrigCapacitor",
|
|
10
|
+
targets: ["EntrigPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "EntrigPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
21
|
+
.product(name: "Entrig", package: "entrig-ios")
|
|
22
|
+
],
|
|
23
|
+
path: "ios/Sources/EntrigPlugin"),
|
|
24
|
+
.testTarget(
|
|
25
|
+
name: "EntrigPluginTests",
|
|
26
|
+
dependencies: ["EntrigPlugin"],
|
|
27
|
+
path: "ios/Tests/EntrigPluginTests")
|
|
28
|
+
]
|
|
29
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
# Entrig
|
|
2
|
+
|
|
3
|
+
**Push Notifications for Supabase**
|
|
4
|
+
|
|
5
|
+
Send push notifications to your Capacitor app, triggered by database events.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
1. **Create Entrig Account** - Sign up at [entrig.com](https://entrig.com?ref=npm)
|
|
13
|
+
|
|
14
|
+
2. **Connect Supabase** - Authorize Entrig to access your Supabase project
|
|
15
|
+
|
|
16
|
+
<details>
|
|
17
|
+
<summary>How it works (click to expand)</summary>
|
|
18
|
+
|
|
19
|
+
During onboarding, you'll:
|
|
20
|
+
1. Click the "Connect Supabase" button
|
|
21
|
+
2. Sign in to your Supabase account (if not already signed in)
|
|
22
|
+
3. Authorize Entrig to access your project
|
|
23
|
+
4. Select which project to use (if you have multiple)
|
|
24
|
+
|
|
25
|
+
That's it! Entrig will automatically set up everything needed to send notifications. No manual SQL or configuration required.
|
|
26
|
+
|
|
27
|
+
</details>
|
|
28
|
+
|
|
29
|
+
3. **Upload FCM Service Account** (Android) - Upload Service Account JSON and provide your Application ID
|
|
30
|
+
|
|
31
|
+
<details>
|
|
32
|
+
<summary>How to get FCM Service Account JSON (click to expand)</summary>
|
|
33
|
+
|
|
34
|
+
1. Create a Firebase project at [console.firebase.google.com](https://console.firebase.google.com)
|
|
35
|
+
2. Add your Android app to the project
|
|
36
|
+
3. Go to Project Settings → Service Accounts
|
|
37
|
+
4. Click "Firebase Admin SDK"
|
|
38
|
+
5. Click "Generate new private key"
|
|
39
|
+
6. Download the JSON file
|
|
40
|
+
7. Upload this file to the Entrig dashboard
|
|
41
|
+
|
|
42
|
+
</details>
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>What is Application ID? (click to expand)</summary>
|
|
46
|
+
|
|
47
|
+
The Application ID is your Android app's package name (e.g., `com.example.myapp`). You can find it in:
|
|
48
|
+
- Your `android/app/build.gradle` file under `applicationId`
|
|
49
|
+
- Or in your `AndroidManifest.xml` under the `package` attribute
|
|
50
|
+
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
> **Note:** If you've configured iOS in your Firebase console, you can use FCM for both Android and iOS, which will skip the APNs setup step.
|
|
54
|
+
|
|
55
|
+
4. **Upload APNs Key** (iOS) - Upload `.p8` key file with Team ID, Bundle ID, and Key ID to Entrig
|
|
56
|
+
|
|
57
|
+
<details>
|
|
58
|
+
<summary>How to get APNs Authentication Key (click to expand)</summary>
|
|
59
|
+
|
|
60
|
+
1. Enroll in [Apple Developer Program](https://developer.apple.com/programs/)
|
|
61
|
+
2. Go to [Certificates, Identifiers & Profiles](https://developer.apple.com/account/resources)
|
|
62
|
+
3. Navigate to Keys → Click "+" to create a new key
|
|
63
|
+
4. Enter a key name and enable "Apple Push Notifications service (APNs)"
|
|
64
|
+
5. Click "Continue" then "Register"
|
|
65
|
+
6. Download the `.p8` key file (you can only download this once!)
|
|
66
|
+
7. Note your **Key ID** (shown on the confirmation page - 10 alphanumeric characters)
|
|
67
|
+
8. Note your **Team ID** (found in Membership section of your Apple Developer account - 10 alphanumeric characters)
|
|
68
|
+
9. Note your **Bundle ID** (found in your Xcode project settings or `Info.plist` - reverse domain format like `com.example.app`)
|
|
69
|
+
10. Upload the `.p8` file along with Team ID, Bundle ID, and Key ID to the Entrig dashboard
|
|
70
|
+
|
|
71
|
+
</details>
|
|
72
|
+
|
|
73
|
+
<details>
|
|
74
|
+
<summary>Production vs Sandbox environments (click to expand)</summary>
|
|
75
|
+
|
|
76
|
+
Entrig supports configuring both APNs environments:
|
|
77
|
+
- **Production**: For App Store releases and TestFlight builds
|
|
78
|
+
- **Sandbox**: For development builds via Xcode
|
|
79
|
+
|
|
80
|
+
You can configure one or both environments during onboarding. Developers typically need Sandbox for testing and Production for live releases. You can use the same APNs key for both environments, but you'll need to provide the configuration separately for each.
|
|
81
|
+
|
|
82
|
+
</details>
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm install @entrig/capacitor
|
|
90
|
+
npx cap sync
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Platform Setup
|
|
96
|
+
|
|
97
|
+
### Android
|
|
98
|
+
|
|
99
|
+
No setup required for Android. We'll take care of it.
|
|
100
|
+
|
|
101
|
+
### iOS
|
|
102
|
+
|
|
103
|
+
#### Automatic Setup (Recommended)
|
|
104
|
+
|
|
105
|
+
Run this command in your project root:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx @entrig/capacitor setup ios
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This automatically configures:
|
|
112
|
+
- AppDelegate.swift with push notification token handlers
|
|
113
|
+
- App.entitlements with push notification entitlements (and links it in Xcode project)
|
|
114
|
+
- Info.plist with background modes
|
|
115
|
+
|
|
116
|
+
> **Note:** The command creates `.backup` files for safety. You can delete them after verifying everything works.
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>Troubleshooting pod install issues (click to expand)</summary>
|
|
120
|
+
|
|
121
|
+
If you encounter CocoaPods dependency errors, try cleaning and updating:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
cd ios
|
|
125
|
+
rm Podfile.lock
|
|
126
|
+
rm -rf Pods
|
|
127
|
+
pod deintegrate
|
|
128
|
+
pod repo update
|
|
129
|
+
pod install
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
</details>
|
|
133
|
+
|
|
134
|
+
<details>
|
|
135
|
+
<summary>Notification Service Extension (Optional - for Delivery Tracking)</summary>
|
|
136
|
+
|
|
137
|
+
The Notification Service Extension enables delivery status tracking even when your app is killed or in the background.
|
|
138
|
+
|
|
139
|
+
#### 1. Create Notification Service Extension in Xcode
|
|
140
|
+
|
|
141
|
+
1. Open `ios/App/App.xcworkspace`
|
|
142
|
+
2. File → New → Target → Notification Service Extension
|
|
143
|
+
3. Product Name: `NotificationService`, Language: Swift
|
|
144
|
+
4. Click "Cancel" when asked to activate scheme
|
|
145
|
+
|
|
146
|
+
#### 2. Update NotificationService.swift
|
|
147
|
+
|
|
148
|
+
```swift
|
|
149
|
+
import UserNotifications
|
|
150
|
+
import EntrigSDK
|
|
151
|
+
|
|
152
|
+
class NotificationService: UNNotificationServiceExtension {
|
|
153
|
+
|
|
154
|
+
var contentHandler: ((UNNotificationContent) -> Void)?
|
|
155
|
+
var bestAttemptContent: UNMutableNotificationContent?
|
|
156
|
+
|
|
157
|
+
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
|
158
|
+
self.contentHandler = contentHandler
|
|
159
|
+
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
|
|
160
|
+
|
|
161
|
+
// Report delivered status to Entrig
|
|
162
|
+
let apiKey = "YOUR_ENTRIG_API_KEY"
|
|
163
|
+
Entrig.reportDelivered(request: request, apiKey: apiKey)
|
|
164
|
+
|
|
165
|
+
if let bestAttemptContent = bestAttemptContent {
|
|
166
|
+
contentHandler(bestAttemptContent)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
override func serviceExtensionTimeWillExpire() {
|
|
171
|
+
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
|
|
172
|
+
contentHandler(bestAttemptContent)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### 3. Link EntrigSDK framework to the extension target
|
|
179
|
+
|
|
180
|
+
In Build Settings for the NotificationService target, ensure the EntrigSDK pod/framework is linked.
|
|
181
|
+
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
<details>
|
|
185
|
+
<summary>Manual AppDelegate setup (click to expand)</summary>
|
|
186
|
+
|
|
187
|
+
#### 1. Enable Push Notifications in Xcode
|
|
188
|
+
|
|
189
|
+
- Open `ios/App/App.xcworkspace`
|
|
190
|
+
- Select App target → Signing & Capabilities
|
|
191
|
+
- Click `+ Capability` → Push Notifications
|
|
192
|
+
- Click `+ Capability` → Background Modes → Enable `Remote notifications`
|
|
193
|
+
|
|
194
|
+
#### 2. Update AppDelegate.swift
|
|
195
|
+
|
|
196
|
+
Add the following methods to your `AppDelegate` class:
|
|
197
|
+
|
|
198
|
+
```swift
|
|
199
|
+
func application(_ application: UIApplication,
|
|
200
|
+
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
201
|
+
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
func application(_ application: UIApplication,
|
|
205
|
+
didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
206
|
+
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
</details>
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Usage
|
|
216
|
+
|
|
217
|
+
### Initialize
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { Entrig } from '@entrig/capacitor';
|
|
221
|
+
|
|
222
|
+
// Initialize Entrig
|
|
223
|
+
await Entrig.init({ apiKey: 'YOUR_ENTRIG_API_KEY' });
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
<details>
|
|
227
|
+
<summary>How to get your Entrig API key (click to expand)</summary>
|
|
228
|
+
|
|
229
|
+
1. Sign in to your Entrig account at [entrig.com](https://entrig.com)
|
|
230
|
+
2. Go to your dashboard
|
|
231
|
+
3. Navigate to your project settings
|
|
232
|
+
4. Copy your **API Key** from the project settings page
|
|
233
|
+
5. Use this API key in the `Entrig.init()` call above
|
|
234
|
+
|
|
235
|
+
</details>
|
|
236
|
+
|
|
237
|
+
### Register
|
|
238
|
+
|
|
239
|
+
Register the device when the user signs in:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
await Entrig.register({ userId: 'user-id' });
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
> **Note:** `register()` automatically handles notification permission requests. The `userId` you pass here must match the user identifier field you select when creating notifications in the Entrig dashboard.
|
|
246
|
+
|
|
247
|
+
Unregister when the user signs out:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
await Entrig.unregister();
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**Example with Supabase Auth:**
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { Entrig } from '@entrig/capacitor';
|
|
257
|
+
import { createClient } from '@supabase/supabase-js';
|
|
258
|
+
|
|
259
|
+
const supabase = createClient('YOUR_SUPABASE_URL', 'YOUR_SUPABASE_ANON_KEY');
|
|
260
|
+
|
|
261
|
+
// Initialize Entrig
|
|
262
|
+
await Entrig.init({ apiKey: 'YOUR_ENTRIG_API_KEY' });
|
|
263
|
+
|
|
264
|
+
// Register/unregister on auth state changes
|
|
265
|
+
supabase.auth.onAuthStateChange(async (event, session) => {
|
|
266
|
+
if (event === 'SIGNED_IN' && session?.user) {
|
|
267
|
+
await Entrig.register({ userId: session.user.id });
|
|
268
|
+
} else if (event === 'SIGNED_OUT') {
|
|
269
|
+
await Entrig.unregister();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
> **Important:** When using Supabase Auth, devices are registered with the **Supabase Auth user ID** (`auth.users.id`). When creating notifications, make sure the user identifier field you select contains this same Supabase Auth user ID to ensure notifications are delivered to the correct users.
|
|
275
|
+
|
|
276
|
+
<details>
|
|
277
|
+
<summary>Custom Permission Handling (click to expand)</summary>
|
|
278
|
+
|
|
279
|
+
If you want to handle notification permissions yourself, disable automatic permission handling:
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
await Entrig.init({
|
|
283
|
+
apiKey: 'YOUR_ENTRIG_API_KEY',
|
|
284
|
+
handlePermission: false,
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Then request permissions manually before registering:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
const { granted } = await Entrig.requestPermission();
|
|
292
|
+
if (granted) {
|
|
293
|
+
await Entrig.register({ userId: 'user-id' });
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
</details>
|
|
298
|
+
|
|
299
|
+
### Listen to Notifications
|
|
300
|
+
|
|
301
|
+
**Foreground notifications** (when app is open):
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
Entrig.addListener('onForegroundNotification', (event) => {
|
|
305
|
+
// Handle notification received while app is in foreground
|
|
306
|
+
// Access: event.title, event.body, event.type, event.data
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Notification tap** (when user taps a notification):
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
Entrig.addListener('onNotificationOpened', (event) => {
|
|
314
|
+
// Handle notification tap - navigate to specific screen based on event.type or event.data
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**NotificationEvent** contains:
|
|
319
|
+
- `title` - Notification title
|
|
320
|
+
- `body` - Notification body text
|
|
321
|
+
- `type` - Optional custom type identifier (e.g., `"new_message"`, `"order_update"`)
|
|
322
|
+
- `data` - Optional custom payload data from your database
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Creating Notifications
|
|
327
|
+
|
|
328
|
+
<details>
|
|
329
|
+
<summary>Learn how to create notification triggers in the dashboard (click to expand)</summary>
|
|
330
|
+
|
|
331
|
+
Create notification triggers in the Entrig dashboard. The notification creation form has two sections: configuring the trigger and composing the notification message.
|
|
332
|
+
|
|
333
|
+
### Section 1: Configure Trigger
|
|
334
|
+
|
|
335
|
+
Set up when and to whom notifications should be sent.
|
|
336
|
+
|
|
337
|
+
#### 1. Select Table
|
|
338
|
+
Choose the database table where events will trigger notifications (e.g., `messages`, `orders`). This is the "trigger table" that activates the notification.
|
|
339
|
+
|
|
340
|
+
#### 2. Select Event
|
|
341
|
+
Choose which database operation triggers the notification:
|
|
342
|
+
- **INSERT** - When new rows are created
|
|
343
|
+
- **UPDATE** - When existing rows are modified
|
|
344
|
+
- **DELETE** - When rows are deleted
|
|
345
|
+
|
|
346
|
+
#### 3. Select User Identifier
|
|
347
|
+
Specify how to identify notification recipients. Toggle "Use join table" to switch between modes.
|
|
348
|
+
|
|
349
|
+
> **Important:** The user identifier field you select here must contain the same user ID that was used when registering the device.
|
|
350
|
+
|
|
351
|
+
**Single User Mode** (Default):
|
|
352
|
+
- Select a field that contains the user ID directly
|
|
353
|
+
- Supports foreign key navigation (e.g., navigate through `orders.customer_id` to reach `customers.user_id`)
|
|
354
|
+
- Example: For a `messages` table with `user_id` field, select `user_id`
|
|
355
|
+
- The selected field should contain the same user ID used during device registration
|
|
356
|
+
|
|
357
|
+
**Multi-User Mode** (Join Table):
|
|
358
|
+
- Use when one database event should notify multiple users
|
|
359
|
+
- Requires configuring the relationship between tables:
|
|
360
|
+
|
|
361
|
+
**Event Table Section:**
|
|
362
|
+
- **Lookup Field**: Select a foreign key field that links to your join table
|
|
363
|
+
- Example: For notifying all room members when a message is sent, select `room_id` from the `messages` table
|
|
364
|
+
|
|
365
|
+
**Join Table Section:**
|
|
366
|
+
- **Join Table**: Select the table containing recipient records
|
|
367
|
+
- Example: `room_members` table that links rooms to users
|
|
368
|
+
- **Matching Field**: Field in the join table that matches your lookup field
|
|
369
|
+
- Usually auto-populated to match the lookup field name
|
|
370
|
+
- Example: `room_id` in `room_members`
|
|
371
|
+
- **User ID Field**: Field containing the actual user identifiers
|
|
372
|
+
- Supports foreign key navigation
|
|
373
|
+
- Example: `user_id` in `room_members`
|
|
374
|
+
- Should contain the same user ID used during device registration (e.g., Supabase Auth user ID)
|
|
375
|
+
|
|
376
|
+
#### 4. Event Conditions (Optional)
|
|
377
|
+
Filter when notifications are sent based on the trigger event data:
|
|
378
|
+
- Add conditions to control notification sending (e.g., only when `status = 'completed'`)
|
|
379
|
+
- Supports multiple conditions with AND/OR logic
|
|
380
|
+
- Conditions check the row data from the trigger table
|
|
381
|
+
|
|
382
|
+
#### 5. Recipient Filters (Optional, Multi-User only)
|
|
383
|
+
Filter which users receive the notification based on join table data:
|
|
384
|
+
- Example: Only notify users where `role = 'admin'` in the join table
|
|
385
|
+
- Different from Event Conditions - these filter recipients, not events
|
|
386
|
+
|
|
387
|
+
### Section 2: Compose Notification
|
|
388
|
+
|
|
389
|
+
Design the notification content that users will see.
|
|
390
|
+
|
|
391
|
+
#### 1. Notification Type (Optional)
|
|
392
|
+
Add a custom type identifier for your app to recognize this notification:
|
|
393
|
+
- Example values: `new_message`, `order_update`, `friend_request`
|
|
394
|
+
- Access via `event.type` in your notification listeners
|
|
395
|
+
- Use to route users to different screens or handle notifications differently
|
|
396
|
+
|
|
397
|
+
#### 2. Payload Data (Optional)
|
|
398
|
+
Select database fields to use as dynamic placeholders:
|
|
399
|
+
- Click "Add Fields" to open the field selector
|
|
400
|
+
- Selected fields appear as clickable pills (e.g., `{{messages.content}}`)
|
|
401
|
+
- Click any pill to insert it at your cursor position in title or body
|
|
402
|
+
- Supports nested field selection through foreign keys
|
|
403
|
+
|
|
404
|
+
#### 3. Title & Body
|
|
405
|
+
Write your notification text using placeholders:
|
|
406
|
+
- Use double-brace format: `{{table.column}}`
|
|
407
|
+
- Example Title: `New message from {{users.name}}`
|
|
408
|
+
- Example Body: `{{messages.content}}`
|
|
409
|
+
- Placeholders are replaced with actual data when notifications are sent
|
|
410
|
+
- Title appears as the notification headline
|
|
411
|
+
- Body appears as the notification message
|
|
412
|
+
|
|
413
|
+
### What Happens Behind the Scenes
|
|
414
|
+
|
|
415
|
+
When you create a notification, Entrig automatically:
|
|
416
|
+
1. Enables `pg_net` extension in your Supabase project
|
|
417
|
+
2. Creates a PostgreSQL function to send HTTP requests to Entrig
|
|
418
|
+
3. Sets up a database trigger on your selected table
|
|
419
|
+
4. Configures webhook endpoint for your notification
|
|
420
|
+
|
|
421
|
+
No manual SQL or backend code required!
|
|
422
|
+
|
|
423
|
+
### Example Use Cases
|
|
424
|
+
|
|
425
|
+
**Single User Notification:**
|
|
426
|
+
- **Table**: `orders`, **Event**: `INSERT`
|
|
427
|
+
- **User ID**: `customer_id`
|
|
428
|
+
- **Title**: `Order Confirmed!`
|
|
429
|
+
- **Body**: `Your order #{{orders.id}} has been received`
|
|
430
|
+
|
|
431
|
+
**Multi-User Notification (Group Chat):**
|
|
432
|
+
- **Table**: `messages`, **Event**: `INSERT`
|
|
433
|
+
- **Lookup Field**: `room_id`
|
|
434
|
+
- **Join Table**: `room_members`
|
|
435
|
+
- **Matching Field in Join Table**: `room_id`
|
|
436
|
+
- **User ID**: `user_id`
|
|
437
|
+
- **Title**: `New message in {{messages.room_name}}`
|
|
438
|
+
- **Body**: `{{messages.sender_name}}: {{messages.content}}`
|
|
439
|
+
|
|
440
|
+
</details>
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## Support
|
|
445
|
+
|
|
446
|
+
- Email: team@entrig.com
|
|
447
|
+
|
|
448
|
+
---
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.8.1'
|
|
15
|
+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply plugin: 'com.android.library'
|
|
20
|
+
apply plugin: 'kotlin-android'
|
|
21
|
+
|
|
22
|
+
android {
|
|
23
|
+
namespace = "com.entrig.plugin.capacitor"
|
|
24
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
25
|
+
defaultConfig {
|
|
26
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
27
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
28
|
+
versionCode 1
|
|
29
|
+
versionName "1.0"
|
|
30
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
31
|
+
}
|
|
32
|
+
buildTypes {
|
|
33
|
+
release {
|
|
34
|
+
minifyEnabled false
|
|
35
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
lintOptions {
|
|
39
|
+
abortOnError = false
|
|
40
|
+
}
|
|
41
|
+
compileOptions {
|
|
42
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
43
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
repositories {
|
|
48
|
+
google()
|
|
49
|
+
mavenCentral()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
dependencies {
|
|
54
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
55
|
+
implementation project(':capacitor-android')
|
|
56
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
57
|
+
api 'com.entrig:entrig:0.0.10-dev'
|
|
58
|
+
testImplementation "junit:junit:$junitVersion"
|
|
59
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
61
|
+
}
|