Skip to content

Commit

Permalink
Add app_data to the webhook query params
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Jan 15, 2024
1 parent 3f5bc81 commit a017c8f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions breezsdk/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func createMessageFactory() services.FCMMessageBuilder {
func createPush(notification *notify.Notification) (*messaging.Message, error) {
data := notification.Data
data["notification_type"] = notification.Template
if notification.AppData != nil {
data["app_data"] = *notification.AppData
}
return &messaging.Message{
Token: notification.TargetIdentifier,
Data: data,
Expand Down
11 changes: 8 additions & 3 deletions http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

type MobilePushWebHookQuery struct {
Platform string `form:"platform" binding:"required,oneof=ios android"`
Token string `form:"token" binding:"required"`
Platform string `form:"platform" binding:"required,oneof=ios android"`
Token string `form:"token" binding:"required"`
AppData *string `form:"app_data"`
}

type NotificationConvertible interface {
Expand All @@ -37,6 +38,7 @@ func (p *WebhookCallbackMessagePayload) ToNotification(query *MobilePushWebHookQ
DisplayMessage: p.GenerateDisplayMessage(),
Type: query.Platform,
TargetIdentifier: query.Token,
AppData: query.AppData,
Data: map[string]string{
"callback_url": p.Data.CallbackURL,
"message_payload": p.Data.MessagePayload,
Expand All @@ -46,7 +48,7 @@ func (p *WebhookCallbackMessagePayload) ToNotification(query *MobilePushWebHookQ

func (p *WebhookCallbackMessagePayload) GenerateDisplayMessage() string {
switch p.MessageType {
case "lnulrpay_info":
case "lnurlpay_info":
return "Receiving payment"
case "lnurlpay_invoice":
return "Invoice requested"
Expand All @@ -67,6 +69,7 @@ func (p *PaymentReceivedPayload) ToNotification(query *MobilePushWebHookQuery) *
DisplayMessage: "Incoming payment",
Type: query.Platform,
TargetIdentifier: query.Token,
AppData: query.AppData,
Data: map[string]string{"payment_hash": p.Data.PaymentHash},
}
}
Expand All @@ -84,6 +87,7 @@ func (p *TxConfirmedPayload) ToNotification(query *MobilePushWebHookQuery) *noti
DisplayMessage: "Transaction confirmed",
Type: query.Platform,
TargetIdentifier: query.Token,
AppData: query.AppData,
Data: map[string]string{"tx_id": p.Data.TxID},
}
}
Expand All @@ -101,6 +105,7 @@ func (p *AddressTxsChangedPayload) ToNotification(query *MobilePushWebHookQuery)
DisplayMessage: "Address transactions changed",
Type: query.Platform,
TargetIdentifier: query.Token,
AppData: query.AppData,
Data: map[string]string{"address": p.Data.Address},
}
}
Expand Down
6 changes: 5 additions & 1 deletion http/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import (
)

func TestPaymentReceivedHook(t *testing.T) {
testAppData := "testdata"
query := MobilePushWebHookQuery{
Platform: "android",
Token: "1234",
AppData: &testAppData,
}

paymentReceivedPayload := PaymentReceivedPayload{
Template: notify.NOTIFICATION_PAYMENT_RECEIVED,
Data: struct {
Expand All @@ -26,12 +29,13 @@ func TestPaymentReceivedHook(t *testing.T) {
PaymentHash: "1234",
},
}

body, err := json.Marshal(paymentReceivedPayload)
if err != nil {
t.Fatalf("failed to marshal notification %v", err)
}
expected := paymentReceivedPayload.ToNotification(&query)
testValidNotification(t, "/api/v1/notify?platform=android&token=1234", body, expected)
testValidNotification(t, "/api/v1/notify?platform=android&token=1234&app_data=testdata", body, expected)
}

func TestTxConfirmedHook(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Notification struct {
DisplayMessage string
Type string
TargetIdentifier string
AppData *string
Data map[string]string
}

Expand Down

0 comments on commit a017c8f

Please sign in to comment.