# email_convert_to_task

Convert Email to Task

## Beschreibung

Creates a Task from an email and links the two so the
conversion is traceable and idempotent.

Pass exactly one of `message_id` (`emsg_…`) or `thread_id`
(`ethr_…`); for a thread the latest message is used as the
anchor. `workspace_id` is the destination workspace (prefix `wsp_…`
or KEY like `ENG`); `project_id` (`proj_…` or slug) is
optional and must belong to that workspace.

Defaults: `title` = the email subject; the task description
is seeded from the email body (override with `description`,
Markdown). `assignee` is a `@handle` or user prefix.

`link_kind` is `created_from` (default — this task was made
from the email) or `referenced_in`. Idempotent: if the
source is already linked with the same `link_kind`, the
existing task is returned with `created: false` and no new
task is made.

## Zugriff

Zugriffsprofil: `gated`. Module: `email`.
Die Freigabe im Profil ersetzt keine Account-, Workspace- oder Rollenberechtigung.

## Parameter

| Name | Typ | Pflicht | Beschreibung |
| --- | --- | --- | --- |
| `account_id` | string | Ja | Account prefix ID (acct_…). |
| `message_id` | string | Nein | Source message (emsg_…). Provide this OR thread_id. |
| `thread_id` | string | Nein | Source thread (ethr_…); its latest message is used. Provide this OR message_id. |
| `workspace_id` | string | Ja | Destination workspace prefix ID (wsp_…) or KEY (e.g. ENG). |
| `project_id` | string | Nein | Optional project (proj_… or slug); must belong to the workspace. |
| `title` | string | Nein | Task title. Defaults to the email subject. |
| `description` | string | Nein | Task description in Markdown. Defaults to the email body. |
| `assignee` | string | Nein | Assignee @handle or user prefix ID. |
| `link_kind` | string | Nein | Provenance link kind. Default created_from. |

## Eingabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "account_id": {
      "type": "string",
      "description": "Account prefix ID (acct_…)."
    },
    "message_id": {
      "type": "string",
      "description": "Source message (emsg_…). Provide this OR thread_id."
    },
    "thread_id": {
      "type": "string",
      "description": "Source thread (ethr_…); its latest message is used. Provide this OR message_id."
    },
    "workspace_id": {
      "type": "string",
      "description": "Destination workspace prefix ID (wsp_…) or KEY (e.g. ENG)."
    },
    "project_id": {
      "type": "string",
      "description": "Optional project (proj_… or slug); must belong to the workspace."
    },
    "title": {
      "type": "string",
      "description": "Task title. Defaults to the email subject."
    },
    "description": {
      "type": "string",
      "description": "Task description in Markdown. Defaults to the email body."
    },
    "assignee": {
      "type": "string",
      "description": "Assignee @handle or user prefix ID."
    },
    "link_kind": {
      "type": "string",
      "enum": [
        "created_from",
        "referenced_in"
      ],
      "description": "Provenance link kind. Default created_from."
    }
  },
  "required": [
    "account_id",
    "workspace_id"
  ],
  "type": "object"
}
```

## Ausgabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "task": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "key": {
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "key",
        "url"
      ]
    },
    "link": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "kind"
      ]
    },
    "created": {
      "type": "boolean",
      "description": "false when an existing link/task was returned (idempotent)."
    }
  },
  "required": [
    "task",
    "link",
    "created"
  ],
  "type": "object"
}
```
