state Object
  • Updated on 17 Aug 2019
  • 3 minutes to read
  • Contributors
  • Print
  • Share
  • Dark
    Light

state Object

  • Print
  • Share
  • Dark
    Light

Description

The state Object is an abstraction layer that implements methods that expose the FrontM.js Capabilities Layer to App developers in a simpler way.

This object also carries the State of the entire conversation and helps the FrontM.js Abstraction Layer to control the flow of the Apps.

The state Object is instantiated by the platform and developers cannot create new instances.

Public Properties

_

This property is read only and contains the Lodash Javascript utilities.

lang

This property is read only and contains the language of the conversation.

developer

This property is an instance of the Developer Class, which is a helper task that exposes debugging and development utility methods and properties.

accounts

This property is an instance of the Accounts Class associated with the State.

orders

This property is an instance of the Orders Class associated with the State.

forms

This property returns an array containing all the forms active in the conversation. Each element is an instance of the Forms Class.

inError

This property is read only and returns the error status of the State: either true or false.

errorStack

This property stacks error messages, if the State is in error.

responsesArray

This property contains all the responses added during the Intent Validation process and Intent Resolution Process.

smartSuggestionsArray

This property contains the Smart Suggestions array generated by the Apps.

blockSmartSuggestions

This property can be set by the developers to stop the display of Smart Suggestions after the execution of a given Intent. It is reset after the Intent responses are processed.

userName

This property contains the user Object referring to the user currently logged in.

location

This property contains the location where the App is running.

messageTypes

This property returns an object with all the contents of the MessageTypeConstants Capability.

activeIntent

This property returns the name of the Intent being processed. It is used internally by the FrontM.js Abstraction Layer.

notification

This property is an instance of the Notification Class which is a helper class that exposes different methods and properties to deal with user notifications.

api

This property is an instance of the API Class which is a helper class that exposes different methods and properties to deal with third-party API access.

db

This property is an instance of the DB Class which is a helper class that exposes different methods and properties to deal with persistent storage.

messageFromUser

This property contains the message received by the App.

messageTypeFromUser

This property contains the message type received by the App.

Methods

defaultOnError()

This method calls the default onError closure in the system. It is usually used within the user-defined onError closures in Apps.

runFunctionOnceAnHour(f)

This method runs a function passed as a parameter once an hour. It is not a scheduler. When it is called, it first checks if the function was run during the last hour. If it was, the function is not run. It is usually used to offer greetings to users.

sendMessage(message)

This method sends a message to the current App. In future, this method will also be used to send messages to other Apps.

getUniqueId()

This method creates a unique single short UUID.

setField(name, value)

This method sets a value to a custom field and stores it within the State.

clearField(name)

This method clears a custom field value.

getField(name)

This method gets a custom field value.

addSmartSuggestion(smartSuggestionObject)

This method adds a Smart Suggestion object to the State, which will be displayed after the Intent processing is finished.

addSmartSuggetionsArray([smartSuggestionsObject])

This method adds an array of Smart Suggestion objects to the State.

addEnglishSmartSuggestions([suggestions])

This method adds English Smart Suggestions to the App. This method receives an array of strings as input.

clearSmartSuggestionsArray()

This method clears the Smart Suggestions array.

getForm(formId)

This method returns a Form Object identified by the passed Id. It returns null if the Form is not found.

addForm(formObject)

This method adds the Form Object pasted in the parameters to the State.

removeForm(formId)

This method removes the Form from the state Object.

addErrorToStack(code, message)

This method adds a user-defined error to the stack. Once an error is added, the state Object enters in (its instead of in?) error state.

clearError()

This method removes all errors from the stack.

addResponse(type, message)

This method adds a response message to the state Object.

addStringResponse(stringMessage)

This method adds a string response to the state Object.

clearResponseArray()

This method clears the response array.

Was this article helpful?