Boosting Automated conversations with Embedded Elixir (EEx)
Akhilesh Negi
July 22, 2021

It’s been around one and a half years since we started working on an open-source project named Glific that would empower communication and help NGOs deliver their programs digitally and manage communication with their beneficiaries at scale. 

One of the core features of Glific is the integration of FlowEditor which helps in creating custom step by step flow to automate conversations while also saving user’s responses like name, age, gender, etc as contact fields, which helps NGOs greatly to deliver their programs to a significantly large number of beneficiaries.

Digital Green and their vision:

With our newest partnership with DigitalGreen aims at supporting smallholder Chilli farmers in Andhra Pradesh by helping them with preventive steps from Leaf Curl, a plantation disease, and curation steps if their crop is already manifested with the disease during the crop cycle.

Advisory messages need to be sent twice a day on a defined time slot and as the crop stage is determined by a number of days since sowing, preventive and curative steps for the crop varies with the different stage crop is in, therefore it requires some computation to determine crop stage based on the day the farmer joined the program, initial crop stage, the climatic condition of nearby area and condition of the crop.

Through our calls and discussion, we listed down their requirements:

  1. Ability to capture the day farmer enrolled and the current stage of the crop
  2. Computing the number of days since the date of enrollment and determining crop stage
  3. Sending preventive/ curative steps based on crop stage and status of crop if it is infected
  4. Compute time till the next slot when the message needs to be sent

As we started creating their flows, we figured out that we need to tweak the FlowEditor a bit in order to support DigitalGreen’s need as in FlowEditor replies were sent based on the user’s response but now we need automated replies based on the crop stage and climatic condition of the nearby area on defined time slots.

Revising automated conversation

Capturing the datapoints: We researched and planned possible scenarios on how we can update Flow editor, and decided to use EEx support in Flow editor, allowing embedding Elixir code inside Flow Editor. With EEx we were able to capture the day the farmer enrolled and the crop stage.

With the enrolled date and crop stage set, next, we need to compute the number of days since farmers enrolled and categorize them in different stages based on days.

Categorizing Farmers based on different stages: For categorizing, we added support in Flow Editor to call an Elixir function, which was an extension to Flow Editor’s inbuilt Call-Webhook.

With Call-a-Function we can call a particular elixir function of our codebase with contact fields like enrolled day, crop stage, etc as function arguments to compute the total days of the crop to update crop stage and categorize.

Based on different crop stages we add farmers to different collections in Glific.

Sending Timely Advisory stepsFor sending preventive/ curative steps on a timely basis, we used Glific’s other feature: Triggers which lets you send recurring messages at a scheduled time.

For the last piece of the puzzle, we added a dynamic wait for a response to wait till the next time slot to send the message when in a flow in case there is no response from the user’s end.

As speech-based conversations have several potential benefits for farmers, we will be integrating audio to text translation with help from Navana Tech to help farmers to communicate more easily with bot

With Glific, we try to solve most of the NGO’s needs right out of the box and are always happy to hear back from the community and their needs, to make Glific a better fit.