Play options¶
By default, Alan AI can respond or execute a command specified in the play()
function only when the AI agent button in the client app is activated. To change this behavior, pass the opts()
parameter to the play()
function. This parameter allows you to specify one or more play settings that determine how the AI agent must behave when the play()
function is executed.
You can define the following options:
Option |
Action type |
Agent type |
Description |
---|---|---|---|
|
command |
AI Chat, voice agent |
Execute a command even if the AI agent button is not activated in the client app |
|
command |
AI Chat, voice agent |
Activate the AI agent button in the client app before a command is executed |
|
response, command |
AI Chat, voice agent |
Deactivate the AI agent button in the client app after a response is given or command is executed |
|
response |
AI Chat |
Allow displaying markdown-formatted text in responses |
|
response |
AI Chat |
Disable voice output for responses |
Assume you want to allow users to set a timer using Alan AI Chat on a web page. The AI agent should behave in the following way:
When the timer is set, the AI agent sends a confirmation message.
When the timer expires, an alert is displayed and the AI agent sends a message:
Time is up
.
intent('Set a 1-minute timer', p => {
p.play('Sure, 1 minute, starting now');
setTimeout(() => {
p.play({command: 'stopTimer'}, opts({force:true}));
p.play('Time is up');
}, 60000)
})
<script>
var alanBtnInstance = alanBtn({
key: "YOUR-ALAN-AI-KEY",
onCommand: function (commandData) {
if (commandData.command === "stopTimer") {
alert('Timer is up')
}
},
rootEl: document.getElementById("alan-btn"),
});
</script>