5
5
"fmt"
6
6
"strings"
7
7
tmpltext "text/template"
8
+ "time"
8
9
9
10
"github.com/prometheus/alertmanager/template"
10
11
"golang.org/x/net/context"
@@ -59,18 +60,15 @@ func NewMessaging() (*messaging.Client, error) {
59
60
return client , err
60
61
}
61
62
62
- // NewMessage returns a new FCM message struct
63
- func NewMessage (topic , title , body string ) * messaging.Message {
63
+ func NewDataMessage (topic , title , body string ) * messaging.Message {
64
+ unixMillisecondsUTC := time .Now ().UTC ().UnixNano () / 1000000
65
+ data := map [string ]string {
66
+ "title" : title ,
67
+ "body" : body ,
68
+ "pageTime" : string (unixMillisecondsUTC ),
69
+ }
64
70
return & messaging.Message {
65
- Notification : & messaging.Notification {
66
- Title : title ,
67
- Body : body ,
68
- },
69
- Data : map [string ]string {
70
- "title" : title ,
71
- "body" : body ,
72
- "click_action" : "FLUTTER_NOTIFICATION_CLICK" ,
73
- },
71
+ Data : data ,
74
72
Topic : topic ,
75
73
// https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
76
74
Android : & messaging.AndroidConfig {
@@ -79,7 +77,18 @@ func NewMessage(topic, title, body string) *messaging.Message {
79
77
}
80
78
}
81
79
82
- // NewMessageFromAlertmanagerDats returns a new FCM message from alertmanager POST data
80
+ // NewNoficationMessage returns a new FCM message including notificaton data
81
+ func NewNoficationMessage (topic , title , body string ) * messaging.Message {
82
+ message := NewDataMessage (topic , title , body )
83
+ message .Notification = & messaging.Notification {
84
+ Title : title ,
85
+ Body : body ,
86
+ }
87
+ message .Data ["click_action" ] = "FLUTTER_NOTIFICATION_CLICK"
88
+ return message
89
+ }
90
+
91
+ // NewMessageFromAlertmanagerDats returns a new FCM data message from alertmanager POST data
83
92
func NewMessageFromAlertmanagerData (topic string , m * template.Data ) (* messaging.Message , error ) {
84
93
title , err := tmpltextExecuteToString (tmplTitle , m )
85
94
if err != nil {
@@ -91,7 +100,7 @@ func NewMessageFromAlertmanagerData(topic string, m *template.Data) (*messaging.
91
100
return nil , & TemplateError {Type : "body" , Err : err }
92
101
}
93
102
94
- return NewMessage (topic , title , body ), nil
103
+ return NewDataMessage (topic , title , body ), nil
95
104
}
96
105
97
106
func tmpltextExecuteToString (tmpl * tmpltext.Template , data interface {}) (string , error ) {
0 commit comments