hedwig-im / hedwig

An Adapter-based Bot Framework for Elixir Applications
MIT License
656 stars 73 forks source link

Make Robot a real OTP behaviour #61

Open michalmuskala opened 7 years ago

michalmuskala commented 7 years ago

Currently the Hewdig.Robot module masquerades as a pseudo behaviour through macros and injection of code into the user's module. This has couple issues, most notably the robot cannot be started twice - for example with different adapters - to handle traffic from two different networks. This limitation prevents me from using the library in it's current shape.

The Hedwig.Robot should be made a real behaviour with API similar to GenServer or to the custom Connection behaviour. This would make the code more flexible for runtime changes and configuration. Limiting injecting code into user modules should also speed up compilation. It is generally discouraged to inject large amounts of code into user modules.

If you agree this would be beneficial I would be glad to work on this.

scrogson commented 7 years ago

@michalmuskala - Yes I agree. I have thought about this many many times.

I appreciate your willingness to help, but this would be something I would prefer to do myself as I have been wanting to do for a while now.

I would definitely appreciate feedback though. Sound good?

michalmuskala commented 7 years ago

I totally understand that. If you have some questions or code you'd like me to review, just ping me.

scrogson commented 7 years ago

I sure will. Thanks for understanding.

I'm going to release v1.0.0 and then begin on this change for 2.0.

electricshaman commented 6 years ago

I'd love to see this for 2.0 as well. I just ran into another issue that stems from this, where a race condition exists due to the global name registration being deferred until handle_connect in the Robot behavior. Ideally this would be in start_link but that function is part of the code being injected and can't be overridden. I'd even settle for init but it's also being injected.