Send Messages
In order to send messages, you need to create a Broadcast using the broadcast() method. This method requires a Private Key, and thus only available in the Backend SDKs.
Ensure you have installed DashX SDKs before continuing.
- Node.js
- Spring Boot (Java)
- Python
- Ruby
// Sending a Message Template
dashx.broadcast('email/forgot-password', {
to: user.email,
data: { reset_password_token: '<TOKEN>' }
});
// Sending an Ad-Hoc Message
dashx.broadcast('email', {
content: {
name: 'Contact us',
from: 'noreply@dashxdemo.com',
to: [email, 'sales@dashx.com'],
subject: 'Contact Us Form',
html_body: `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text>Thanks for reaching out! We will get back to you soon!</mj-text>
<mj-text>Your feedback: </mj-text>
<mj-text>Name: {{name}}</mj-text>
<mj-text>Email: {{email}}</mj-text>
<mj-text>Feedback: {{feedback}}</mj-text>
<mj-divider border-color="#F45E43"></mj-divider>
</mj-column>
</mj-section>
</mj-body>
</mjml>`
},
data: {
name,
email,
feedback
}
});
import com.dashx.graphql.generated.types.CreateBroadcastInput;
import com.dashx.graphql.generated.types.TemplateSubkind;
// Sending a Message Template
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.EMAIL)
.templateIdentifier("forgot-password")
.content(Map.of("to", user.getEmail()))
.data(Map.of("reset_password_token", "<TOKEN>"))
.build());
// Sending an Ad-Hoc Message
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.EMAIL)
.content(Map.of(
"name", "Contact us",
"from", "noreply@dashxdemo.com",
"to", List.of(email, "sales@dashx.com"),
"subject", "Contact Us Form",
"html_body", """
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text>Thanks for reaching out! We will get back to you soon!</mj-text>
<mj-text>Your feedback: </mj-text>
<mj-text>Name: {{name}}</mj-text>
<mj-text>Email: {{email}}</mj-text>
<mj-text>Feedback: {{feedback}}</mj-text>
<mj-divider border-color="#F45E43"></mj-divider>
</mj-column>
</mj-section>
</mj-body>
</mjml>"""
))
.data(Map.of(
"name", name,
"email", email,
"feedback", feedback
))
.build());
// Sending a Push Message (via template)
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.PUSH)
.templateIdentifier("welcome-push")
.content(Map.of("to", List.of("account_uid:<USER ID>")))
.build());
// Sending an Ad-Hoc Push Message
Map<String, Object> content = new HashMap<>();
content.put("to", List.of("account_uid:<USER ID>"));
content.put("title", "Order shipped!");
content.put("body", "Your order #1234 is on its way.");
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.PUSH)
.content(content)
.build());
// Sending a Push Message with shared title/body and platform-specific overrides
// - top-level title/body are used as defaults for all platforms
// - androidSettings.title/body override them on Android devices
// - iosSettings.title/body override them on iOS devices
// - all other android/ios keys are applied regardless of whether title/body are overridden
Map<String, Object> combinedAndroidSettings = new HashMap<>();
combinedAndroidSettings.put("title", "Order shipped! 🚚"); // Android-specific title override
combinedAndroidSettings.put("body", "Tap to track your order."); // Android-specific body override
combinedAndroidSettings.put("collapseKey", "orders"); // groups notifications with same key
combinedAndroidSettings.put("priority", "HIGH"); // HIGH or NORMAL
combinedAndroidSettings.put("smallIcon", "ic_notification"); // drawable resource name
combinedAndroidSettings.put("largeIcon", "ic_launcher"); // drawable resource name
combinedAndroidSettings.put("channelId", "orders_channel"); // Android 8.0+ notification channel
combinedAndroidSettings.put("sound", "default");
combinedAndroidSettings.put("visibility", "PUBLIC"); // PUBLIC, PRIVATE, or SECRET
combinedAndroidSettings.put("color", "#FF5733"); // accent color (hex)
combinedAndroidSettings.put("tag", "order-1234"); // replaces existing notification with same tag
combinedAndroidSettings.put("notificationCount", 3); // badge count
combinedAndroidSettings.put("clickAction", "OPEN_ORDER"); // intent action on tap
combinedAndroidSettings.put("lightSettings", Map.of(
"color", "#FF5733",
"lightOnDuration", 1000L, // ms
"lightOffDuration", 500L // ms
));
Map<String, Object> combinedIosSettings = new HashMap<>();
combinedIosSettings.put("title", "Order shipped! 📦"); // iOS-specific title override
combinedIosSettings.put("body", "Tap to track your order."); // iOS-specific body override
combinedIosSettings.put("subtitle", "Estimated delivery: tomorrow"); // shown below title
combinedIosSettings.put("badge", 1); // app icon badge count
combinedIosSettings.put("sound", "default");
combinedIosSettings.put("threadId", "orders"); // groups notifications in Notification Center
combinedIosSettings.put("category", "ORDER_ACTIONS"); // maps to a registered UNNotificationCategory
combinedIosSettings.put("targetContentId", "order-1234"); // used with notification content extensions
combinedIosSettings.put("interruptionLevel", "active"); // active, passive, timeSensitive, or critical
combinedIosSettings.put("relevanceScore", 0.75); // 0.0–1.0, influences summary ordering
combinedIosSettings.put("priority", "High"); // Low (1), Normal (5), or High (10)
combinedIosSettings.put("collapseId", "orders"); // replaces existing notification with same id
combinedIosSettings.put("launchImage", "LaunchImage"); // launch image name from bundle
Map<String, Object> combinedContent = new HashMap<>();
combinedContent.put("to", List.of("account_uid:<USER ID>"));
combinedContent.put("title", "Your order has been shipped!"); // fallback for any platform not overriding
combinedContent.put("body", "Order #1234 is on its way."); // fallback for any platform not overriding
combinedContent.put("androidSettings", combinedAndroidSettings);
combinedContent.put("iosSettings", combinedIosSettings);
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.PUSH)
.content(combinedContent)
.build());
// Sending a Push Message with deep linking
// - url: opens a deep link or in-app browser (when richLanding is true)
// - screenName / screenData: navigates to a named screen with optional parameters
// - clickAction: triggers an intent action (Android) or maps to a UNNotificationCategory (iOS)
// - richLanding: when true, opens the url in an in-app browser instead of the system browser
// - action buttons can each carry their own deep link fields
Map<String, Object> deepLinkContent = new HashMap<>();
deepLinkContent.put("to", List.of("account_uid:<USER ID>"));
deepLinkContent.put("title", "Your order has been shipped!");
deepLinkContent.put("body", "Order #1234 is on its way.");
deepLinkContent.put("url", "https://example.com/orders/1234"); // deep link for the main notification tap
deepLinkContent.put("screenName", "OrderDetail"); // in-app screen navigation (takes priority over url)
deepLinkContent.put("screenData", Map.of("orderId", "1234")); // parameters passed to the screen
deepLinkContent.put("richLanding", true); // opens url in in-app browser if screenName is absent
deepLinkContent.put("clickAction", "OPEN_ORDER"); // intent action fallback
deepLinkContent.put("actionButtons", List.of(
Map.of(
"identifier", "track",
"label", "Track Order",
"url", "https://example.com/orders/1234/track",
"richLanding", true // opens in in-app browser
),
Map.of(
"identifier", "details",
"label", "View Details",
"screenName", "OrderDetail", // navigates to a named screen
"screenData", Map.of("orderId", "1234")
)
));
dashX.sendBroadcast(CreateBroadcastInput.newBuilder()
.templateSubkind(TemplateSubkind.PUSH)
.content(deepLinkContent)
.build());
// Sending a Message Template
dashx.broadcast('email/forgot-password', {
to: user.email,
data: { reset_password_token: '<TOKEN>' }
})
// Sending an Ad-Hoc Message
dashx.broadcast('email', {
content: {
name: 'Contact us',
from: 'noreply@dashxdemo.com',
to: [email, 'sales@dashx.com'],
subject: 'Contact Us Form',
html_body: `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text>Thanks for reaching out! We will get back to you soon!</mj-text>
<mj-text>Your feedback: </mj-text>
<mj-text>Name: {{name}}</mj-text>
<mj-text>Email: {{email}}</mj-text>
<mj-text>Feedback: {{feedback}}</mj-text>
<mj-divider border-color="#F45E43"></mj-divider>
</mj-column>
</mj-section>
</mj-body>
</mjml>`
},
data: {
name,
email,
feedback
}
})
# Sending a Message Template
dashx.broadcast('email/forgot-password', {
to: user.email,
data: { reset_password_token: '<TOKEN>' }
})
# Sending an Ad-Hoc Message
dashx.broadcast('email', {
content: {
name: 'Contact us',
from: 'noreply@dashxdemo.com',
to: [email, 'sales@dashx.com'],
subject: 'Contact Us Form',
html_body: `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text>Thanks for reaching out! We will get back to you soon!</mj-text>
<mj-text>Your feedback: </mj-text>
<mj-text>Name: {{name}}</mj-text>
<mj-text>Email: {{email}}</mj-text>
<mj-text>Feedback: {{feedback}}</mj-text>
<mj-divider border-color="#F45E43"></mj-divider>
</mj-column>
</mj-section>
</mj-body>
</mjml>`
},
data: {
name,
email,
feedback
}
})