public Sub SendMessage(Topic As String, Title As String, Body As String, Data As Map) As ResumableSub
Dim sdeviceID As String = Data.get("deviceid")
Dim smsgType As String = Data.get("msgtype")
Dim smsgdate As String = Data.get("msgdate")
Dim sVoltage As String = Data.get("voltage")
'
smsgdate = NiceDate(smsgdate)
Dim stitle As String = GetMessageTitle(sdeviceID, smsgType)
Dim sBody As String = stitle & ", voltage @ " & sVoltage & ", on " & smsgdate
Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
Data.Put("topic", Topic)
Data.Put("title", stitle)
Data.Put("body", sBody)
If Topic.StartsWith("ios_") Then
Dim iosalert As Map = CreateMap("title": stitle, "body": sBody, "sound": "default", "icon": "./assets/appicon.png")
m.Put("notification", iosalert)
m.Put("priority", 10)
Else
Dim pri As Map = CreateMap("priority":"high")
m.Put("priority", "high")
m.Put("android", pri)
End If
m.Put("data", Data)
Dim jg As JSONGenerator
jg.Initialize(m)
'
Dim msgOut As String = jg.ToString
Log(msgOut)
Dim j As HttpJob
j.Initialize("fcm", Me)
j.PostString("https://fcm.googleapis.com/fcm/send", msgOut)
J.GetRequest.SetContentType("application/json;charset=UTF-8")
J.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
Wait For (j) JobDone (j As HttpJob)
If j.Success = True Then
' Reply from Firebase
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim rp As Map = jp.NextObject
Dim message As String = rp.Get("message_id")
'this is important for the associations related content
'convert the map to an array of objects
Data.Put("msgid", message)
Else
Data.Put("msgid", "")
Log(j.ErrorMessage)
End If
j.Release
Data.Put("status", "A")
Return Data
End Sub