# 사용자 정의 자동화 만들기

**URL:** https://meta.discourse.org/t/create-custom-automations/275931
**Category:** Developer Guides
**Tags:** automation, how-to
**Created:** [8월 20, 2023, 2:57오후 UTC](https://meta.discourse.org/t/create-custom-automations/275931 "2023-08-20T14:57:33Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [8월 20, 2023, 2:57오후 UTC](https://meta.discourse.org/t/create-custom-automations/275931/1 "2023-08-20T14:57:33Z")

</div>

ℹ 이 문서는 초안이며 추가 작업이 필요할 수 있습니다.

### 용어

- **trigger** : 트리거의 이름을 나타냅니다. 예: `user_added_to_group`
- **triggerable** : 트리거와 관련된 코드 로직을 나타냅니다. 예: `triggers/user_added_to_group_.rb`
- **script** : 스크립트의 이름을 나타냅니다. 예: `send_pms`
- **scriptable** : 스크립트와 관련된 코드 로직을 나타냅니다. 예: `scripts/send_pms.rb`

#### 플러그인 API

```rb
add_automation_scriptable(name, &block)
add_automation_triggerable(name, &block)

```

#### 스크립터블 API

##### field

`field :name, component:`는 자동화 UI에 사용자 정의 값을 추가할 수 있게 해줍니다.

유효한 컴포넌트 목록:

```rb
# foo는 고유해야 하며 필드의 이름을 나타냅니다.

field :foo, component: :text # 텍스트 입력 필드를 생성합니다
field :foo, component: :list # 사용자가 값을 입력할 수 있는 다중 선택 텍스트 입력 필드를 생성합니다
field :foo, component: :choices, extra: { content: [{id: 1, name: 'your.own.i18n.key.path' }] } # 사용자 정의 내용을 가진 콤보 박스를 생성합니다
field :foo, component: :boolean # 체크박스 입력 필드를 생성합니다
field :foo, component: :category # 카테고리 선택기를 생성합니다
field :foo, component: :group # 그룹 선택기를 생성합니다
field :foo, component: :date_time # 날짜 및 시간 선택기를 생성합니다
field :foo, component: :tags # 태그 선택기를 생성합니다
field :foo, component: :user # 사용자 선택기를 생성합니다
field :foo, component: :pms # 하나 이상의 개인 메시지 템플릿을 생성할 수 있습니다
field :foo, component: :categories # 하나 이상의 카테고리를 선택할 수 있습니다
field :foo, component: :key-value # 키-값 쌍을 생성할 수 있습니다
field :foo, component: :message # 치환 가능한 변수를 가진 개인 메시지를 작성할 수 있습니다
field :foo, component: :trustlevel # 하나 이상의 신뢰 수준을 선택할 수 있습니다

```

##### triggerables 및 triggerable!

```rb
# 스크립트에 허용되는 트리거러블 목록을 정의합니다
triggerables %i[recurring]

# 스크립트에 트리거러블을 강제하고 필드에 일부 상태를 강제할 수 있습니다
field :recurring, component: :boolean
triggerable! :recurring, state: { foo: false }

```

##### placeholders

```rb
# 텍스트에서 플레이스홀더 문법 `%%sender%%`을 사용하여 키를 치환 가능하도록 표시합니다
placeholder :sender

```

플레이스홀더에 대한 값을 제공하고 `input = utils.apply_placeholders(input, { sender: 'bob' })`를 사용하여 치환을 적용하는 것은 스크립트의 책임임을 유의하세요.

##### script

이것은 자동화의 핵심이며 모든 로직이 실행되는 곳입니다.

```rb
# context는 자동화가 트리거될 때 전송되며, 트리거에 따라 크게 다를 수 있습니다
script do |context, fields, automation|
end

```

#### 지역화

사용할 각 필드는 i18n 키에 의존하며, 해당 트리거/스크립트에 네임스페이스가 부여됩니다.

예를 들어 다음 내용을 가진 스크립터블이 있다고 가정해 보겠습니다:

```rb
field :post_created_edited, component: :category

```

이 경우 client.en.yml에서 다음 키가 필요합니다:

```yaml
en:
  js:
    discourse_automation:
      scriptables:
        post_created_edited:
          fields:
            restricted_category:
              label: Category
               description: Optional, allows to limit trigger execution to this category

```

여기서 description은 선택 사항임을 유의하세요.

* * *

이 문서는 버전 관리됩니다 - 변경 사항을 [github](https://github.com/discourse/discourse/blob/main/docs/developer-guides/docs/06-general-guides/02-custom-automations.md)에서 제안하십시오.

---

_[View the full topic](https://meta.discourse.org/t/create-custom-automations/275931)._
