areacode

Summit Area Code Lookup Library.

This utility can be used to get state information by supplying an area code. It will return a table that contains the full name and abbreviation of the state. It is for North American numbers only.

Functions

Name Summary
areacode_to_state

Get state information from an areacode.

Functions : areacode

areacode_to_state(areacode)

Get state information from an areacode.

Parameters
Name Type Default Summary

areacode

string

The area code for which you would like to determine the state

Returns
Type Summary

table

Information about the provided area code

Return Table 1
Name Type Summary

abbr

string

Abbreviation of the state

name

string

Full name of the state

Usage
-- Example is for North American numbers

local log = require("summit.log")
local areacode = require("summit.areacode")

channel.answer()

-- The ANI will be e164 encoded (includes country code) so we get the substring
-- starting with the 3rd character for North American numbers
local caller = string.sub(channel.data.ani, 3)

-- Now we get the substring of the first 3 characters of our 10-digit North American number
local caller_area_code = string.sub(caller, 1, 3)

-- Now we use the `areacode` library to get the caller's state
local caller_state = areacode.areacode_to_state(caller_area_code)

-- Insert spaces between characters for playing back the phone number and area code using TTS
-- so it will sound like a phone number. This will also add a `.` to create a natural pause while
-- playing it back (e.g. "5551239999" will be converted to "5 5 5. 1 2 3. 9 9 9 9")
local pattern = "(%d%s%d%s%d)"
local number_spaced = string.gsub(caller, "%d", "%1 "):gsub(pattern, "%1.", 2)
local area_code_spaced = string.gsub(caller_area_code, "%d", "%1 "):gsub(pattern, "%1.")

log.info('Caller number as string for TTS: '..number_spaced)
log.info('Caller area code as string for TTS: '..area_code_spaced)

channel.say("Hello, I see you are calling from, "..number_spaced)
channel.say("Your area code is, "..area_code_spaced)
channel.say("It looks like you are calling from, "..caller_state.name)

log.info("The caller is calling from state: "..caller_state.name)

-- New York
local state = areacode.areacode_to_state("212")
log.info("Area code 212 is for "..state.name..", ("..state.abbr..")")

-- This will be nil
log.info(areacode.areacode_to_state('800'))

channel.say("Goodbye")
channel.hangup()