← All posts
Tutorial

UnifyPort Poll Messages: Validate Options and Selection Limits

A UnifyPort poll request uses message.type: "poll" and a message.poll object containing question, options, and max_selections. Supply at least two options, each with a non-blank title. max_selections is the maximum number of choices per voter, not a limit on voters, and must be an integer from 1 through the option count. Do not mix the poll with text or other message payloads.

Start with the poll contract, not a text-message template

The message-send reference exposes the shared fields for POST /v1/messages, including polls. Its page title does not mean you should retain message.text when switching the message type to poll.

The important boundaries are:

  • The question and each option title must contain a non-whitespace character.
  • Question and option titles are preserved verbatim; validation should not silently trim, change case, or normalize their Unicode content.
  • max_selections: 1 describes a single-choice poll. A larger valid value permits more selections per voter.
  • A valid shared payload does not establish support for the selected channel or account.

This is a different request shape from sending media by URL. Do not reuse a media form that leaves url, caption, or another message payload attached after the operator selects Poll.

Validate the draft before constructing the request

The following JavaScript builds the body only. It performs no network request and has not been run against a live account here. Pass an authorized account and an existing conversation selection from your application. The function name and error strings are local application code, not API error codes.

function buildPollRequest({ accountId, conversation, question, titles, maxSelections }) {
  const nonBlank = value => typeof value === 'string' && /\S/u.test(value);
  if (!nonBlank(accountId) || !nonBlank(conversation?.id) ||
      !['user', 'group', 'channel'].includes(conversation?.type)) {
    throw new Error('Select an account and conversation');
  }
  if (!nonBlank(question) || !Array.isArray(titles) ||
      titles.length < 2 || !titles.every(nonBlank)) {
    throw new Error('Provide a question and at least two non-blank options');
  }
  if (!Number.isInteger(maxSelections) ||
      maxSelections < 1 || maxSelections > titles.length) {
    throw new Error('Selection limit must be an integer within the option count');
  }
  return {
    account_id: accountId,
    to: { id: conversation.id, type: conversation.type },
    message: {
      type: 'poll',
      poll: {
        question,
        options: titles.map(title => ({ title })),
        max_selections: maxSelections
      }
    }
  };
}

For an illustrative scheduling poll, the question could be “Which support session can you attend?” with “Morning” and “Afternoon” as titles. Set maxSelections to 1 for one choice or 2 to allow both. Neither value restricts the number of participants.

The builder creates a fresh message object rather than copying a previous draft. It checks for visible content but retains the original strings. If your editor offers whitespace cleanup or duplicate-title warnings, make those explicit application choices before confirmation.

Test the boundaries without sending messages

These are proposed local checks, not reported test results:

Draft inputExpected local validation
Two non-blank options, limit 1Pass; single choice
Two non-blank options, limit 2Pass; up to two choices per voter
One optionReject
Blank question or whitespace-only titleReject
Limit 0, a fraction, or greater than the option countReject
String "1" instead of numeric 1Reject in this builder
Original titles contain surrounding spacesPreserve the strings if they contain non-whitespace content

JSON numeric values such as 1.0 and 1e0 represent the integer 1; the documented contract accepts integer-valued numbers. That does not make a quoted string a numeric value.

The public structure does not set a question-length limit, a maximum option count, or a duplicate-title restriction. This is not a promise of unlimited provider acceptance. Providers may impose additional limits. Do not invent a universal cap or silently discard options to fit an assumed one.

Revalidate after editing. If an operator removes an option, a previously valid selection limit may become invalid. Present the change for review rather than silently changing a multiple-choice poll into a single-choice poll.

Put channel eligibility before dispatch

UnifyPort is an unofficial interface. The channel message-support reference is separate from the shared request schema; the matrix reviewed for this article does not enumerate a poll row. Confirm the target provider, account, and deployment support before enabling a live Poll control. Do not probe capability by sending to customers, and do not infer LINE, Zalo, or Telegram support from the existence of message.poll.

Once support and authorization are established, submit the body from your backend using POST /v1/messages, X-Api-Key, and Content-Type: application/json. Keep the API key out of browser code and logs.

Record the actual response. data.status: accepted means the message was queued for delivery to the provider, not that recipients saw it or voted. Preserve request_id for troubleshooting as described in the request-tracing guide; it is not a duplicate-send prevention key. A timeout leaves the outcome uncertain, so do not automatically resend the poll.

FAQ

Does max_selections limit the number of voters?

No. It limits the choices each voter can select, from 1 to the number of options.

Can I include introductory text in the same message object?

Do not mix message.text with message.poll. Put the poll question in question. Any separate explanatory message should be an independently approved send.

Does sending a poll also provide vote results?

The sending fields establish a poll creation payload, not a vote-result API or event contract. Do not invent a result endpoint, subscription name, or vote count from an acceptance response. Verify a separate documented capability before promising automated tallying.

Next step and sources

Implement the local draft tests against the shared message-send fields, then confirm channel support before a controlled send. No release date or live test outcome is claimed.

Official product references checked on 2026-11-26:

UnifyPort API

Turn messaging integration into a stable product pipeline.

Start by sending through one API, then bring every inbound message back into your business system with standard events.