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 |
---|---|
Fired when Alan connects to the voice project and is ready to listen to the user’s input |
|
Fired when the user clicks the voice assistant button in the app |
|
Fired when a prompt to allow access to the microphone is displayed |
|
Fired when the user allows access to the microphone |
|
Fired if the user activates the voice assistant for the first time during the dialog session |
|
Fired when a popup next to the Alan button is displayed |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Boolean |
Access to microphone during the dialog session: allowed ( |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
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 |
---|---|---|
|
String |
Event name: |
|
Integer |
Number of interactions with the user |
|
Integer |
Timestamp of the last connection to the voice assistant |
|
Integer |
Timestamp of the last interaction with the voice assistant |
|
Integer |
Number of recognized user’s interactions |
|
Integer |
Number of unrecognized user’s interactions |