Push Notifications
Push notifications in Ductape let you send parameterized alerts to your users' devices through your configured push provider. Use push notifications for real-time alerts, confirmations, or updates.
What Is a Push Notification?
A push notification consists of:
- title: The title of the push notification (required). Can include template variables (e.g.,
{{username}}). - body: The body of the push notification (required). Can include template variables.
- data: Additional data sent with the notification (optional, JSON object). Can include template variables.
Push Notification Structure
- title: The notification title, with optional template variables.
- body: The notification body, with optional template variables.
- data: Optional JSON object with additional data, with optional template variables.
Example Template:
- TypeScript
- Java
- Go
- .NET
const push_notification = {
title: "Credit Alert From {{username}}",
body: "{{username}} sent you {{amount}} {{currency}}",
data: {
transaction_id: "{{transactionId}}",
bank_code: "{{bankCode}}"
}
}
Map<String, Object> push_notification = Map.of(
"title", "Credit Alert From Map.of(Map.of(username))",
"body", "Map.of(Map.of(username)) sent you Map.of(Map.of(amount)) Map.of(Map.of(currency))",
data: Map.of(
"transaction_id", "Map.of(Map.of(transactionId))",
"bank_code", "Map.of(Map.of(bankCode))"
)
)
push_notification := map[string]any{
"title": "Credit Alert From {{username}}",
"body": "{{username}} sent you {{amount}} {{currency}}",
data: {
"transaction_id": "{{transactionId}}",
"bank_code": "{{bankCode}}"
}
}
var push_notification = new Dictionary<string, object?>
{
["title"] = "Credit Alert From {{username}}",
["body"] = "{{username}} sent you {{amount}} {{currency}}",
data: {
["transaction_id"] = "{{transactionId}}",
["bank_code"] = "{{bankCode}}"
}
}
Using Template Variables
Template variables in any part of the push notification are enclosed in {{ }} and replaced with actual values when the notification is sent.
Note: All template variables in your title, body, and data must be provided in the data object when sending the notification. If a variable is missing, the placeholder will remain unreplaced in the final notification.
Example Input Data
- TypeScript
- Java
- Go
- .NET
const data = {
title: {
username: "Thomas"
},
body: {
username: "Thomas",
amount: "50",
currency: "GBP"
},
data: {
transactionId: "111292929-1-18288282",
bankCode: "039"
}
}
Map<String, Object> data = Map.of(
title: Map.of(
"username", "Thomas"
),
body: Map.of(
"username", "Thomas",
"amount", "50",
"currency", "GBP"
),
data: Map.of(
"transactionId", "111292929-1-18288282",
"bankCode", "039"
)
)
data := map[string]any{
title: {
"username": "Thomas"
},
body: {
"username": "Thomas",
"amount": "50",
"currency": "GBP"
},
data: {
"transactionId": "111292929-1-18288282",
"bankCode": "039"
}
}
var data = new Dictionary<string, object?>
{
title: {
["username"] = "Thomas"
},
body: {
["username"] = "Thomas",
["amount"] = "50",
["currency"] = "GBP"
},
data: {
["transactionId"] = "111292929-1-18288282",
["bankCode"] = "039"
}
}
Generated Push Notification
The system will automatically replace the placeholders to produce:
- TypeScript
- Java
- Go
- .NET
{
title: "Credit Alert From Thomas",
body: "Thomas sent you 50 GBP",
data: {
transaction_id: "111292929-1-18288282",
bank_code: "039"
}
}
Map.of(
"title", "Credit Alert From Thomas",
"body", "Thomas sent you 50 GBP",
data: Map.of(
"transaction_id", "111292929-1-18288282",
"bank_code", "039"
)
)
{
"title": "Credit Alert From Thomas",
"body": "Thomas sent you 50 GBP",
data: {
"transaction_id": "111292929-1-18288282",
"bank_code": "039"
}
}
{
["title"] = "Credit Alert From Thomas",
["body"] = "Thomas sent you 50 GBP",
data: {
["transaction_id"] = "111292929-1-18288282",
["bank_code"] = "039"
}
}
Key Points:
- All template variables are required at send time.
- Unmatched placeholders will remain in the message.
- Choose and configure your push provider in your notification environment settings.
Next Steps: