Skip to content

Adding support for condition field#82

Open
ks0m1c wants to merge 3 commits into
shufo:masterfrom
ks0m1c:master
Open

Adding support for condition field#82
ks0m1c wants to merge 3 commits into
shufo:masterfrom
ks0m1c:master

Conversation

@ks0m1c

@ks0m1c ks0m1c commented Oct 27, 2022

Copy link
Copy Markdown

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)"
)

κϩⲐⲡⲓז‎ς_ⲙ0ᚱⲣⲉ𐤅ᛊ added 3 commits October 28, 2022 00:42
Motivation: To pattern match the condition option match to more cleanly
ignore the to field

Quoting from Erlang OTP team => https://erlangforums.com/t/handling-options-in-erlang-otp-apis/1133
Briefly, the main motivation for avoiding lists unless necessary, is that given the option list [{use_foo,true}, {use_foo,false}] the value of the use_foo is not immediately clear. Existing OTP APIs that use options are not consistent in that regard. With maps, that ambiguity cannot arise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant