Skip to main content

Building Audiences from Conditions (Audience Filter)

Overview

Audience Filter builds audiences from user behaviour conditions instead of requiring a manually uploaded CSV. The system pulls the member list straight from data it has already recorded.

Supported condition sources:

SourceExample condition
CampaignOpened or clicked a particular campaign
Rich MenuTapped a particular menu button
Auto ResponseSent a message matching a particular keyword
Form BuilderAnswered a particular question with a particular value
Multi-sourceAny combination of the above

The module's key strength is its preview step, which shows the member count and a sample of matching members before anything is created — reducing the risk of building the wrong audience and only discovering it after messages have gone out.

Business Flow

Preparing the options

  1. cms-web loads the selectable options for each source into dropdowns via the list-dropdown-campaign, list-dropdown-richmenu, list-dropdown-auto-response and list-dropdown-form-builder endpoints.
  2. If the user filters by form, GET /api/audiences-filter/form-questions/:formId returns that form's questions so a specific question and expected value can be chosen.
  3. GET /api/audiences-filter/form-response shows a preview of the raw answers, confirming the shape of the data.

Preview, then create

  1. Form-based filter — call POST /api/audiences-filter/preview-form-filter to inspect the result, then POST /api/audiences-filter/create-form-filter to create it for real.
  2. Multi-source filter — the same pattern using preview-multi-source-filter followed by create-multi-source-filter.
  3. General filterPOST /api/audiences-filter/create-filter with a CreateAudiencesFilterDto payload.
  4. Every creation path checks the maxSegments quota from the customer's plan first.
  5. Once created, the result becomes a regular audience managed by the Audience Management module, including member CSV generation and optional auto-refresh.

Internal path

  1. POST /api/audiences-filter/internal/refresh is called by other services, not by users. It is protected by InternalApiKeyGuard via the X-Internal-Key header and accepts a body containing audienceId, lineOaId, organizationId, lineOaHash and triggerType. Workers and webhooks use it to trigger a recomputation of a filter-derived audience's members.

Key Files & Functions

The code lives in internal/modules/audiencefilter/, split across controller.go, service.go and dto.go.

MethodRouteHandlerPolicy
POST/api/audiences-filter/create-filterct.createFiltercreate audiences
GET/api/audiences-filter/list-dropdown-campaignct.getListDropdownCampaignread audiences
GET/api/audiences-filter/list-dropdown-richmenuct.getListDropdownRichmenuread audiences
GET/api/audiences-filter/list-dropdown-auto-responsect.getListDropdownAutoResponseread audiences
GET/api/audiences-filter/list-dropdown-form-builderct.getListDropdownFormBuilderread audiences
GET/api/audiences-filter/form-questions/:formIdct.getFormQuestionsread audiences
GET/api/audiences-filter/form-responsect.formResponsePreviewread audiences
POST/api/audiences-filter/preview-form-filterct.previewFormSegmentread audiences
POST/api/audiences-filter/create-form-filterct.createFormFilterAudienceread audiences
POST/api/audiences-filter/preview-multi-source-filterct.previewMultiSourceFilterread audiences
POST/api/audiences-filter/create-multi-source-filterct.createMultiSourceFiltercreate audiences
POST/api/audiences-filter/internal/refreshct.internalRefreshinternalApiKeyGuard()

Connections to Other Services

  • Permissions — user-facing routes sit on the authed group, which enforces JWT globally, and carry PolicyModuleAudiences as metadata. The internal route uses InternalApiKey (from the INTERNAL_API_KEY environment variable) instead of a JWT.
  • Tablesaudience, campaign, rich_menu, auto_response, form_builder, form_submission, line_user and tracking_line_users.
  • Cross-module — calls formbuilder.Service.GetFormById through a local formByIDProvider interface to avoid an import cycle, and depends on Plan Limits and Storage.
  • Storage — writes the resulting member list as a CSV file to object storage.
  • Related modules — Audience Management, Form Builder, Campaign Management and Rich Menu.