dnotifier 1.1.6
dnotifier: ^1.1.6 copied to clipboard
Real-time notification and messaging SDK for Dart and Flutter. Use in Flutter (Android, iOS, Web) or pure Dart. WebSocket & HTTP, auth, binary frames, and optional AI integration. No platform-specific [...]
DNotifier Dart SDK #
DNotifier is a real-time notification & messaging SDK for Dart and Flutter, supporting Android and iOS. It provides WebSocket and HTTP transports, binary streaming, and framed packet communication.
Features #
- WebSocket & HTTP transport support
- Secure authentication handshake
- Real-time messaging (send/receive text and binary)
- Binary data transfer (files, images, media)
- AI pipeline: send messages to AI (
sendAI), fetch AI history (fetchAIHistory), semantic search (search) - RAG / Knowledge Base APIs: add, update, get, list, delete, search documents
- Plan limits from auth (
getPlanLimits) - Automatic packet framing & decoding
- Handles partial packets & large payloads
- Flutter-ready: works in Flutter (Android, iOS, Web) and pure Dart; no platform-specific code in the SDK
Installation #
Add to your pubspec.yaml:
dependencies:
dnotifier:
path: . # or git: https://github.com/...
Or publish the package and use:
dependencies:
dnotifier: ^1.0.0
Then run:
# In a Dart project
dart pub get
# In a Flutter project
flutter pub get
Usage #
import 'package:dnotifier/dnotifier.dart';
void main() async {
final client = DNotifier(
appId: 'your-app-id',
secret: 'your-app-secret',
transport: 'ws',
userId: 'user-123',
onConnected: () => print('Connected'),
onMessage: (DNotifierMessage msg) {
print('Message from ${msg.metadata.sender}: ${msg.payload.toJSON()}');
},
onDisconnected: ({code, reason}) => print('Disconnected: $reason'),
);
await client.connect();
// Send a text message
client.send(
senderId: 'user-123',
receiverId: 'user-456',
data: {'text': 'Hello'},
);
// Send binary - No need to use this function. Use the send function as it gives more space and types can defined as per the use-cases.
client.sendBinary(
senderId: 'user-123',
receiverIds: ['user-456'],
buffer: [0x00, 0x01, 0x02],
);
Constructor options (logs + transport) #
final client = DNotifier(
appId: 'your-app-id',
secret: 'your-app-secret',
userId: 'user-123',
transport: 'http', // or 'ws'
logs: true, // enable SDK session/log tracking
);
logs: enables SDK log lifecycle calls (add-log,update-log-status,add-session-step).transport: 'http': sends AI/RAG RPC requests over HTTP transport.
Sending text, images, audio, documents, and other binary attachments #
The SDK supports any binary payload. The type field in data is defined by your app—use whatever values fit your logic (e.g. 'text', 'image', 'audio', 'doc'). In onMessage, branch on body['type'] (e.g. with if/else if) to handle each kind.
// Text message
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'text',
'text': 'hello from dnotifier sdk!',
},
);
// Image (bytes; SDK will split into multiple messages if over plan limit)
final imagePath = File('path/to/your/image.png');
if (await imagePath.exists()) {
final imageBytes = await imagePath.readAsBytes();
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'image',
'content': imageBytes,
},
);
}
// Audio (e.g. base64)
final audioPath = File('path/to/your/voice.m4a');
if (await audioPath.exists()) {
final audioBytes = await audioPath.readAsBytes();
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'audio',
'content': audioBytes,
},
);
}
Use dart:convert for base64Encode. In onMessage, handle body['type'] (e.g. 'image' / 'audio') and decode or save the payload as needed.
Plan limits and AI (after connect) #
final limits = client.getPlanLimits();
if (limits != null && limits.aiEnabled) {
client.sendAI(
senderId: 'user-123',
message: {'text': 'Hello'},
);
// Or with chat history:
// client.sendAI(
// senderId: 'user-123',
// message: {
// 'messages': [
// {'role': 'system', 'content': 'You are a helpful assistant.'},
// {'role': 'user', 'content': 'Generate the plan.'},
// ],
// },
// );
client.fetchAIHistory(senderId: 'user-123');
// Semantic search over message/context knowledge base
client.search(
senderId: 'user-123',
query: 'low impact shoulder safe exercises',
limit: 5,
minSimilarity: 0.7,
);
}
RAG / Knowledge Base APIs #
// Add document
await client.addDocument(
senderId: 'user-123',
recordId: 'doc-001',
content: 'Patient-safe shoulder mobility routine...',
type: 'text',
metadata: {'source': 'sdk-runner'},
);
// Update document
await client.updateDocument(
senderId: 'user-123',
recordId: 'doc-001',
content: 'Updated routine content...',
type: 'text',
);
// Get single document
final doc = await client.getDocument(
senderId: 'user-123',
recordId: 'doc-001',
);
// List documents
final docs = await client.listDocuments(
senderId: 'user-123',
limit: 10,
offset: 0,
type: 'text',
);
// Search documents
final search = await client.search(
senderId: 'user-123',
query: 'shoulder pain low impact',
limit: 5,
minSimilarity: 0.7,
filterbySource: 'sdk-runner',
);
// Delete document
await client.deleteDocument(
senderId: 'user-123',
recordId: 'doc-001',
);
API summary #
| Method / property | Description |
|---|---|
DNotifier(appId, secret, transport, userId, logs?, url?, ...) |
Build the client. transport is 'ws' or 'http'; logs toggles SDK logging; |
connect() |
Authenticate and connect (WebSocket handshake when using ws). |
getPlanLimits() |
Plan limits from last auth (e.g. aiEnabled, maxAIRequestsPerMonth). Throws if not connected. |
send(senderId, receiverId/receiverIds, data, saveHistory?) |
Send a text message (JSON-serializable data). Optional saveHistory (default true) |
sendAI(senderId, message, saveHistory?, sessionId?) |
Send to AI pipeline. Supports new/existing session flow with optional sessionId. |
fetchAIHistory(senderId) |
Fetch AI conversation history for the sender. |
search(senderId, query, limit?, minSimilarity?, filterbySource?) |
Semantic search over Knowledge Base documents. |
addDocument(senderId, recordId, content, type?, metadata?) |
Add a knowledge-base document. |
updateDocument(senderId, recordId, content, type?, metadata?) |
Update an existing knowledge-base document. |
getDocument(senderId, recordId) |
Get a document and its chunks by record id. |
listDocuments(senderId, limit?, offset?, type?) |
List knowledge-base documents. |
deleteDocument(senderId, recordId) |
Delete a knowledge-base document by record id. |
deleteAIHistoryMessage(senderId, messageId) |
Delete one AI history message by id. |
fetchChatHistory(senderId, receiverIds) |
Request chat history; server responds via onMessage with the history payload. |
deleteChatHistoryMessage(senderId, messageId) |
Delete one chat history message by id |
sendBinary(senderId, receiverIds, buffer, type?) |
Send raw bytes. |
sendWithOpenAI(senderId, message, ...) |
Deprecated: use sendAI instead. Forwards to AI pipeline. |
disconnect() |
Close the WebSocket. |
isConnected, aiEnabled |
Connection state and whether AI is enabled for the plan. |
onConnected |
Callback when connection is ready. |
onMessage |
Callback with DNotifierMessage (metadata + Payload). |
onDisconnected |
Callback when connection closes. |
Payload.raw(), .toString(), .toJSON(), .toBase64() |
Read received payload. |
DNotifierPlanLimits |
Plan limits: messagesHardLimit, maxAIRequestsPerMonth, maxAIWordsPerMonth, knowledgeBaseMaxWords, aiEnabled, maxUsers, maxRowsPerUser. |
Links #
- Product: dnotifier.com
- Docs: Product docs