Sub AppStart (Args() As String)
SendMessage("general", "mis title", "body slam")
StartMessageLoop
End Sub
Private Sub SendMessage(Topic As String, Title As String, Body As String)
Log("Topic: " & Topic)
Log("Title: " & Title)
Log("Body: " & Body)
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
Dim data As Map = CreateMap("title": Title, "body": Body)
If Topic.StartsWith("ios_") Then
Dim iosalert As Map = CreateMap("title": Title, "body": Body, "sound": "default")
m.Put("notification", iosalert)
m.Put("priority", 10)
End If
' neither seems to matter
m.Put("android", CreateMap("priority": "high")) ' Erel
''m.Put("android", CreateMap("priority": 10)) ' Marc - what am i thinking?
m.Put("data", data)
Dim jg As JSONGenerator
jg.Initialize(m)
Log("POST: " & jg.ToString)
Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
''Log("using API_KEY" & CRLF & API_KEY)
Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub
Sub JobDone(job As HttpJob)
Log("JobDone: " & job.Success)
If job.Success Then
Log(job.GetString)
End If
job.Release
ExitApplication '!
End Sub