> For the complete documentation index, see [llms.txt](https://more-about-angular.gitbook.io/artyom-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://more-about-angular.gitbook.io/artyom-js/api/untitled-17.md).

# on

artyom.on 方法是 artyom.addCommands的等价代替，其仅仅是作为语法糖存在。对于只有几个命令将会被使用的 artyom 项目中，该方法将会更加便利。

{% hint style="info" %}
该方法并不是基于Promise的实现，其仅仅是对 artyom.addCommands 函数的二次封装。作为第一个参数，需要提供commands的indexs属性，它将返回一个对象，该对象的then属性是一个函数。触发该函数并提供一个函数作为第一个参数，函数接受下标信息（数组中与命令匹配的项的索引）和通配信息。
{% endhint %}

## 普通的command

```javascript
let artyom = new Artyom();

artyom.on(['Good morning','Good afternoon']).then(function(i){
    switch (i) {
        case 0:
            artyom.say("Good morning, how are you?");
        break;
        case 1:
            artyom.say("Good afternoon, how are you?");
        break;            
    }
});
```

## smart command

如果你希望创建一个smart command，需要将on 函数接受的第二个参数设定为true：

```javascript
artyom.on(['Repeat after me *'] , true).then(function(i,wildcard){
    artyom.say("You've said : " + wildcard);
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://more-about-angular.gitbook.io/artyom-js/api/untitled-17.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
