LocationState Class

class LocationState(name, opts)

A state which requests a location from the user, and sets the user data through getting the location data from the Google Maps API. It may also request a second prompt from the user to further refine the location if the first prompt wasn’t clear enough.

Arguments:
  • name (string) – name used to identify and refer to the state
  • opts.question (string_or_LazyText) – The question to first display to the user. Defaults to What is your address?.
  • opts.map_provider (an instance of :class:location.providers.utils.Provider) – The provider to use when searching for locations. Defaults to an instance of :class:location.providers.googlemaps.GoogleMaps.
  • opts.refine_question (string_or_LazyText) – The question to display to the user when selecting a location from a list if the first search query wasn’t clear enough. Defaults to Please select your location from the following:
  • opts.error_question (string_or_LazyText) – The question to display to the user when no locations are found for their search term. It will keep requesting until results are found. Defaults to Error: No results for your search term. Please try another search term.
  • opts.continue_session (boolean) – whether or not this is the last state in a session. Defaults to true.
  • opts.send_reply (boolean) – whether or not a reply should be sent to the user’s message. Defaults to true.
  • opts.next (function_or_string_or_object) – The state that the user should visit after this state. May either be the name of the next state, an options object representing the next state, or a function of the form f(content) returning either, where content is the input given by the user. If next is null or not defined, the state machine will be left in the current state. See State.set_next_state(). Defaults to null
  • opts.options_per_page (integer) – The maximum limit for the amount of choices on each page. Defaults to 8.
  • opts.characters_per_page (integer) – The maximum limit for the amount of characters on each page. Defaults to 160. Whichever one of characters_per_page or option_per_page is reached first will be chosen.
  • opts.next_text (string) – The text to display for the next page option. Defaults to Next.
  • opts.previous_text (string) – The text to display for the previous page option. Defaults to Previous.
  • opts.namespace (string) – The namespace to use when storing the contact details, ie. location:..... Defaults to location.
  • opts.events (object) – Optional event name-listener mappings to bind.

Example:

self.states.add('states:example-locationState', function(name){
    return new LocationState(name, {
        question: ["Welcome to the location app.",
            "What is your current address?"].join("\n"),
        next: "states:end",
        previous_text: "Prev",
    });
});

Each provider has its own .fixture(...) function for conveniently creating HTTP resource fixtures for its location queries. See the documentation for each provider on how to use these.