Chatlayer Documentation
Get in touchAbout Chatlayer
  • Welcome
  • What's new
  • Send feedback
  • start quickly
    • Leadzy tutorial
      • 0. Introduction
      • 1. New bot, new block
      • 2. Understand your users
      • 3. Collect and display user input
      • 4. Steer the conversation with Conditions
      • 5. Empower your bot with Actions
      • 6. Set up a channel and publish your bot
    • Templates
      • Banking
      • E-Commerce Returns
      • E-Bike Shop
      • E-Scooter Support
      • Feedback
      • Find Nearest Location
      • GPT
      • 🆕Gym
      • Job applications
      • Knowledge base AI template
      • Lead generation
      • 🆕NPS
      • Restaurant
      • Retail
  • navigation
    • Analytics
      • Dashboard
      • Customers
      • Conversations
      • User flow
      • Intents
      • 🆕Funnels [Beta]
    • Bot builder
      • Flows
        • Canvas functionalities
        • Collaborate with team members
        • Manage your flows
        • 🆕[Beta] Export and import flows
      • Bot dialogs view
      • Translations
      • Events
    • NLP
      • Dashboard
      • Intents
      • Expressions
      • Entities
      • Train
      • NLP settings
      • Improve
    • Knowledge base AI
      • Add content to your KBAI
      • Build your KBAI flow
      • Use your KBAI source URL in a button
      • Use tags to limit your KBAI content
      • 🆕Use Tables to store your KBAI questions
      • 🆕Manage handover where KBAI is unsatisfactory
    • History
      • Conversations
      • Execution logs
      • Versions
    • Channels
    • Tables
      • Create a table with records
      • Column types
      • Operate on your records
        • Insert record
        • Update record
        • Retrieve record
        • Delete record
      • API
    • Settings
      • Bot settings
      • Offloading
      • Variables
      • Voice
      • Import/Export
  • build your bot
    • Conversation design
      • Plan your bot
      • Conversation design workflow
    • Flow logic
      • Blocks
        • Message
        • Condition
        • Collect input
        • Action
      • Go-to connections
    • 🆕Emulator
    • Tips & best practices
      • Route your flow depending on the time
      • Improve the Not understood block
        • How to create better not understood messages
        • Not understood counter
        • Not understood Google search
      • Go to previous block
      • Recognizing a returning user
      • Skip introduction message
      • Route your flow depending on the channel
      • Reuse flows
      • Connect two bots to each other
  • understand users
    • Natural language processing (NLP)
      • Basic NLP concepts
      • Detect information with entities
        • Match entities
        • Contextual entities
        • System entities
        • Composite entities
      • NLP best practices
        • Word order and diversity of expressions
      • AI intent booster
      • Train your NLP
      • Context
      • NLP import & export
      • Sentiment analysis
    • Languages
      • Supported languages
      • Make your bot multilingual
      • Change language within the conversation
  • set up channels
    • Add a channel to your bot
    • All channels
      • 🚨Facebook Messenger [Deprecated soon]
        • Facebook Admin Removal
        • Facebook Webview Whitelisting
        • Facebook Messenger API updates for Europe
      • 🚨Google Assistant [Deprecated soon]
      • Webhook
      • Web
        • 🚨Web V1 [Deprecated]
          • Customize web widget
          • Live example web widget
        • 🆕Web V2
          • 🆕From Web V1 to V2
          • 🆕Web V2 methods and options
    • Sinch Conversation API
      • Configure your Sinch Conversation API
      • 🆕 Make the most of RCS with Carousels
      • WhatsApp Business API
  • integrate & code
    • API calls
      • Configure your API integration
      • Advanced API features
      • V1 API Reference
      • Custom integrations 101
    • Code editor
      • [Example] Sending data to Airtable (POST)
      • [Example] Retrieving data from Airtable (GET)
      • [Example] Making SOAP requests
    • App integrations
      • Airtable
      • Freshdesk
      • Freshdesk Messaging
      • 🆕Gmail
      • Intercom
      • Mailgun
      • OpenAI: GPT-3, ChatGPT and GPT-4
      • Salesforce
      • 🆕Slack
      • Topdesk
      • Zendesk Support
      • Zendesk Sunshine (beta)
    • 🆕Expression syntax
    • Human handover & live chat
      • Sinch Contact Pro
      • #Interact
      • Genesys Cloud
      • Offloading Webhook
      • Salesforce Service Cloud
      • Sparkcentral by Hootsuite
      • Zendesk Chat
    • Chatlayer messages specifications
  • Publish
    • Publish your bot
      • Publish a flow
  • Analyze & maintain
    • Analytics definitions
    • Data retention
    • Maintenance
    • Session
    • Track events for analytics
  • VOICE
    • 🆕Send bot response as audio
    • Voicebots
      • Create a voicebot
      • Voicebot-specific actions
      • Test your voicebot
      • From chat to voice
  • access & support
    • Identity & Access
      • Single Sign-On (SAML SSO)
    • Billing & subscription
    • Get in touch
    • Chatlayer glossary
    • SaaS Regions & IP Ranges
    • Status
    • Debug your bot
      • No correct response
      • Collect input not working
      • Video isn't working
Powered by GitBook
On this page
  • How to customise this template
  • Flow: General
  • Connect the flow to other flows

Was this helpful?

  1. start quickly
  2. Templates

Find Nearest Location

PreviousFeedbackNextGPT

Last updated 1 year ago

Was this helpful?

With this template, your customers can easily find your business' nearest branch by simply asking your chatbot! After asking the user for their address, the bot will look through an external database (Airtable) which contains the data for all your branch locations. Then it will calculate which location is closest to the user’s address by using the Google Maps API. Finally, the bot will show the result on Google Maps, within an iFrame.

Keep reading to learn how you can customise this template for your own organisation.

How to customise this template

Make sure to always after loading a template!

This template uses two third party services:

  1. Airtable, as a database for branch locations

  2. Google Maps API, for finding the user address

To let your bot interact with these services you will need an API key for each and configure these in the Action blocks where the bot makes the API calls.`

Setting up your own Airtable base

If you have not worked with Airtable before, you can sign up for free and learn the basics .

For each of your organisation's locations, your Airtable will need fields with the following information:

  1. Name of the branch

  2. Address

  3. Latitude

  4. Longitude

When you’ve newly imported the 'Nearest Location' template, it will automatically link to . Feel free to use it for testing, but make sure to replace it once you start using the bot for your own organisation!

Below is an overview of the key blocks in each flow of the bot. Here we will walk you through how to configure the connection with the Airtable and Google Maps APIs, as well as some other tips to customise this template for your business.

Flow: General

Block: Ask address

In this block, the bot asks the user for their address and saves the response as a variable: user_address.

Block: Locator

To make this template work, your bot needs to be able to access the location data of your branch locations (in Airtable) and look up the user’s address (using the Google Maps API).

This block uses a Code Action to call both the Airtable API and the Google Maps API with the Javascript code shown below. This code may look a bit intimidating, but don’t worry, you only have to change a few pieces of information!

const allStations = await fetch(`https://api.airtable.com/v0/(YOUR_BASE_ID)/(YOUR_TABLE_NAME)`, { 
headers: {
Authorization: `Bearer (YOUR_AIRTABLE_API_KEY)`
}
}).then(r => r.json());
let re = / /g; 

const currLoc = args.user_address.replace(re, '+');
let minDistance = Number.MAX_SAFE_INTEGER; 
let nearestShop;
const chatlayer = ChatlayerResponseBuilder(); chatlayer.addSessionVariable('currLoc', currLoc); 
const addressFromMaps = await fetch(`https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=${currLoc}&inputtype=textquery&fields=geometry&key=(YOUR_GOOGLEMAPS_API_KEY)`).then(r=> r.json()); 
const geoLocation2 = { 
Latitude: addressFromMaps.candidates[0].geometry.location.lat, 
Longitude: addressFromMaps.candidates[0].geometry.location.lng, 
} 
//const geoLocation2 = {Latitude : "52.5001278", Longitude : "13.3121555"}; allStations.records.forEach(station=>{ 
const geoLocation1 = station.fields;
const lat = geoLocation1.Latitude - geoLocation2.Latitude; 
const lon = geoLocation1.Longitude - geoLocation2.Longitude; 
 
const val = Math.sqrt(Math.pow(lat, 2) + Math.pow(lon, 2)); if(minDistance>val){ 
minDistance = val; 
closestLocation = geoLocation1;
}
});

closestLocation.Address = closestLocation.Address.replace(/ /g, ' ');
chatlayer.addSessionVariable('closestLocation', closestLocation);
chatlayer.addSessionVariable('addressFromMaps', addressFromMaps); chatlayer.send();----------------------------------

In this piece of code, you should customise the following three things:

  1. The Google Maps API key On line 13, replace (YOUR_GOOGLEMAPS_API_KEY) with your own Google API key.

Block: Give address

In this block, the bot shows the name and address of the closest location found in the database. The name is stored in the closestLocation.Name variable and the address in closestLocation.Address.

Block: Show location on map

In this block the bot shows the closest branch location on a map, within an iFrame. In the Source Field of the iFrame action, also replace (YOUR_GOOGLEMAPS_API_KEY) with your own Google API key.

Block: Clear user address

Finally, in this block the bot clears the variable user_address so the user can start the flow again and use another address.

Connect the flow to other flows

Now that you've added this new flow, make sure it connects to other flows. For example, if this is an important use case for your bot, make sure to mention it in the introduction.

That's it, now your bot can find locations nearest to the user's address! 👏

For more information on how to integrate Airtable into your bot, check out .

Managing your branch locations in another database? You can link any type of database to this bot, as long as it has an API. Read more about our API integrations .

The Airtable link In the url on line 1 of the code block, replace (YOUR_BASE_ID) with the ID of your own Airtable base and (YOUR_TABLE_NAME) with the name or ID of the table that contains your location data. You can find your Airtable's base and table IDs , or in the URL of your table view.

The Airtable API key In the url on line 3, replace (YOUR_AIRTABLE_API_KEY) with your own Airtable API key. You can find the API key on your .

update the NLP
here
here
this Airtable
this tutorial
here
here
Airtable account page
The Show location on map block with the part of the source URL to change highlighted in red