Get information about the phone number of a carrier or caller with Twilio.
### How this function works
Use this function to get information about the phone number of a carrier or caller. The function will be triggered by a document written to a specified Cloud Firestore collection. The document must contain the phone number and lookup type.
### Prerequisites
- You must have previous knowledge of **Firestore**.
- You must have previous knowledge of **Twilio**.
### Function details
In order to complete the installation process, you must add the required info to the form with the following parameters from your Twilio account:
- TWILIO_ACCOUNT_SID: The Account SID, a unique key that Twilio uses to identify the user.
- TWILIO_AUTH_TOKEN: The token to grant access to Twilio services.
- PHONE_NUMBER_ACCESSOR: The name of the field in the Firestore document that will contain the phone number.
The following is an example of how to use this function with `phoneNumber` as the name of the PHONE_NUMBER_ACCESSOR field:
```
{
phoneNumber: '+15108675310',
lookupType: ['carrier','caller-name'],
}
```
Whenever you write a document to the specified Cloud Firestore collection, this function does the following:
- Retrieves additional information about a phone number using Twilio Lookup API.
- Adds the additional information about a phone number to a separately specified field **lookupResponse** in the same document.
The **lookupResponse** should appear in the document with the following structure:
```
lookupResponse: {
"caller_name": {
"caller_name": "Delicious Cheese Cake",
"caller_type": "CONSUMER",
"error_code": null
},
"carrier": {
"error_code": null,
"mobile_country_code": "310",
"mobile_network_code": "456",
"name": "verizon",
"type": "mobile"
},
"country_code": "US",
"national_format": "(510) 867-5310",
"phone_number": "+15108675310",
"add_ons": null,
"url": "https://lookups.twilio.com/v1/PhoneNumbers/+15108675310"
}
```
>Note that if the **phoneNumber** or **lookupType** of the document is updated, then the information will be automatically updated, as well.
### Resources
For more information about Twilio, see:
- [Twilio Lookup API Documentation](https://www.twilio.com/docs/lookup/api)
- [Twilio Support](https://console.twilio.com/?frameUrl=/console/support)