> ## Documentation Index
> Fetch the complete documentation index at: https://mikting.docs.komo.moe/llms.txt
> Use this file to discover all available pages before exploring further.

# Actions

> Arguments and outputs for each Mikting action.

Mikting actions use the regular script fields supported by ItsMyBot, including
`triggers`, `conditions`, `target`, `delay`, `chance`, `cooldown`, and `every`.
Most accept `args.follow-up-actions`. Follow-ups run after success or failure.
To handle an error, branch on an output variable or use a condition. Actions do
not accept `not-met-actions`; that field belongs to conditions.

String inputs support `[[variables]]`, `%placeholders%`, and
`{{secret.NAME}}`. `storeAs` creates namespaced outputs such as `[[probe_ok]]`.

## HTTP requests

### `miktingHttp`

Send a request to any HTTP endpoint. A request body is optional. If included,
choose one of `json`, `form`, or `text`.

```yaml theme={null}
- id: miktingHttp
  args:
    method: POST            # GET|POST|PUT|PATCH|DELETE|HEAD (default GET)
    url: 'https://api.example.com/v1/check'
    headers: { Authorization: 'Bearer {{secret.API_TOKEN}}' }
    query: { verbose: 'true' }
    json: { text: '%message_content%' }
    # form: { q: 'hello' }  # url-encoded alternative
    # text: 'raw body'      # plain-text alternative
    # auth: { type: bearer, tokenSecret: API_TOKEN }  # instead of headers
    # auth: { type: basic, userSecret: API_USER, passSecret: API_PASS }
    timeoutMs: 10000
    retries: 1
    storeAs: mod
    follow-up-actions:
      - id: miktingBranch
        args:
          when: '[[mod_ok]] == false'
          then: [{ id: miktingReply, args: { content: 'API error: [[mikting_error]]' } }]
```

The action sets `mikting_status`, `mikting_ok`, `mikting_body`, and, when the
response is JSON, `mikting_json` plus flattened JSON paths. Response headers
are available as `mikting_headers_<name>`. With `storeAs: probe`, the same
outputs use the `probe_` prefix. For example, a JSON field at `results.0.flagged`
becomes `[[probe_json_results_0_flagged]]`.

When using `auth.tokenSecret`, numbered keys rotate automatically. The chosen
slot name appears in `mikting_key_name` and `probe_key_name`. See
[Secrets](https://mikting.docs.komo.moe/secrets.md).

### Validate a response

`responseCheck` validates the response body against a known contract. Supported
checks include OpenAI moderation, OpenAI and Groq policy responses, and Jev
policy responses. A check adds `valid` and `flagged` outputs to its namespace;
Jev also adds `score`. HTTP `ok` means only that the status is 2xx. Check both
`valid` and `flagged` before taking action.

OpenAI and Groq policy checks expect a completed Chat Completions response
whose message contains JSON with a boolean `flagged` and a 1 to 500 character
`reason`. Jev validates TypeSafe's response shape, including its model, Noul
answer, score, and token counters. `policyThreshold` accepts a number from 0 to
1 and defaults to `0.80`. A score at or above the threshold sets `flagged` to
true. This value is a model estimate, not a guarantee of accuracy. Extra fields
are allowed; missing fields and invalid types fail validation. See the
[TypeSafe Noul contract](https://docs.typesafe.ai/primitives/noul).

### `miktingHttpPaginate`

Follow a next URL or an RFC 5988 `Link` header and combine results:

```yaml theme={null}
- id: miktingHttpPaginate
  args:
    method: GET
    url: 'https://api.example.com/items'
    headers: { Authorization: 'Bearer {{secret.API_TOKEN}}' }
    nextPath: 'paging.next'   # dot path to next URL in each JSON body
    linkHeader: true          # or follow RFC5988 Link: <u>; rel="next"
    maxPages: 5
    storeAs: items            # -> [[items]] merged array + [[mikting_pages]]
```

Array response bodies are merged directly. For object bodies, the action merges
the `data` array when present; otherwise it appends the object. It sets
`mikting_page_count` and the named result array.

## Variables

* `miktingSet { key, value }` stores a value in the current run.
* `miktingGet { key, storeAs? }` copies a value to a new name or the same key.
  A missing key sets `mikting_error`.
* `miktingAppend { key, value, sep? }` appends to an array or joins text with
  `sep` (default `,`). It creates a missing variable.
* `miktingClear { keys }` removes one or more variables. `keys` can be a string
  or list.
* `miktingMath { expr, storeAs? }` evaluates a numeric filtrex expression.
  It defaults the output name to `result` and does not use JavaScript `eval`.

```yaml theme={null}
- id: miktingMath
  args: { expr: '[[wins]] * 10 + 5', storeAs: xp }
```

## Text and data

`miktingString` supports `upper`, `lower`, `trim`, `length`, `slice`,
`replace`, `split`, `join`, and `regex`. `slice` uses `from` and `to`;
`replace` uses a literal `pattern` and `replacement`; `split` and `join` use
`sep`. `regex` uses a JavaScript regular expression and returns the match or
capture groups, or `null` when there is no match.

`miktingJson` parses, stringifies, or queries JSON. The `query` operation uses a
dot path such as `users.0.name`. `miktingArray` supports `len`, `first`,
`last`, `reverse`, `unique`, `join`, `includes`, and `at`. `join` uses `sep`,
`includes` uses `item`, and `at` uses a zero-based `index`. A direct array
variable input preserves objects; other string inputs are templated first.

`miktingDate` supports `now`, `format`, `parse`, and `add`. `now` returns epoch
milliseconds; `format` returns ISO text; `parse` returns milliseconds; `add`
shifts a timestamp by an amount in `ms`, `s`, `m`, `h`, or `d`.
`miktingRandom` produces an inclusive integer, UUID, or selected choice.
`miktingHash` supports SHA-256 and MD5. `miktingEncode` converts between
Base64, URL encoding, and hexadecimal.

## Flow control

These actions run nested action lists where noted. They do not accept their own
follow-up lists unless stated.

`miktingBranch { when, then?, else? }` evaluates a templated boolean
expression, then runs one of its action lists:

```yaml theme={null}
- id: miktingBranch
  args:
    when: '[[mod_json_results_0_flagged]] == true'
    then:
      - id: deleteMessage
      - id: miktingReply
        args: { content: 'Flagged and logged.' }
```

`miktingForEach { list, itemVar, actions, maxIter? }` runs actions for each
array item and sets the item variable and its zero-based index. The default
iteration limit is 100. `miktingWhile { cond, actions, maxIter? }` defaults to
25 iterations. `miktingTry { try, catch?, storeErrorAs? }` runs a catch list
when the try list fails. `miktingSleep { ms }` pauses for up to 60 seconds.
`miktingStop` ends the current chain. `miktingCallFunction` calls a function
defined in a library. `miktingInclude { path }` runs an `{actions:[...]}` YAML
file confined to the bot working directory. See [Libraries](https://mikting.docs.komo.moe/libraries.md).

## Discord actions

`miktingReply` sends a message using standard message arguments, including
`content`, `embeds`, `components`, and `ephemeral`. It replies to an interaction
when available and otherwise sends to the channel. Follow-ups receive the sent
message context.

`miktingDm { user? }` sends a direct message to the context member by default.
Closed DMs set `mikting_error`. `miktingReact { value }` reacts to the current
message. `miktingPoll { question, options, durationH? }` creates a native poll
with 2 to 10 options and a duration from 1 to 336 hours, defaulting to 24.

`miktingTimeout { durationSec?, user?, reason? }` applies a timeout to the
context member by default. Zero removes a timeout. The duration is in seconds.
`miktingModerate` supports `ban`, `unban`, `kick`, `addRole`, `removeRole`,
`nickname`, and `slowmode`; role and nickname operations accept their
corresponding values, ban accepts `deleteMessagesSec`, and slowmode requires a
text channel context.

`miktingWebhookSend { url, content, username?, storeAs? }` sends JSON to a
Discord webhook. Keep its URL in a secret. `miktingPaginate { pages, timeoutSec? }` sends the first page and lets the trigger author navigate the
pages; the current index is stored in `paginate_page`.

`miktingWaitFor { type, timeoutSec?, fromUser?, storeAs? }` waits for a message
or reaction. Message results include content and author; reaction results
include the emoji. A timeout sets `mikting_error`. Reactions require a message
context.

## Store actions

Use `miktingStoreSet`, `miktingStoreGet`, `miktingStoreIncr`,
`miktingStoreListOp`, and `miktingStoreRemove` for persistent data. The store
supports global, guild, user, channel, and message scopes. Setting the remove
key to `*` clears the selected scope. See [Key-value store](https://mikting.docs.komo.moe/key-value-store.md).

[Documentation home](https://mikting.docs.komo.moe/index.md) · [Source Markdown](https://gitlab.com/komomori/mikting/-/blob/main/docs/mikting-actions.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.