axelson

axelson

Scenic Core Team

How would you implement Slack's notification flowchart in Elixir?

Slack has a crazy/intense flowchart to decide if they should send a push notification to a user for a specific message. Here it is for reference:

[source]

As a thought experiment if you were tasked with creating a system in Elixir to implement this decision tree how would you implement it? Ideally the approaches would take into consideration:

  • Maintainability of the code
  • Clarity/readability (bonus points if it can easily be shown to the business owner)
  • The understanding that answering some of the questions in the flowchart may require a non-negligible db query

Most Liked

gregvaughn

gregvaughn

There was a talk at this year’s ElixirConf about Behavior Trees that might be applicable here. They’re a concept mostly from the video game industry and NPC behavior. They were new to me, but might be worth watching the talk to see if you’d want to try them for this.

10
Post #2
slashdotdash

slashdotdash

I’ve just discovered a library named Opus which allows you to create pipelines using a declarative DSL. It even supports outputting a pipeline as a graph using GraphVix.

sanswork

sanswork

I’d create a module with a single entry point and all the rules as private functions within it, pattern matching where possible. In a roughly top down order.

def send_notification(user, message)

#called from send_notifications
defp channel_muted(user, message)

#called from channel_muted
defp message_and_subscribed(user, message)

I don’t see any way to get something with that complex of a flow in a way that could easily be shown to a business owner in code so I wouldn’t put much energy into trying since a flow chart like this is a better route for that. I’d focus exclusively on trying to get it to be easy for developers to slot in new rules. So things like making sure comments show all calling functions.

Last Post!

axelson

axelson

Scenic Core Team

I wanted to circle back on this. For now I went with @venkatd’s suggestion of creating a single entry point to collect all the data into a struct, that we then check. Although in my case I ended up with several structs, but it’s been working pretty well. But in the future I’d really like to try something like the behavior trees!

Where Next?

Popular in Discussions Top

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14403 124
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement