ivy: flow/v1
name: Invoice intake
description: Extract, check and approve supplier invoices that arrive in a folder.

on:
  file:
    folder: Inbox # the folder suppliers' invoices arrive in
    events: [created]
    match: "*.pdf"

steps:
  - id: extract
    agent: ivy
    prompt: Extract the supplier, the invoice number, the date and the total.
    files: ["{{ trigger.file }}"]
    output:
      schema:
        type: object
        required: [supplier, number, date, total]
        properties:
          supplier: { type: string }
          number: { type: string }
          date: { type: string }
          total: { type: number }
  - id: approve
    if: steps.extract.output.total > 1000
    ask:
      to: { role: workspace_admins }
      in: { channel: Accounts payable } # a channel of this space the approvers read
      question: "Approve {{ steps.extract.output.supplier }}, invoice {{ steps.extract.output.number }}?"
      options: [approve, reject]
