Skip to content

Commit

Permalink
Update inbound call logic for Laos
Browse files Browse the repository at this point in the history
  • Loading branch information
samnang committed Dec 17, 2024
1 parent c769241 commit 6e4355a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/models/call_flow_logic/ews_laos_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def full_name_lo

District = Struct.new(:code, :province, :name_en, :name_lo, keyword_init: true) do
def address_en
[full_name_en, province.full_name_en].join(", ")
[ full_name_en, province.full_name_en ].join(", ")
end

def address_lo
[full_name_lo, province.full_name_lo].join(" ")
[ full_name_lo, province.full_name_lo ].join(" ")
end

def full_name_en
Expand All @@ -33,7 +33,7 @@ def full_name_lo
CHAMPASAK = Province.new(code: "16", iso3166: "LA-CH", name_en: "Champasak", name_lo: "ຈຳປາສັກ")
ATTAPEU = Province.new(code: "17", iso3166: "LA-AT", name_en: "Attapeu", name_lo: "ອັດຕະປື")

PROVINCE_MENU = [SALAVAN, CHAMPASAK, ATTAPEU].freeze
PROVINCE_MENU = [ SALAVAN, CHAMPASAK, ATTAPEU ].freeze

# https://en.wikipedia.org/wiki/Districts_of_Laos
DISTRICTS = [
Expand Down Expand Up @@ -181,7 +181,7 @@ def gather(&_block)
end

def play(filename, response, language_code: "lao")
key = ["ews_laos_registration/#{filename}", language_code].compact.join("-")
key = [ "ews_laos_registration/#{filename}", language_code ].compact.join("-")
response.play(url: AudioURL.new(key: "#{key}.mp3").url)
end

Expand Down Expand Up @@ -238,6 +238,12 @@ def persist_district
def update_contact
contact = phone_call.contact
district = DISTRICTS.find { |d| d.code == phone_call_metadata(:district_code) }

contact.addresses.find_or_create_by!(
iso_region_code: district.province.iso3166,
administrative_division_level_2_code: district.code,
)

registered_districts = contact.metadata.fetch("registered_districts", [])
registered_districts << district.code
registered_districts.uniq!
Expand Down
4 changes: 4 additions & 0 deletions spec/models/call_flow_logic/ews_laos_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ module CallFlowLogic
"latest_address_en" => "Paksong District, Champasak Province",
"latest_address_lo" => "ເມືອງປາກຊ່ອງ ແຂວງຈຳປາສັກ"
)
expect(contact.addresses.last).to have_attributes(
iso_region_code: "LA-CH",
administrative_division_level_2_code: "1604",
)
assert_play("registration_successful-lao.mp3", response)
end

Expand Down

0 comments on commit 6e4355a

Please sign in to comment.