Context variables

Context variables

We recommend to use frontend injected variables only to handle non-sensitive context data.

Usage in the Solvemate Web App

Setup in Solvemate Web App

To set up a new Context variable in Solvemate Web App:

  1. Go to Workspace > Variables
  2. To add new variable click on Context Variable button
  3. Enter name of the new variable and press Enter
  4. Variable is created and available to be used
Add context variable
The names for the variables set in the Web App (here website_location ), also need to be the names of the variables being used in the script.

Variable usage

There is a special format to use variables in Solution, Question, Custom texts and/or configurations in the Web App: ${variable_name|fallback text}.

  • Starts with a dollar $ sign
  • Is surrounded by curly braces { }
  • Has optional fallback text after |
Variable syntax

Fallback text

Optional fallback text can be set for each variable in case it doesn’t have any value.

If fallback text is not specified and variable is not injected or has no value - it will be left blank in the texts displayed in the Widget.

  • Fallback text should not be surrounded by quotes

Technical Implementation

Inject variables from the frontend into the Widget

Injecting variables from the frontend is possible with a function solvemate('contextVariables', {'variable_name': variable_value}); in Solvemate integration script.

An example of Solvemate integration script with Context variables:

	<!-- Solvemate -->
	<script>
	(function(s,o,l,v,e,m,a,t){t='solvemateConfig';s[e]=s[e]||function(x,y)
	{(s[t]=s[t]||{})[x]=y;};a=o.createElement(l);a.async=1;a.src=v;o.body.appendChild(a);
	})(window,document,'script','');	
	
	solvemate('projectID', project_id);

	solvemate('contextVariables', {
        'website_location': webLocation,
		'current_url': documentUrl,
		'browser_language': browserLanguage,
	})
	</script>
	<!-- End Solvemate -->
The names for the variables used in the script (here website_location , current_url and browser_language), also need to be the names of the variables being used in the Web App.

Note:

  • variable values can be updated during a conversation,
  • nested variables are not supported,
  • these variables are neither signed nor encrypted.

Mobile apps (Expert page)

If the bot is integrated not only on a website but also in a mobile app by rendering Widget (hosted on expert.solvemate.com) in a webview, as of now, injecting Context variables is not possible.

In case Context variables are set up in the Web App only Fallback texts will be displayed in the Widget accessed from the mobile app.

To overcome this limitation and use Context variables from the mobile app, we recommend:

  • set up a blank page to render in a Webview
  • place the Widget script including the variables so that the values are passed into the Widget