Prompt Fields

Sym Flows can be configured to include custom input fields.

Overview

Sym workflows support custom input fields so you can collect variable information from a user who's requesting access to a resource, and then use it in the SDK.

Prompt Fields are used in two ways:

  1. For Flows invoked in Slack, they define input fields to be displayed in the request modal.
  2. For Flows invoked by API, they define the structure of the flow_inputs block in the body of the request.

Configuring Prompt Fields

Prompt Fields are defined as part of a Flow's Params using the prompt_fields_json attribute. This attribute collects all your fields as a jsonencoded string so they can be rendered at runtime.

The prompt_fields_json attribute must be provided via Terraform as a jsonencoded list. Each item in the list must be a map, containing the following items:

  • name (required string) - a unique identifier for the field
  • type (required string) - the field type (one of "string", "int", "bool", "duration")
  • required (optional boolean, defaults to True) - whether this field is a required input
  • label (optional string) - a non-unique name for the field, to be displayed in Slack
  • default (optional string) - a fallback value for optional fields if no value is provided
  • allowed_values (optional string list) - defines the full list of valid choices for this field's value (changes field display in Slack to a dropdown)

πŸ“˜

For more information on the special "duration" field type, see Access Duration.

Example

resource "sym_flow" "example" {
  ...

  params = {
    ...
    
    prompt_fields_json = jsonencode(
      [
        {
          name     = "reason"
          type     = "string"
          required = true
        },
        {
          name           = "urgency"
          type           = "string"
          allowed_values = ["low", "medium", "high", "emergency"]
          required       = true
        }
      ]
    )
  }
}

Accessing Prompt Fields in the SDK

Any fields defined in prompt_fields_json can be accessed and used in the SDK via the event.payload.fields dictionary, as with other field data.

Example

@hook
def on_request(event):
  urgency = event.payload.fields["urgency"]
  
  # Auto-approve requests in emergencies.
  if urgency == "emergency":
    return ApprovalTemplate.approve()

Did this page help you?