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:
| Source | Example condition |
|---|---|
| Campaign | Opened or clicked a particular campaign |
| Rich Menu | Tapped a particular menu button |
| Auto Response | Sent a message matching a particular keyword |
| Form Builder | Answered a particular question with a particular value |
| Multi-source | Any 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
- cms-web loads the selectable options for each source into dropdowns via the
list-dropdown-campaign,list-dropdown-richmenu,list-dropdown-auto-responseandlist-dropdown-form-builderendpoints. - If the user filters by form,
GET /api/audiences-filter/form-questions/:formIdreturns that form's questions so a specific question and expected value can be chosen. GET /api/audiences-filter/form-responseshows a preview of the raw answers, confirming the shape of the data.
Preview, then create
- Form-based filter — call
POST /api/audiences-filter/preview-form-filterto inspect the result, thenPOST /api/audiences-filter/create-form-filterto create it for real. - Multi-source filter — the same pattern using
preview-multi-source-filterfollowed bycreate-multi-source-filter. - General filter —
POST /api/audiences-filter/create-filterwith aCreateAudiencesFilterDtopayload. - Every creation path checks the
maxSegmentsquota from the customer's plan first. - Once created, the result becomes a regular audience managed by the Audience Management module, including member CSV generation and optional auto-refresh.
Internal path
POST /api/audiences-filter/internal/refreshis called by other services, not by users. It is protected byInternalApiKeyGuardvia theX-Internal-Keyheader and accepts a body containingaudienceId,lineOaId,organizationId,lineOaHashandtriggerType. 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.
| Method | Route | Handler | Policy |
|---|---|---|---|
| POST | /api/audiences-filter/create-filter | ct.createFilter | create audiences |
| GET | /api/audiences-filter/list-dropdown-campaign | ct.getListDropdownCampaign | read audiences |
| GET | /api/audiences-filter/list-dropdown-richmenu | ct.getListDropdownRichmenu | read audiences |
| GET | /api/audiences-filter/list-dropdown-auto-response | ct.getListDropdownAutoResponse | read audiences |
| GET | /api/audiences-filter/list-dropdown-form-builder | ct.getListDropdownFormBuilder | read audiences |
| GET | /api/audiences-filter/form-questions/:formId | ct.getFormQuestions | read audiences |
| GET | /api/audiences-filter/form-response | ct.formResponsePreview | read audiences |
| POST | /api/audiences-filter/preview-form-filter | ct.previewFormSegment | read audiences |
| POST | /api/audiences-filter/create-form-filter | ct.createFormFilterAudience | read audiences |
| POST | /api/audiences-filter/preview-multi-source-filter | ct.previewMultiSourceFilter | read audiences |
| POST | /api/audiences-filter/create-multi-source-filter | ct.createMultiSourceFilter | create audiences |
| POST | /api/audiences-filter/internal/refresh | ct.internalRefresh | internalApiKeyGuard() |
Connections to Other Services
- Permissions — user-facing routes sit on the
authedgroup, which enforces JWT globally, and carryPolicyModuleAudiencesas metadata. The internal route usesInternalApiKey(from theINTERNAL_API_KEYenvironment variable) instead of a JWT. - Tables —
audience,campaign,rich_menu,auto_response,form_builder,form_submission,line_userandtracking_line_users. - Cross-module — calls
formbuilder.Service.GetFormByIdthrough a localformByIDProviderinterface 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.