From ba6dadf3fae7f20b75335522375053feb43fc2a7 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Sun, 31 Dec 2023 17:57:15 +0200 Subject: [PATCH] Add support for webhook_callback_message --- breezsdk/init.go | 3 ++- http/router.go | 19 ++++++++++++++++++- notify/notify.go | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/breezsdk/init.go b/breezsdk/init.go index bb9b4ce..a51be29 100644 --- a/breezsdk/init.go +++ b/breezsdk/init.go @@ -21,7 +21,8 @@ func createMessageFactory() services.FCMMessageBuilder { switch notification.Template { case notify.NOTIFICATION_PAYMENT_RECEIVED, notify.NOTIFICATION_TX_CONFIRMED, - notify.NOTIFICATION_ADDRESS_TXS_CHANGED: + notify.NOTIFICATION_ADDRESS_TXS_CHANGED, + notify.NOTIFICATION_WEBHOOK_CALLBACK: return createSilentPush(notification) } diff --git a/http/router.go b/http/router.go index ea528d4..b84b4d4 100644 --- a/http/router.go +++ b/http/router.go @@ -22,6 +22,23 @@ type NotificationConvertible interface { ToNotification(query *MobilePushWebHookQuery) *notify.Notification } +type WebhookCallbackMessagePayload struct { + Template string `json:"template" binding:"required,eq=webhook_callback_message"` + Data struct { + CallbackURL string `json:"callback_url" binding:"required"` + MessagePayload string `json:"message_payload"` + } `json:"data"` +} + +func (p *WebhookCallbackMessagePayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification { + return ¬ify.Notification{ + Template: p.Template, + Type: query.Platform, + TargetIdentifier: query.Token, + Data: map[string]string{"callback_url": p.Data.CallbackURL, "message_payload": p.Data.MessagePayload}, + } +} + type PaymentReceivedPayload struct { Template string `json:"template" binding:"required,eq=payment_received"` Data struct { @@ -97,7 +114,7 @@ func addWebHookRouter(r *gin.RouterGroup, notifier *notify.Notifier) { } // Find a matching notification payload - payloads := []NotificationConvertible{&PaymentReceivedPayload{}, &TxConfirmedPayload{}, &AddressTxsChangedPayload{}} + payloads := []NotificationConvertible{&PaymentReceivedPayload{}, &TxConfirmedPayload{}, &AddressTxsChangedPayload{}, &WebhookCallbackMessagePayload{}} var validPayload NotificationConvertible for _, p := range payloads { if err := c.ShouldBindBodyWith(p, binding.JSON); err != nil { diff --git a/notify/notify.go b/notify/notify.go index e2f28bf..33be57d 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -13,6 +13,7 @@ const ( NOTIFICATION_PAYMENT_RECEIVED = "payment_received" NOTIFICATION_TX_CONFIRMED = "tx_confirmed" NOTIFICATION_ADDRESS_TXS_CHANGED = "address_txs_changed" + NOTIFICATION_WEBHOOK_CALLBACK = "webhook_callback_message" ) var (