By the end of this epic, Avni should be able to send HSM templated Whatsapp messages to Glific. These messages can be configured to run at the end of filling up a form, at scheduled times or based on a time that is derived from a form field.
Top level solution
There will be a new module - AvniMessagingService. This service will take in requests to send a message to a beneficiary at a specific point in time. It will also sync HSM messages from Glific, and provide mechanisms to store rules that map parameters in an HSM message to variables available in Avni.
MessagingService will have its own domain and java module that will not be related to Avni.
All messages to be sent are saved in a message_queue that will be evaluated and executed separately.
Templates will be evaluated at the last responsible moment to prevent problems due to change in values
Each rule will have 2 parts - scheduleRule and runRule. The scheduleRule helps figure out the time when a rule needs to be evaluated and sent. The runRule will evaluate the template.
Sample API for AvniMessagingService
AvniMessagingService.processEvent(Event e) where Event contains a type (ProgramEnrolment, ProgramEncounter, Individual), state (Create, Delete) and an identifier (id of the object)
AvniMessagingService will have APIs for CRUD of groups, group members etc that will be called by the webapp or integration service API
AvniMessagingService will have a scheduled job that sends all relevant messages
API in AvniService
AvniService.getSchedule(String rule, EntityType entityType, EntityIdentifier entityIdentifier). This will call rules-server and return results
AvniService.runRules(String rule, EntityType entityType, EntityIdentifier entityIdentifier). This will call rules-server and return results
Objective
By the end of this epic, Avni should be able to send HSM templated Whatsapp messages to Glific. These messages can be configured to run at the end of filling up a form, at scheduled times or based on a time that is derived from a form field.
Top level solution
There will be a new module - AvniMessagingService. This service will take in requests to send a message to a beneficiary at a specific point in time. It will also sync HSM messages from Glific, and provide mechanisms to store rules that map parameters in an HSM message to variables available in Avni.
Sample API for AvniMessagingService
API in AvniService
Data model available here - https://dbdiagram.io/d/6228ad1661d06e6eadcf53d1"