# Message templates tools

[All tool areas](/docs/tools.md). Each tool acts within your access.

## Message templates

### list_message_templates

List every message Lokl sends, with its subject and editable words as they are at one level, where each value comes from (Lokl's own text, the organization's, or an entity's: an entity's beats the organization's, which beats Lokl's), what {{variables}} the text may use, and what Lokl always writes itself. Pass `entityId` for the text an entity's guests get, or nothing for the organization's own. Messages to staff and the kitchen can't be edited and are listed as such. Use before update_message_template.

Reads · Members of an organization · Needs settings:read

#### Input

- `entityId` — string; optional. Brand the message for this entity: its text beats the organization's. Leave out to read or change the organization's own
- `locale` — string; optional. The language the text is written in. Only en for now Allowed: "en"; default: "en"

#### Output

- `level` — string; required.  Allowed: "organization", "entity"
- `name` — string; required. The organization's or the entity's name
- `locale` — string; required. 
- `templates` — array; required. 
  - `templates[]` — object; optional. 
    - `templates[].notification` — string; required. The message's key, as list_message_templates names it
    - `templates[].name` — string; required. 
    - `templates[].description` — string; required. When it's sent, and to whom
    - `templates[].audience` — string; required.  Allowed: "guest", "staff"
    - `templates[].editable` — boolean; required. 
    - `templates[].reason` — string or null; required. Why it can't be edited, when it can't; null otherwise
    - `templates[].about` — string or null; required. What it's about. Only a message about an order can be previewed against a real booking; the rest use a sample Allowed: "order", "quote", "invoice", "tip", "gift\_certificate"
    - `templates[].subject` — object or null; required. The subject, or null where it can't be changed (it says what happened) or the message can't be edited
      - `templates[].subject.value` — string; required. The text in effect at this level, in the format blocks are written in
      - `templates[].subject.default` — string; required. Lokl's own text
      - `templates[].subject.inherited` — string; required. What it would be if this level's own text were taken away: Lokl's own for the organization, and the organization's (or Lokl's) for an entity
      - `templates[].subject.source` — object; required. 
        - `templates[].subject.source.level` — string; required. Where the text comes from: Lokl's own (default), the organization's, or the entity's Allowed: "default", "organization", "entity"
        - `templates[].subject.source.id` — string or null; required. The saved template it comes from (mtp_…); null for Lokl's own
      - `templates[].subject.overriddenHere` — boolean; required. Whether this level has text of its own for it
    - `templates[].blocks` — array; required. The editable words, in the order they appear in the email
      - `templates[].blocks[]` — object; optional. 
        - `templates[].blocks[].value` — string; required. The text in effect at this level, in the format blocks are written in
        - `templates[].blocks[].default` — string; required. Lokl's own text
        - `templates[].blocks[].inherited` — string; required. What it would be if this level's own text were taken away: Lokl's own for the organization, and the organization's (or Lokl's) for an entity
        - `templates[].blocks[].source` — object; required. 
          - `templates[].blocks[].source.level` — string; required. Where the text comes from: Lokl's own (default), the organization's, or the entity's Allowed: "default", "organization", "entity"
          - `templates[].blocks[].source.id` — string or null; required. The saved template it comes from (mtp_…); null for Lokl's own
        - `templates[].blocks[].overriddenHere` — boolean; required. Whether this level has text of its own for it
        - `templates[].blocks[].key` — string; required. The block's key, as update_message_template takes it
        - `templates[].blocks[].label` — string; required. 
        - `templates[].blocks[].description` — string; required. 
        - `templates[].blocks[].format` — string; required. line: one plain line (a heading, a greeting). paragraphs: paragraphs separated by a blank line, with **bold** and [links](https://…) Allowed: "line", "paragraphs"
        - `templates[].blocks[].required` — boolean; required. A required block can't be left empty
    - `templates[].variables` — array; required. What {{variables}} the subject and the blocks may use
      - `templates[].variables[]` — object; optional. 
        - `templates[].variables[].name` — string; required. Write it in the text as {{name}}
        - `templates[].variables[].description` — string; required. 
        - `templates[].variables[].example` — string; required. What it looks like filled in
    - `templates[].fixed` — array; required. What Lokl always writes itself in this message, which can't be changed or taken out
      - `templates[].fixed[]` — string; optional. 
    - `templates[].updatedAt` — string or null; required. When this level's text was last saved; null if it has none format: "date-time"

### render_message_template

See a message as a guest would get it: its subject, HTML, and plain text, written from the text saved at this level (the entity's, else the organization's, else Lokl's) with a `draft` laid over it to try new words before saving them. With `orderId` it uses that booking's real details (a booking you may see in full: its guest's name and what they paid); a message about something else, or none, uses a built-in sample. Links in a preview are placeholders that open nothing. Changes nothing; send_test_message emails it to you.

Reads · Members of an organization · Needs settings:read

#### Input

- `notification` — string; required. The message's key, as list_message_templates names it
- `entityId` — string; optional. Brand the message for this entity: its text beats the organization's. Leave out to read or change the organization's own
- `locale` — string; optional. The language the text is written in. Only en for now Allowed: "en"; default: "en"
- `orderId` — string; optional. Write it from this booking. Only for a message about a booking
- `draft` — object; optional. Text to try over what's saved at this level (a JSON object in the query string): `subject`, and `blocks` by key; null tries what the level inherits
  - `draft.subject` — string or null; optional. The subject to try, or null to try the text this level inherits maxLength: 10000
  - `draft.blocks` — object; optional. Text to try for each block by its key, or null to try what this level inherits
    - `draft.blocks.*` — string or null; optional.  maxLength: 10000

#### Output

- `notification` — string; required. 
- `subject` — string; required. 
- `html` — string; required. 
- `text` — string; required. 
- `source` — string; required. Whether it was written from the booking you named or the sample Allowed: "order", "sample"
- `bookingCode` — string or null; required. 
- `note` — string; required. 

### send_test_message

Email yourself a message as guests would get it, to see it in a real inbox: written from the text saved at this level with an optional `draft` laid over it, and from a booking's details with `orderId` (a booking you may see in full) or the built-in sample. It goes only to your own address, with "[Test]" in front of the subject, through the email queue. Links in it are placeholders that open nothing. Up to 20 an hour. Can't be undone. Returns a preview to confirm.

Changes · Members of an organization · Needs settings:write

#### Input

- `notification` — string; required. The message's key, as list_message_templates names it
- `entityId` — string; optional. Brand the message for this entity: its text beats the organization's. Leave out to read or change the organization's own
- `locale` — string; optional. The language the text is written in. Only en for now Allowed: "en"; default: "en"
- `orderId` — string; optional. Write it from this booking. Only for a message about a booking
- `draft` — object; optional. Text to try over what's saved at this level: `subject`, and `blocks` by key; null tries what the level inherits
  - `draft.subject` — string or null; optional. The subject to try, or null to try the text this level inherits maxLength: 10000
  - `draft.blocks` — object; optional. Text to try for each block by its key, or null to try what this level inherits
    - `draft.blocks.*` — string or null; optional.  maxLength: 10000

#### Output

- `notification` — string; required. 
- `sentTo` — string; required. Your own address
- `subject` — string; required. The subject it was sent with

### update_message_template

Change the words of a message at one level: the organization's, or one entity's with `entityId` (branded per entity: it beats the organization's, which beats Lokl's). Set `subject` and any of the editable `blocks` by their key (list_message_templates gives them, with the {{variables}} each may use); write null to take this level's text away so it inherits again. Text is plain paragraphs separated by a blank line, with {{variable}} placeholders, **bold**, and [links](https://…) only; an unknown variable, HTML, or a link that isn't https is refused, naming it. Lokl's own parts of the message (the booking's details, totals, QR code, links, policies) can't be changed. Takes effect on the next message sent, reminders already scheduled included. Use render_message_template to try words first. Undo puts the text back while it hasn't been changed since. Returns a preview to confirm.

Changes · Members of an organization · Needs settings:write

#### Input

- `notification` — string; required. The message's key, as list_message_templates names it
- `entityId` — string; optional. Brand the message for this entity: its text beats the organization's. Leave out to read or change the organization's own
- `locale` — string; optional. The language the text is written in. Only en for now Allowed: "en"; default: "en"
- `subject` — string or null; optional. The new subject, one line with {{variables}}, or null to take this level's own away. Leave out to keep it maxLength: 10000
- `blocks` — object; optional. New text by block key (headline, greeting, intro, closing, where the message has them), or null to take this level's own away. Leave a block out to keep it
  - `blocks.*` — string or null; optional.  maxLength: 10000

#### Output

- `notification` — string; required. The message's key, as list_message_templates names it
- `name` — string; required. 
- `description` — string; required. When it's sent, and to whom
- `audience` — string; required.  Allowed: "guest", "staff"
- `editable` — boolean; required. 
- `reason` — string or null; required. Why it can't be edited, when it can't; null otherwise
- `about` — string or null; required. What it's about. Only a message about an order can be previewed against a real booking; the rest use a sample Allowed: "order", "quote", "invoice", "tip", "gift\_certificate"
- `subject` — object or null; required. The subject, or null where it can't be changed (it says what happened) or the message can't be edited
  - `subject.value` — string; required. The text in effect at this level, in the format blocks are written in
  - `subject.default` — string; required. Lokl's own text
  - `subject.inherited` — string; required. What it would be if this level's own text were taken away: Lokl's own for the organization, and the organization's (or Lokl's) for an entity
  - `subject.source` — object; required. 
    - `subject.source.level` — string; required. Where the text comes from: Lokl's own (default), the organization's, or the entity's Allowed: "default", "organization", "entity"
    - `subject.source.id` — string or null; required. The saved template it comes from (mtp_…); null for Lokl's own
  - `subject.overriddenHere` — boolean; required. Whether this level has text of its own for it
- `blocks` — array; required. The editable words, in the order they appear in the email
  - `blocks[]` — object; optional. 
    - `blocks[].value` — string; required. The text in effect at this level, in the format blocks are written in
    - `blocks[].default` — string; required. Lokl's own text
    - `blocks[].inherited` — string; required. What it would be if this level's own text were taken away: Lokl's own for the organization, and the organization's (or Lokl's) for an entity
    - `blocks[].source` — object; required. 
      - `blocks[].source.level` — string; required. Where the text comes from: Lokl's own (default), the organization's, or the entity's Allowed: "default", "organization", "entity"
      - `blocks[].source.id` — string or null; required. The saved template it comes from (mtp_…); null for Lokl's own
    - `blocks[].overriddenHere` — boolean; required. Whether this level has text of its own for it
    - `blocks[].key` — string; required. The block's key, as update_message_template takes it
    - `blocks[].label` — string; required. 
    - `blocks[].description` — string; required. 
    - `blocks[].format` — string; required. line: one plain line (a heading, a greeting). paragraphs: paragraphs separated by a blank line, with **bold** and [links](https://…) Allowed: "line", "paragraphs"
    - `blocks[].required` — boolean; required. A required block can't be left empty
- `variables` — array; required. What {{variables}} the subject and the blocks may use
  - `variables[]` — object; optional. 
    - `variables[].name` — string; required. Write it in the text as {{name}}
    - `variables[].description` — string; required. 
    - `variables[].example` — string; required. What it looks like filled in
- `fixed` — array; required. What Lokl always writes itself in this message, which can't be changed or taken out
  - `fixed[]` — string; optional. 
- `updatedAt` — string or null; required. When this level's text was last saved; null if it has none format: "date-time"
