Skip to content

lark-cli api --as bot ignored inside pipe (while read loop) #41

@Heyjoy

Description

@Heyjoy

Description

When using lark-cli api POST ... --as bot inside a pipe (while IFS= read -r line loop), the --as bot flag is ignored and the command falls back to user identity, resulting in:

{
  "ok": false,
  "identity": "user",
  "error": {
    "type": "validation",
    "message": "resolved identity \"user\" (via auto-detect or default-as) is not supported, this command only supports: bot\nhint: use --as bot"
  }
}

Reproduction

Exactly following the official example from lark-event skill documentation:

lark-cli event +subscribe \
  --event-types im.message.receive_v1 --compact --quiet \
  | while IFS= read -r line; do
      content=$(echo "$line" | jq -r '.content // empty')
      message_id=$(echo "$line" | jq -r '.message_id // empty')
      [[ -z "$content" ]] && continue

      reply_data=$(jq -n --arg t "$content" '{msg_type:"text",content:({text:$t}|tojson)}')
      lark-cli api POST "/open-apis/im/v1/messages/$message_id/reply" \
        --data "$reply_data" --as bot --format data
    done

Event reception works — messages are received and the while loop executes.
Reply failslark-cli api POST ... --as bot resolves to user identity.

Also tried:

  • lark-cli im +messages-send --chat-id "$chat_id" --text "..." --as bot — same error
  • Adding < /dev/null to the command — same error
  • The same commands work perfectly when run directly in the terminal (not inside a pipe)

Expected behavior

--as bot should force bot identity regardless of whether the command runs in a TTY or inside a pipe.

Environment

  • macOS (Darwin 25.3.0)
  • lark-cli version 1.0.0
  • Installed via npm install -g @larksuite/cli
  • lark-cli doctor passes all checks
  • lark-cli auth status shows valid token

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdomain/authAuthentication subsystemdomain/coreCLI framework and core librariesdomain/eventEvent subscription domaindomain/imPR touches the im domain

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions