We add a new type of Vumi Go message, similar to a VumiApiCommand to handle events:
VumiApiEvent:
account_key
conversation_key
conversation_type
event_type
event_data
A kind of event is uniquely identified by conversation_type
and event_type
, and event_data
is a dict. All events go to an event dispatcher (either part of or similar to the command dispatcher) which looks up what needs to happen with each event and does the appropriate things.
Event sources generate and publish events.
All application/conversation workers are potential event sources. We may want to have some additional non-conversation event sources as well at some point.
Event handlers are pieces of code (perhaps workers, perhaps part of the event dispatcher) that accept an event and then do something with it. Handlers would have to be specific to certain event types, but could also be event sources and fire their own events in response to things the're handling.
For example: A vxpolls conversation could fire a poll_complete
event containing the poll results when someone finishes filling in a poll. The account has a create_contact
handler listening for poll_complete
events from that particular conversation, and configured to extract certain values from the poll data to create a contact with.
Event handlers would have to be configured in the UI somewhere, probably in a manner similar to a conversation start. Perhaps this kind of flow:
- Create new event handler
- Select event source and type
- Select event handler type
- Configure handler-specific options
- Profit!
We'd need to be able to chain handlers, so we could create a new contact and then send an SMS when a poll finishes.
Not entirely event-related, but this might be a good place to set up account-level tag routing and such, perhaps with a default account-wide message handler that does something sane rather than just throwing all the messages on the floor.
VumiApiCommand
, I suppose, but I'm not really sold on the idea. I'm thinking of a command as a directed instruction (tell this conversation to start) and an event as a broadcast notification (this conversation has done something others might be interested in).poll_complete
event, the dispatcher would catch it, see that there's a "create contact" handler interested in that kind of event from that source, and feed the event to the handler.