onConnectionStatus handler

Responsible for handling the connection status to the AI agent project in the Alan AI Cloud.

Depending on the current connection state, the Alan AI Cloud returns one of the following statuses:

  • authorized: a request to connect to the AI agent project is authorized

  • auth-failed: a request to connect to the AI agent project is not authorized

  • connected: a connection to the AI agent project in the Alan AI Cloud is established

  • disconnected: a connection to the AI agent project in the Alan AI Cloud is closed

  • invalid-auth-response: an invalid authentication response is received

Note

At present, the onConnectionStatus handler is supported only for the Web platform (including cross-platform frameworks, for example, Ionic).

Examples

Client app
alanBtn({
  key: 'YOUR_KEY_FROM_ALAN_STUDIO_HERE',
  host: 'v1.alan.app',
  onConnectionStatus: function(status) {
    console.log("The status is " + status);
  },
});

Ionic Angular

Client app
this.alanBtnComponent.nativeElement.addEventListener('connectionStatus', (data) => {
  const connectionData = (<CustomEvent>data).detail;
  console.info('Received status: ', connectionData);
});

Ionic React

Client app
alanBtnComponent.current.addEventListener('connectionStatus', (data: CustomEvent) => {
  const connectionData = data.detail;
  console.info('Received status: ', connectionData);
});

Ionic Vue

Client app
<ion-content :fullscreen="true">
  <alan-button v-on:connectionstatus="connectionstatus" alan-key="YOUR_KEY_FROM_ALAN_STUDIO_HERE" />
</ion-content>

export default defineComponent({
  methods: {
    connectionstatus: function(data:any) {
      console.info('Received status: ', data.detail);
    }
  },
});