Address.dev docs

Technical Docs

Get Country Code Function:

Use this function to search for and return details about the country code a customer responds with. The country field will send a two digit country code or a country name. Use the “Chatbot Receives Attribute” block to allow a customer to send your chatbot a country code. The response from the countryCode function will include details about the country based on that country code.

Store the response code in another attribute and the data in a countryResponseData attribute with the $ path. Store the $.countryCode.alphaTwoCode back to the countryCode attribute to ensure you’ve got a valid two digit code in uppercase ready to use.

Get Allowed Fields function:

Once you obtain a valid CountryCode from the GetCountryCode function, pass this to the Get Allowed Fields function. This will return all the fields required to have a valid address for that country. The response can be stored to another JSON attribute with the path $. The response is JSON. Use a code block which will then parse this response and setups the attributes needed in case the information from the customer is needed afterwards.

const allowedFieldsResponse = attributeApi.get("allowedFieldsResponse");
attributeApi.set("isAddressLineOneRequired", allowedFieldsResponse?.validation?.addressLineOne === "required");
attributeApi.set("isAddressLineTwoRequired", allowedFieldsResponse?.validation?.addressLineTwo === "required");
attributeApi.set("isCityRequired", allowedFieldsResponse?.validation?.city === "required");
attributeApi.set("isCompanyNameRequired", allowedFieldsResponse?.validation?.companyName === "required");
attributeApi.set("isIsoCountryCodeRequired", allowedFieldsResponse?.validation?.isoCountryCode === "required");
attributeApi.set("isPostalCodeRequired", allowedFieldsResponse?.validation?.postalCode === "required");

You can then build out a chat bot like the example included to have the chatbot ask for relevant fields.

Validate Address Function:

Once the chatbot has received values for all of the required fields from the previous Get Allowed Fields Function, the chatbot will be ready to validate the address and ensure the values for each field are valid. For each attribute setup the request to the Validate Address function. The response is very simple, with a 200 meaning it’s a valid address or a 400 meaning bad address. Setup a condition on this response code based on 200 or else.

Contact us!

If you need help with address.dev or you have any questions about our solution, don't hesitate to reach out to us!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.