User events¶
Alan AI emits several types of events triggered by users’ interactions with the AI agent. You can listen to these events with the onUserEvent callback.
Note
The user statistics is updated after the user dialog session is closed.
Types of events¶
Event name |
Description |
---|---|
Fired when the user clicks the AI agent button in the app |
|
Fired when Alan AI connects to the AI agent project and is ready to listen to the user’s input |
|
Fired when the user activates the AI agent for the first time during the dialog session |
|
Fired when the user clicks the AI agent button for the first time during the dialog session |
|
Fired when the user allows access to the microphone |
|
Fired when a prompt to allow access to the microphone is displayed |
|
Fired when the user clicks the close icon in the Alan AI button popup |
|
Fired during and upon the user’s input recognition |
|
Fired when a popup next to the AI agent button is displayed |
In the example below, the AI agent listens to the firstActivate
event and, if the last interaction with the user occurred earlier than one day ago, plays a greeting to the user.
function diffFrom(ts, units) {
let last = DateTime.fromMillis(ts);
let now = DateTime.local();
console.log(`now.diff(last): ${now.diff(last)}`);
console.log(`units: ${units}, now.diff(last).as(units): ${now.diff(last).as(units)}`);
return now.diff(last).as(units);
}
onUserEvent((p, e) => {
console.info('event', JSON.stringify(e));
if (e.event == 'firstActivate') {
if (diffFrom(e.userInfo.lastInteractionTs, 'days') > 1) {
p.play('Hi, I am Alan, your AI agent. Ask any question or tell me what you would like to do');
}
}
});
buttonClicked event
Fired when the user clicks the AI agent button in the app.
{
"event": "buttonClicked",
"micAllowed": false,
"ts": 1666259901446,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259897357
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Boolean |
Access to microphone during the dialog session: allowed ( |
|
Integer |
Timestamp of when the AI agent button was clicked |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
buttonReady event
Fired when Alan AI connects to the AI agent project and is ready to listen to the user’s input.
{
"event": "buttonReady",
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 0,
"lastConnectTs": 1666259897357
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
firstActivate event
Fired when the user activates the AI agent for the first time during the dialog session.
{
"event": "firstActivate",
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259138126
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
firstClick event
Fired when the user clicks the AI agent button for the first time during the dialog session.
{
"event": "firstClick",
"ts": 1666259398408,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259395336
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the AI agent button was clicked for the first time |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
micAllowed event
Fired when the user allows access to the microphone.
{
"event": "micAllowed",
"ts": 1666259399772,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259395336
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the microphone access was allowed |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
micPermissionPrompt event
Fired when a prompt to allow access to the microphone is displayed.
{
"event": "micPermissionPrompt",
"ts": 1666259901443,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259897357
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the prompt was displayed |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
recognized event
Fired during and upon the user’s input recognition. The event description contains an interim or final result for the interpreted user’s phrase and the recognition state in the final
field:
If the user’s input is still being recognized, the
final
field value isfalse
.If the user’s input has been recognized, the
final
field value istrue
.
{
"event": "recognized",
"final": false,
"text": "hello",
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666257658614
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Boolean |
User’s input recognition state: final ( |
|
String |
Interim or final result for the interpreted user’s input |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
popupCloseClicked event
Fired when the user clicks the close icon in the popup displayed next to the AI agent button. For details, see Alan AI button popups.
{
"event": "popupCloseClicked",
"ts": 1666259141166,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259138126
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the close icon was clicked |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
showPopup event
Fired when a popup next to the AI agent button is displayed. For details, see Alan button popups.
{
"event": "showPopup",
"ts": 1666259141166,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259138126
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the popup was displayed |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
Event name |
Description |
---|---|
Fired when Alan AI connects to the AI agent project and is ready to listen to the user’s input |
|
Fired when the user clicks the AI agent button for the first time during the dialog session |
|
Fired when the user allows access to the microphone |
|
Fired when a prompt to allow access to the microphone is displayed |
|
Fired during and upon the user’s input recognition |
In the example below, the AI agent listens to the firstClick
event and, if the last interaction with the user occurred earlier than one day ago, plays a greeting to the user.
function diffFrom(ts, units) {
let last = DateTime.fromMillis(ts);
let now = DateTime.local();
console.log(`now.diff(last): ${now.diff(last)}`);
console.log(`units: ${units}, now.diff(last).as(units): ${now.diff(last).as(units)}`);
return now.diff(last).as(units);
}
onUserEvent((p, e) => {
console.info('event', JSON.stringify(e));
if (e.event == 'firstClick') {
if (diffFrom(e.userInfo.lastInteractionTs, 'days') > 1) {
p.play('Hi, I am Alan, your AI agent. Ask any question or tell me what you would like to do');
}
}
});
buttonReady event
Fired when Alan AI connects to the AI agent project and is ready to listen to the user’s input.
{
"event": "buttonReady",
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 0,
"lastConnectTs": 1666259897357
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
firstClick event
Fired when the user clicks the AI agent button for the first time during the dialog session.
{
"event": "firstClick",
"ts": 1666259398408,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259395336
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the AI agent button was clicked for the first time |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
micAllowed event
Fired when the user allows access to the microphone.
{
"event": "micAllowed",
"ts": 1666259399772,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259395336
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the microphone access was allowed |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
micPermissionPrompt event
Fired when a prompt to allow access to the microphone is displayed.
{
"event": "micPermissionPrompt",
"ts": 1666259901443,
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666259897357
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Integer |
Timestamp of when the prompt was displayed |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |
recognized event
Fired during and upon the user’s input recognition. The event description contains an interim or final result for the interpreted user’s phrase and the recognition state in the final
field:
If the user’s input is still being recognized, the
final
field value isfalse
.If the user’s input has been recognized, the
final
field value istrue
.
{
"event": "recognized",
"final": false,
"text": "hello",
"userInfo": {
"interactions": 25,
"recognized": 25,
"unrecognized": 0,
"lastInteractionTs": 1666255324364,
"lastConnectTs": 1666257658614
}
}
Field name |
Data type |
Description |
---|---|---|
|
String |
Event name: |
|
Boolean |
User’s input recognition state: final ( |
|
String |
Interim or final result for the interpreted user’s input |
|
Integer |
Number of interactions with the user |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |
|
Integer |
Timestamp of the last interaction with the AI agent |
|
Integer |
Timestamp of the last connection to the AI agent |