User events

Alan emits several types of events driven by users’ interactions with the voice assistant in the app. You can listen to these events with the onUserEvent callback and perform the activities needed for your voice assistant logic.

Event name

Description

buttonReady

Fired when Alan connects to the voice project and is ready to listen to the user’s input

buttonClicked

Fired when the user clicks the voice assistant button in the app

micPermissionPrompt

Fired when a prompt to allow access to the microphone is displayed

micAllowed

Fired when the user allows access to the microphone

firstActivate

Fired if the user activates the voice assistant for the first time during the dialog session

showPopup

Fired when a popup next to the Alan button is displayed

popupCloseClicked

Fired when the user clicks the close icon in the Alan button popup

In the example below, the voice assistant 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|Hi there|Hello), I am Alan, your voice assistant. Ask any question or tell me what you would like to do');
        }
    }
});

buttonReady event

Fired when Alan connects to the voice project and is ready to listen to the user’s input.

{
    event: 'buttonReady',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1617959169468,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: buttonReady

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

buttonClicked event

Fired when the user clicks the voice assistant button in the app.

{
    event: 'buttonClicked',
    micAllowed: false,
    userInfo: {
        interactions: 0,
        lastConnectTs: 1617959249642,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: buttonClicked

micAllowed

Boolean

Access to microphone during the dialog session: allowed (true) or denied (false)

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

micPermissionPrompt event

Fired when a prompt to allow access to the microphone is displayed.

{
    event: 'micPermissionPrompt',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1617959249642,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: micPermissionPrompt

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

micAllowed event

Fired when the user allows access to the microphone.

{
    event: 'micAllowed',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1617959249642,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: micAllowed

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

firstActivate event

Fired if the user activates the voice assistant for the first time during the dialog session.

{
    event: 'firstActivate',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1617959249642,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: firstActivate

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

showPopup event

Fired when a popup next to the Alan button is displayed. For details, see Alan button popups.

{
    event: 'showPopup',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1620807678212,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: showPopup

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions

popupCloseClicked event

Fired when the user clicks the close icon in the popup displayed next to the Alan button. For details, see Alan button popups.

{
    event: 'popupCloseClicked',
    userInfo: {
        interactions: 0,
        lastConnectTs: 1620807678212,
        lastInteractionTs: 0,
        recognized: 0,
        unrecognized: 0
    }
}

Field name

Data type

Description

event

String

Event name: popupCloseClicked

interactions

Integer

Number of interactions with the user

lastConnectTs

Integer

Timestamp of the last connection to the voice assistant

lastInteractionTs

Integer

Timestamp of the last interaction with the voice assistant

recognized

Integer

Number of recognized user’s interactions

unrecognized

Integer

Number of unrecognized user’s interactions