Location Message

This page describes where to use and find a location message type

What is a location message?

A location message is a message type that allows you to ask the user for their location. The user will then be able to open up a map and submit their location, or drag the map to whatever location they want to submit

A user can click the button at the bottom to open a map
Example of the map view where a user can select their location
An example of a message when a user has submitted their location

When to use location messages

A location message is best used when you need to get the users exact location, for example when having them input their personal data such as address. It could also be used if the user is having a problem, such as a car breakdown, and needs to share where they are in order to get help.

How to create a location message

Via the custom message in Message Editor

Navigate to the Message Editor and create a Custom Message. Copy the XML snippet at the bottom of this page into the black box, or select location-message from the drop down, and your chat message will appear in the Preview panel.

Fill in the template with the properties of your particular message and when you are happy with it make sure to save your message and test it in the Test Preview chat window.

How to create a location message in the custom message block

XML Snippet

<location-message>
    <text>text</text>
    <callback>callback</callback>
    <attribute_name>location</attribute_name>
    <api_key>google_maps_api_key</api_key>
</location-message>

How to use location messages

Storing, Retrieving and Displaying Location Information

Location information is stored in an attribute of type Location. If you haven't configured a new attributes then you could use a built-in attribute called Location (which is also of type Location). Alternative you can create a new attribute and set the type to Location.

Creating an attribute of type attribute

Once you've create the new attribute set that attribute name in the XML mentioned above.

Once a user has submitted some location information this is stored in an attribute of type Location. The structure of the information stored is as the example below:

user_address: {
    "formatted_address":"31 Ufford St, London SE1 8LJ, UK", 
    "postal_code":"SE1 8LJ", 
    "line_1":"31", 
    "line_2":"Ufford Street", 
    "province":"England", 
    "country":"United Kingdom", 
    "lat":51.50252510000001, 
    "lng":-0.1060668 
}

The attribute is called user_address in this case.

In order to display some of this information back to the user (for example, in order to ask them to confirm it), you can access the various fields in the following format from within a message

Ok - we have your new address as {user.new_address['formatted_address']}. 
Is this correct?

Please pay attention to how formatted_address is enclosed in single quotes and square brackets. You can access any of the components of the address in the same way.

How to construct a location message

When structuring a message, you are able to use multiple different message blocks together to create the message that you are looking for. However, when it comes to ordering and structing these, there are some rules that need to be followed. To learn more about this, please head to the Constructing Messages page for more information.

For all message types, a key element to take into consideration is Accessibility, especially for messages that include customisation with multimedia types such as buttons, images and links. For all information on accessibility within OpenDialog, please click here.

Last updated