Zenera Logo

With authData, you can send a JSON object with any configuration or authentication parameters from the client app to the dialog script. For example, you may want to pass user's credentials, device ID or other data required by your dialog script logic.

Unlike visual state that has a dynamic nature and can be altered at any moment of the dialog session with the setVisualState() method, authData is sent only once, when the Alan AI SDK connects to the dialog script. For this reason, you should use it to share static device- or user-specific data. On the dialog script side, the passed data is accessible through Alan AI's p.authData runtime object.

In the example below, a user's token is sent from the client app to the dialog script. The token is written to Alan AI Studio logs when a new dialog session with the user is started.

onCreateUser(p => {
    console.log(`A user has connected with token ${p.authData.token}`);
});
// Specifying a user's token in the app
var userToken = {
  "token": "demo"
}

var alanBtnInstance = alanBtn({
  key: "YOUR_KEY_FROM_ALAN_STUDIO_HERE",
  // Passing the token
  authData: userToken,
  onCommand: function(commandData) {
    if (commandData.command === "go:back") {}
  },
  rootEl: document.getElementById("alan-btn")
});