diff --git a/breezsdk/init.go b/breezsdk/init.go index a51be29..38b3cf0 100644 --- a/breezsdk/init.go +++ b/breezsdk/init.go @@ -24,17 +24,16 @@ func createMessageFactory() services.FCMMessageBuilder { notify.NOTIFICATION_ADDRESS_TXS_CHANGED, notify.NOTIFICATION_WEBHOOK_CALLBACK: - return createSilentPush(notification) + return createPush(notification) } return nil, nil } } -func createSilentPush(notification *notify.Notification) (*messaging.Message, error) { +func createPush(notification *notify.Notification) (*messaging.Message, error) { data := notification.Data data["notification_type"] = notification.Template - return &messaging.Message{ Token: notification.TargetIdentifier, Data: data, @@ -47,6 +46,9 @@ func createSilentPush(notification *notify.Notification) (*messaging.Message, er }, Payload: &messaging.APNSPayload{ Aps: &messaging.Aps{ + Alert: &messaging.ApsAlert{ + Title: notification.DisplayMessage, + }, ContentAvailable: false, MutableContent: true, }, diff --git a/http/router.go b/http/router.go index b84b4d4..eddbd9f 100644 --- a/http/router.go +++ b/http/router.go @@ -23,8 +23,9 @@ type NotificationConvertible interface { } type WebhookCallbackMessagePayload struct { - Template string `json:"template" binding:"required,eq=webhook_callback_message"` - Data struct { + Template string `json:"template" binding:"required,eq=webhook_callback_message"` + MessageType string `json:"message_type" binding:"required"` + Data struct { CallbackURL string `json:"callback_url" binding:"required"` MessagePayload string `json:"message_payload"` } `json:"data"` @@ -33,10 +34,24 @@ type WebhookCallbackMessagePayload struct { func (p *WebhookCallbackMessagePayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification { return ¬ify.Notification{ Template: p.Template, + DisplayMessage: p.GenerateDisplayMessage(), Type: query.Platform, TargetIdentifier: query.Token, - Data: map[string]string{"callback_url": p.Data.CallbackURL, "message_payload": p.Data.MessagePayload}, + Data: map[string]string{ + "callback_url": p.Data.CallbackURL, + "message_payload": p.Data.MessagePayload, + }, + } +} + +func (p *WebhookCallbackMessagePayload) GenerateDisplayMessage() string { + switch p.MessageType { + case "lnulrpay_info": + return "Receiving payment" + case "lnurlpay_invoice": + return "Invoice requested" } + return "" } type PaymentReceivedPayload struct { @@ -49,6 +64,7 @@ type PaymentReceivedPayload struct { func (p *PaymentReceivedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification { return ¬ify.Notification{ Template: p.Template, + DisplayMessage: "Incoming payment", Type: query.Platform, TargetIdentifier: query.Token, Data: map[string]string{"payment_hash": p.Data.PaymentHash}, @@ -65,6 +81,7 @@ type TxConfirmedPayload struct { func (p *TxConfirmedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification { return ¬ify.Notification{ Template: p.Template, + DisplayMessage: "Transaction confirmed", Type: query.Platform, TargetIdentifier: query.Token, Data: map[string]string{"tx_id": p.Data.TxID}, @@ -81,6 +98,7 @@ type AddressTxsChangedPayload struct { func (p *AddressTxsChangedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification { return ¬ify.Notification{ Template: p.Template, + DisplayMessage: "Address transactions changed", Type: query.Platform, TargetIdentifier: query.Token, Data: map[string]string{"address": p.Data.Address}, diff --git a/notify/notify.go b/notify/notify.go index 33be57d..399ce15 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -22,6 +22,7 @@ var ( type Notification struct { Template string + DisplayMessage string Type string TargetIdentifier string Data map[string]string