Push Notifications
Push notifications require users to have registered devices.
Registering a Device
Before sending a push, you must register the user's device token.
func registerAndroidDevice(client *cdp.Client, userID, fcmToken string) {
payload := cdp.DevicePayload{
UserID: userID,
DeviceToken: fcmToken,
Platform: "android", // or "ios"
Attributes: map[string]interface{}{
"device_model": "Pixel 7",
"app_version": "1.0.2",
},
}
if err := client.RegisterDevice(context.Background(), payload); err != nil {
log.Printf("Failed to register device: %v", err)
}
}
Sending a Push Notification
Sending a push notification uses a TransactionalMessageID which corresponds to a push configuration in Conviso.
func sendPush(client *cdp.Client) {
payload := cdp.PushPayload{
Identifiers: cdp.Identifiers{
ID: "u_12345",
},
TransactionalMessageID: "promo-sale-winter",
// Overrides (optional, if allowed by template)
Title: "Winter Sale Starts Now!",
Body: "Get 50% off all jackets.",
// Data payload (for deep linking or custom app logic)
MessageData: map[string]interface{}{
"deep_link": "app://shop/category/jackets",
"sale_id": "winter_2024",
},
}
if err := client.SendPush(context.Background(), payload); err != nil {
log.Printf("Failed to send push: %v", err)
}
}