Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The SDK provides access to Base44's functionality through the following modules:
- **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
- **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built server-side functions for external services.
- **[`mobile`](#mobile-native-features)**: Send push notifications and access mobile native capabilities.

## Example

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

## Mobile Native Features

The SDK provides mobile native capabilities through the `mobile` module, allowing you to send push notifications to your app users.

### Push Notifications

Send push notifications to users on mobile devices:

```typescript
import { base44 } from "@/api/base44Client";

// Send a push notification to a user
await base44.mobile.sendNotification({
userId: "user_123",
title: "New Message!",
content: "You have a new message from John",
actionLabel: "View Message",
actionUrl: "/messages/456",
channels: ["mobile_push"], // Mobile push only
});

// Send to both mobile push and in-app notifications (default)
await base44.mobile.sendNotification({
userId: "user_456",
title: "Order Shipped",
content: "Your order #12345 has been shipped and is on its way!",
actionLabel: "Track Order",
actionUrl: "/orders/12345",
});
```

### Notification Channels

The `mobile` module supports two notification channels:

- **`mobile_push`**: Sends a push notification to the user's mobile device (iOS/Android)
- **`in_app`**: Sends an in-app notification visible in the web interface

By default, notifications are sent to both channels. You can specify specific channels using the `channels` parameter:

```typescript
// Mobile push only - user will receive push notification on their phone
await base44.mobile.sendNotification({
userId: "user_123",
title: "Time-sensitive alert",
content: "Your session will expire in 5 minutes",
channels: ["mobile_push"],
});

// In-app only - notification visible only in the web interface
await base44.mobile.sendNotification({
userId: "user_789",
title: "System Update",
content: "We've updated the dashboard with new features",
channels: ["in_app"],
});
```

### Common Use Cases

**Order & Delivery Updates**:
```typescript
// Notify user when order is ready
await base44.mobile.sendNotification({
userId: order.userId,
title: "Order Ready for Pickup",
content: `Your order #${order.id} is ready at ${store.name}`,
actionLabel: "View Order",
actionUrl: `/orders/${order.id}`,
});
```

**Chat & Messaging**:
```typescript
// Notify user of new messages
await base44.mobile.sendNotification({
userId: recipient.id,
title: `New message from ${sender.name}`,
content: message.preview,
actionLabel: "Reply",
actionUrl: `/chats/${conversation.id}`,
channels: ["mobile_push"], // Mobile only, avoid duplicate with in-app chat
});
```

**Reminders & Events**:
```typescript
// Send event reminder
await base44.mobile.sendNotification({
userId: attendee.userId,
title: "Event Starting Soon",
content: `${event.name} starts in 30 minutes`,
actionLabel: "View Details",
actionUrl: `/events/${event.id}`,
});
```

### Error Handling

The notification API handles errors gracefully:

```typescript
try {
const result = await base44.mobile.sendNotification({
userId: "user_123",
title: "Test Notification",
content: "This is a test",
});

if (result.success) {
console.log("Notification sent successfully");
console.log("Notification ID:", result.notificationId);
}
} catch (error) {
if (error.status === 404) {
console.error("User not found");
} else if (error.status === 403) {
console.error("Not authorized to send notifications");
} else {
console.error("Failed to send notification:", error.message);
}
}
```

**Graceful Degradation**:
- If a user doesn't have mobile push enabled, the notification is still sent to other channels
- If one channel fails, other channels still receive the notification
- Notifications are queued and retried automatically for temporary failures

## Learn more

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