Using Context and Variables in Flow

Flow can inject, evaluate or make use of many conversation variables in the canvas nodes. Below are some examples of the variables available to users.

When nodes support variables or context, the txt fields are a dropdown that can be changed to msg.

Intent Detection Node Example

When using the intent detection node, the response from the NLP will be set the payload.result object.

To get just the intent name, use payload.result.intent. Or to get the action associated with the intent, payload.result.action

Full response Example

msg :{
    payload :{
      result: {
        intent: 'intent_name',
        slots: {},
        action: {},
        fulfilment: 'message from NLP', //for a single response
        fulfillmentResponses: ['array', 'of', 'nlp', 'responses'],
        intentDetectionConfidence: 1
      }
    }
  }

BaaS API Example

When a BaaS node responds, data will be stored in a baas.[alias] object. Note that baasAlias will be replaced with whatever aliases you picked. Example object:

  msg :{
  baas :{
    baasAlias: {
      some: 'response',
      data: 'here'
    }
  }

}

Initial Context when Conversation is started

ServisBOT messenger sends a conversation start event whenever a conversation starts. The objects in this event are usable for adjusting your flows, especially the context values.

{
	"system": {
		"sessionId": "sessionid",
		"conversationId": "convoid",
		"organization": "organization",
		"identity": "identity",
		"region": "region",
		"bot": "botname"
	},
	"context": {
		"endpointData": {
			"Address": "endpointaddress",
			"Organization": "organization",
			"Useragent": "useragent",
			"EngagementType": "EngagementType",
			"Updated": 1573140377768,
			"TargetBotReference": "botName",
			"Status": "online",
			"AllowedDomains": "AllowedDomains",
			"anotherAllowedDomain",
			"Name": "Endpoint Name",
			"Created": 1573140377768
		},
		"correlationId": "correlationId",
		"version": "v2",
		"organization": "organization",
		"endpoint": "endpointaddress",
		"sbRegion": "sbRegion",
		"conversations": {
			"endpointAddress": "conversationid"
		  }
		}
	},
	"tenant": {},
	"user": {},
	"correlationId": "correlationId",
	"endpoint": "endpointAddress"
}

Example Message Payload

Every message back from a user will have similar data provided, but also have the user message provided as user.message

Storing additional data in user.message makes it available as $variables in flow.

{
	"system": {
		"sessionId": "sessionid",
		"conversationId": "convoid",
		"organization": "organization",
		"identity": "identity",
		"region": "region",
		"bot": "botname"
	},
	"context": {
		"endpointData": {
			"Address": "endpointaddress",
			"Organization": "organization",
			"Useragent": "useragent",
			"EngagementType": "EngagementType",
			"Updated": 1573140377768,
			"TargetBotReference": "botName",
			"Status": "online",
			"AllowedDomains": "AllowedDomains",
			"anotherAllowedDomain",
			"Name": "Endpoint Name",
			"Created": 1573140377768
		},
		"correlationId": "correlationId",
		"version": "v2",
		"organization": "organization",
		"endpoint": "endpointaddress",
		"sbRegion": "sbRegion",
		"conversations": {
			"endpointAddress": "conversationid"
		  }
		}
	},
	"tenant": {},
	"user": {},
	"correlationId": "correlationId",
	"endpoint": "endpointAddress",
	"user": {
		"message": "hello"
	}
}

Using Context to detect if a user is on a mobile device

Once a conversation has started meta data is gathered about the device the user is using to communicate with the bot. The meta data exposes a property called isMobile which is true if the user is on a mobile device (including a tablet), or false if the user is not on a mobile device. You can access this attribute in your flow under the payload.context.meta.isMobile key.

An example of the payload with the meta data looks like the following:

{
	"system": {
		"sessionId": "sessionid",
		"conversationId": "convoid",
		"organization": "organization",
		"identity": "identity",
		"region": "region",
		"bot": "botname"
	},
	"context": {
		"meta": {
			"isMobile": true
		}
	},
	"tenant": {},
	"user": {},
	"correlationId": "correlationId",
	"endpoint": "endpointAddress",
	"user": {
		"message": "hello"
	}
}

An example of a dialogue node using this attribute looks like the following:

Testing your flow

To test your flow is correctly using the isMobile attribute, you can do the following in the chrome dev console:

  • Open the chrome dev console
  • Open the chrome dev tools command menu, explained here: https://developers.google.com/web/tools/chrome-devtools/command-menu
  • Search for show network conditions, and select the option that’s available like this:
  • This will open a menu like the following:
  • Make sure the User agent Select automatically checkbox is not ticked.
  • From here select the mobile device you wish to use, and send a message to the bot.
  • The message you send will act like it was coming from a mobile device.
  • To switch back to your real device, tick the User agent Select automatically checkbox.

The example below shows a flow which prints out if a user is on a mobile device, the chrome console is setup to use an iPhone: