Sending SMS to landlines causes failed deliveries and unnecessary charges, a problem that Twilio’s Lookup v2 API solves by identifying phone number types. The API’s line_type_intelligence field returns a classification such as “mobile” or “landline”, enabling applications to filter out non-mobile numbers before sending an SMS. This Go tutorial loads Twilio credentials from a .env file and uses Go 1.23’s iter package to create a custom iterator over a phone number list. Within the iterator, each number is validated by calling FetchPhoneNumber with the line_type_intelligence parameter, and if the type is not “mobile” or the call fails, the number is skipped. Only mobile numbers are then passed to the sendSMS function, which sends the message using the Twilio Go helper library’s CreateMessage, and the terminal finally logs each success or identifies a skipped landline.
Context
Developers sending SMS from applications often have lists of phone numbers that include both mobile and landline numbers. Sending an SMS to a landline results in a failed delivery and still incurs a cost. Twilio’s Lookup v2 API provides a way to check the line type of a phone number before sending, allowing developers to filter out landlines programmatically.
Approach / What changed
Use Twilio’s Lookup v2 API with the line_type_intelligence field. In Go, create a custom iterator using the iter package from Go 1.23. For each phone number, call client.LookupsV2.FetchPhoneNumber with params.SetFields(“line_type_intelligence”). Check the response’s LineTypeIntelligence.Type field; if not “mobile”, skip the number. Only pass mobile numbers to the sendSMS function, which uses Twilio’s Go helper library to send an SMS via CreateMessage. Load Twilio credentials from a .env file using godotenv.
Takeaways
1
Twilio’s Lookup v2 API line_type_intelligence field returns the phone number type as “mobile” or “landline”, allowing programmatic filtering.
2
Using Go’s iter package, you can create a custom iterator to filter a slice while making API calls and handling errors within the iteration.
3
Filtering out landlines before sending SMS prevents charges for failed deliveries and reduces application errors.
FAQ
How does the Lookup v2 API identify phone number types?
It uses the line_type_intelligence field. When you call FetchPhoneNumber with params.SetFields("line_type_intelligence"), the response includes a LineTypeIntelligence.Type property that returns values such as "mobile" or "landline".
What Go version and packages are required?
Go 1.23 or above is needed for the iter package. The project uses the twilio-go helper library and godotenv to load environment variables.
How are errors handled when looking up a number?
If the FetchPhoneNumber call fails, the code uses continue to skip that number entirely, preventing an SMS from being sent to an unverifiable number.
The Branded Calling trust chain, layer by layer: how identity, STIR/SHAKEN attestation, Rich Call Data, and carrier delivery combine so a verified brand name reaches the recipient's screen.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.