Advanced Configuration

setExtensionState

There is an additional, code only action available to AI Assistants, setExtensionState. This is leveraged in combination with custom UI Extensions that can be built and embedded into the right hand side of the messaging console.

examples

In this example, we'll look at a simple example that looks for customer information being shared, in this case email, and offers to add that to their contact information:

A simple setExtensionState examples

A simple setExtensionState example

def suggest_set_email(context):
  email = context['prompts']['get-email']['completion']['email']
  
  action = {
    "message": f"I've recognized the customers email as {email}. Would you like me to set that in the contact information?",
    "action": "setEmail",
    "data": email
  }
  
  actions = []
  actions.append({"action": "setExtensionState", "state": {"suggestedAction": action }})

  return {"actions": actions}

And here is the code that the UI extension would use to use that extension state:

 Quiq.on('assistStateChanged', function(data) {
   if(data.assistState.extensionState && data.assistState.extensionState.suggestedAction)
   {
     suggestedAction = data.assistState.extensionState.suggestedAction
     if(suggestedAction.action != "setEmail" || !stopsuggestingemail) {
       actionData = suggestedAction.data
       action = suggestedAction.action
       document.querySelector("#suggestion-details").innerHTML = suggestedAction.message

       document.getElementById("process-div").style.display = "block"
     }
   }
 })