Skip to content

Commit cd6c3ea

Browse files
gdauber1claude
andcommitted
Add mobile module to Base44 SDK for push notifications
Implements mobile native capabilities in the SDK, allowing apps to send push notifications to users. This exposes the backend mobile API to LLM-generated apps through base44.mobile.sendNotification(). SDK changes: - Create mobile module with sendNotification() method - Add TypeScript types for mobile notifications - Add mobile module to Base44Client interface - Export mobile types from index.ts - Update README with mobile features documentation - Add comprehensive mobile notifications examples Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b0c509f commit cd6c3ea

File tree

7 files changed

+645
-0
lines changed

7 files changed

+645
-0
lines changed

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The SDK provides access to Base44's functionality through the following modules:
1313
- **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
1414
- **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
1515
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built server-side functions for external services.
16+
- **[`mobile`](#mobile-native-features)**: Send push notifications and access mobile native capabilities.
1617

1718
## Example
1819

@@ -37,6 +38,135 @@ await base44.entities.Task.update(newTask.id, {
3738
const tasks = await base44.entities.Task.list();
3839
```
3940

41+
## Mobile Native Features
42+
43+
The SDK provides mobile native capabilities through the `mobile` module, allowing you to send push notifications to your app users.
44+
45+
### Push Notifications
46+
47+
Send push notifications to users on mobile devices:
48+
49+
```typescript
50+
import { base44 } from "@/api/base44Client";
51+
52+
// Send a push notification to a user
53+
await base44.mobile.sendNotification({
54+
userId: "user_123",
55+
title: "New Message!",
56+
content: "You have a new message from John",
57+
actionLabel: "View Message",
58+
actionUrl: "/messages/456",
59+
channels: ["mobile_push"], // Mobile push only
60+
});
61+
62+
// Send to both mobile push and in-app notifications (default)
63+
await base44.mobile.sendNotification({
64+
userId: "user_456",
65+
title: "Order Shipped",
66+
content: "Your order #12345 has been shipped and is on its way!",
67+
actionLabel: "Track Order",
68+
actionUrl: "/orders/12345",
69+
});
70+
```
71+
72+
### Notification Channels
73+
74+
The `mobile` module supports two notification channels:
75+
76+
- **`mobile_push`**: Sends a push notification to the user's mobile device (iOS/Android)
77+
- **`in_app`**: Sends an in-app notification visible in the web interface
78+
79+
By default, notifications are sent to both channels. You can specify specific channels using the `channels` parameter:
80+
81+
```typescript
82+
// Mobile push only - user will receive push notification on their phone
83+
await base44.mobile.sendNotification({
84+
userId: "user_123",
85+
title: "Time-sensitive alert",
86+
content: "Your session will expire in 5 minutes",
87+
channels: ["mobile_push"],
88+
});
89+
90+
// In-app only - notification visible only in the web interface
91+
await base44.mobile.sendNotification({
92+
userId: "user_789",
93+
title: "System Update",
94+
content: "We've updated the dashboard with new features",
95+
channels: ["in_app"],
96+
});
97+
```
98+
99+
### Common Use Cases
100+
101+
**Order & Delivery Updates**:
102+
```typescript
103+
// Notify user when order is ready
104+
await base44.mobile.sendNotification({
105+
userId: order.userId,
106+
title: "Order Ready for Pickup",
107+
content: `Your order #${order.id} is ready at ${store.name}`,
108+
actionLabel: "View Order",
109+
actionUrl: `/orders/${order.id}`,
110+
});
111+
```
112+
113+
**Chat & Messaging**:
114+
```typescript
115+
// Notify user of new messages
116+
await base44.mobile.sendNotification({
117+
userId: recipient.id,
118+
title: `New message from ${sender.name}`,
119+
content: message.preview,
120+
actionLabel: "Reply",
121+
actionUrl: `/chats/${conversation.id}`,
122+
channels: ["mobile_push"], // Mobile only, avoid duplicate with in-app chat
123+
});
124+
```
125+
126+
**Reminders & Events**:
127+
```typescript
128+
// Send event reminder
129+
await base44.mobile.sendNotification({
130+
userId: attendee.userId,
131+
title: "Event Starting Soon",
132+
content: `${event.name} starts in 30 minutes`,
133+
actionLabel: "View Details",
134+
actionUrl: `/events/${event.id}`,
135+
});
136+
```
137+
138+
### Error Handling
139+
140+
The notification API handles errors gracefully:
141+
142+
```typescript
143+
try {
144+
const result = await base44.mobile.sendNotification({
145+
userId: "user_123",
146+
title: "Test Notification",
147+
content: "This is a test",
148+
});
149+
150+
if (result.success) {
151+
console.log("Notification sent successfully");
152+
console.log("Notification ID:", result.notificationId);
153+
}
154+
} catch (error) {
155+
if (error.status === 404) {
156+
console.error("User not found");
157+
} else if (error.status === 403) {
158+
console.error("Not authorized to send notifications");
159+
} else {
160+
console.error("Failed to send notification:", error.message);
161+
}
162+
}
163+
```
164+
165+
**Graceful Degradation**:
166+
- If a user doesn't have mobile push enabled, the notification is still sent to other channels
167+
- If one channel fails, other channels still receive the notification
168+
- Notifications are queued and retried automatically for temporary failures
169+
40170
## Learn more
41171

42172
For complete documentation, guides, and API reference, visit the **[Base44 SDK Documentation](https://docs.base44.com/sdk-getting-started/overview)**.

0 commit comments

Comments
 (0)