Skip to content

Commit

Permalink
Add support for webhook_callback_message
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Dec 31, 2023
1 parent 66bed11 commit ba6dadf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion breezsdk/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 18 additions & 1 deletion http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &notify.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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit ba6dadf

Please sign in to comment.