shufo / fcmex

A Firebase Cloud Message client for Elixir
https://hex.pm/packages/fcmex
MIT License
75 stars 24 forks source link

Adding support for condition field #82

Open KosmonautX opened 1 year ago

KosmonautX commented 1 year ago

Naive implementation of incorporating conditions for pushing messages to topics.

condition | Optional, string | This parameter specifies a logical expression of conditions that determine the message target.

Supported condition: Topic, formatted as "'yourTopic' in topics". This value is case-insensitive. Supported operators: &&, \|\|. Maximum two operators per topic message supported.

Current library is built around the to field, however using condition field collides with the 'to' field. As below:

{:error, "Must use either \"registration_ids\" field or \"to\" field or \"condition\", not more than one\n"}

As such to support condition field, I have prevented the merge of the to field

Willing to add in the test cases and update docs if satisfactory.


Fcmex.push("Messages all of Athens but not Pheidippides",
  notification: %{
    title: "CITY.Athens not USER.Pheidippides",
    body: "Rejoice, we conquer"
  },
  condition: "'CITY.Athens' in topics && !('USER.Pheidippides' in topics)"
)