chatformdocs
Blocks

Poll

Pick one, then see how everybody else answered. Use it when showing the split is the point; use single_select when it is not.

Choicepoll

Pick one, then see how everybody else answered. Use it when showing the split is the point; use single_select when it is not.

Requires options.

How it gets answered — matched exactly — never sent to a model.

Configuration

Fields specific to poll. The fields every block hasid, ref, title, required, visibility, media, agentHints, prefillParam, identityField — are documented once.

poll configuration
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "buttonLabel": {
      "type": "string",
      "maxLength": 60
    },
    "type": {
      "type": "string",
      "const": "poll"
    },
    "options": {
      "minItems": 2,
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 6,
            "maxLength": 32
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "image_key": {
            "default": null,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "score": {
            "type": "number"
          }
        },
        "required": [
          "id",
          "label"
        ]
      }
    },
    "showResults": {
      "default": true,
      "type": "boolean"
    },
    "minResponsesToReveal": {
      "default": 2,
      "type": "integer",
      "minimum": 1,
      "maximum": 1000
    }
  },
  "required": [
    "id",
    "ref",
    "title",
    "type",
    "options"
  ],
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "op": {
          "type": "string",
          "enum": [
            "and",
            "or"
          ]
        },
        "conditions": {
          "default": [],
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "left": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "ref"
                      },
                      "ref": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{1,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "ref"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "variable"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9_]{0,40}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "hidden"
                      },
                      "name": {
                        "type": "string",
                        "pattern": "^[a-zA-Z_][a-zA-Z0-9_.-]{0,60}$"
                      }
                    },
                    "required": [
                      "kind",
                      "name"
                    ]
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "literal"
                      }
                    },
                    "required": [
                      "kind"
                    ]
                  }
                ]
              },
              "op": {
                "type": "string",
                "enum": [
                  "eq",
                  "neq",
                  "gt",
                  "gte",
                  "lt",
                  "lte",
                  "contains",
                  "not_contains",
                  "starts_with",
                  "ends_with",
                  "matches_regex",
                  "is_empty",
                  "is_not_empty",
                  "is_checked",
                  "is_not_checked",
                  "includes",
                  "not_includes",
                  "ranked_above",
                  "ranked_below"
                ]
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  },
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                ]
              }
            },
            "required": [
              "left",
              "op"
            ]
          }
        },
        "groups": {
          "default": [],
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        }
      },
      "required": [
        "op"
      ]
    }
  }
}

In a generated draft these arrive as config pairs: showResults=false to collect the answer without ever showing the tally back; minResponsesToReveal=<n> to hold the split until n people have answered (default 2, so nobody is shown an audience of one).

What you receive

GET /v1/forms/{id} and every "next question" projects blocks through toPublicBlock. For the example above:

PublicBlock
{
  "id": "blk_poll0001",
  "ref": "q_stack",
  "type": "poll",
  "title": "Which do you reach for?",
  "required": true,
  "imageKey": null,
  "media": null,
  "options": [
    {
      "id": "opt_react0001",
      "label": "React",
      "imageKey": null
    },
    {
      "id": "opt_svelte001",
      "label": "Svelte",
      "imageKey": null
    }
  ],
  "showResults": true,
  "minResponsesToReveal": 2
}

What you send

The chosen option's id. Identical to single_select: the tally is a read, never an answer.

type Answer = string;
curl -X POST https://api.chatform.in/v1/responses/{RESPONSE_ID}/answers \
  -H "x-api-key: $CHATFORM_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"ref": "q_stack", "value": "opt_react0001"}'

What gets stored

The value is normalised before it is saved, so what you read back is not always what you sent.

You sendStored
"opt_react0001""opt_react0001"
"React""opt_react0001"a label resolves to its id

Errors

CodeWhenMessage
requiredan empty answer on a required blockThis question needs an answer.
invalid_option"opt_nope"Please pick one of the available options.

On this page