Skip to content

Commit

Permalink
[Android] for new notification endpoint use the message format
Browse files Browse the repository at this point in the history
to target a specific device
  • Loading branch information
e-marchand committed Oct 15, 2024
1 parent 0b6db5f commit 76f6932
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project/Sources/Methods/Mobile App Push Notification.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ If (Not:C34($isMissingRecipients))
$notificationInput:=New object:C1471(\
"project"; $Obj_auth.project; \
"serverKey"; $Obj_auth.serverKey; \
"message"; JSON Stringify:C1217($message))
"message"; $message)

$status:=android_sendNotification($notificationInput)

Expand Down
27 changes: 25 additions & 2 deletions Project/Sources/Methods/android_sendNotification.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ $Obj_result:=New object:C1471("success"; False:C215)

// ENDPOINT
//________________________________________

var $message : Variant
$message:=$input.message

var $endpoint : Text
If ($input.project#Null:C1517)

$endpoint:="https://fcm.googleapis.com/v1/projects/"+String:C10($input.project)+"/messages:send"

If (Value type:C1509($input.message)=Is object:K8:27)

If ($input.message.to#Null:C1517)
// old format, convert
$message:=New object:C1471("message"; New object:C1471("token"; $input.message.to; "notification"; $input.message.data))
End if

End if

Else
$endpoint:="https://fcm.googleapis.com/fcm/send"
End if

var $messageText : Text
Case of
: (Value type:C1509($message)=Is object:K8:27)
$messageText:=JSON Stringify:C1217($message)
Else
$messageText:=String:C10($message)
End case

If ((Length:C16(String:C10($input.serverKey))>0)\
& (Length:C16(String:C10($input.message))>0))
& (Length:C16($messageText)>0))

$cmdPush:="curl"

Expand All @@ -37,7 +60,7 @@ If ((Length:C16(String:C10($input.serverKey))>0)\
"--header \"Authorization: "+$authorizationHeader+"\" "+\
"--header \"Content-Type: application/json\" "+\
$endpoint+" "+\
"-d \""+Replace string:C233($input.message; "\""; "\\\"")+"\""
"-d \""+Replace string:C233($messageText; "\""; "\\\"")+"\""

LAUNCH EXTERNAL PROCESS:C811($cmdPush; $cmdPush_in; $cmdPush_out; $cmdPush_err)

Expand Down

0 comments on commit 76f6932

Please sign in to comment.