Skip to main content

Audience

Overview

An audience is a selected group of LINE users targeted for messaging or rich menu switching. There are two ways to build one, expressed by the AudiencesDataSource enum:

  • csv — upload a list of userIds directly
  • filter — define conditions over attributes or user activity and let the system compute the membership

A key design decision: audience membership is not stored in a join table. It is denormalized into line_user.audience_ids (JSONB with a GIN index), which makes "which groups is this user in?" extremely fast to answer. The history of joins and departures is recorded separately in audience_member_log.

Core Data Structure

audience (model Audience)

Descriptive fields are title, description, slug, details and data_source (csv or filter).

Summary and conditionsinfo JSONB holds summary data such as the member count, while filter_info JSONB holds the filter conditions, which reference keys from Attribute Definitions.

Auto-refreshauto_refresh_enabled, last_refresh_date and refresh_status (default idle).

Scope and originline_oa_id and organization_id, plus api_client_id and api_key_id for audiences managed through the public API.

Deletion is soft via deleted_date, and the table has 1 : N relationships with campaign, rich_menu, rich_menu_archive and audience_member_log.

audience_member_log (model AudienceMemberLog)

Records every join and departure, with audience_id (FK to audience.id), line_user_id (the LINE userId as a string), action (enum AudienceMemberAction: add or remove) and trigger_type (enum AudienceMemberTriggerType: auto_refresh, manual or api).

Indexes cover (audience_id), (created_date DESC), (action) and (line_oa_id).

How refreshes are governed

Auto-refresh is controlled at two levels: the channel, through line_oa.audience_refresh_enabled and line_oa.audience_refresh_interval (in minutes), and each audience individually through audience.auto_refresh_enabled. Both are further constrained by plan_limits.maxSegments and plan_limits.autoRefresh.

  • prisma/schema.prisma:424 — model Audience
  • prisma/schema.prisma:1319 — model AudienceMemberLog
  • seed-data/08.audience.sql — seeds a sample audience
  • manual-sql/7.plan_limits.sql — the maxSegments and autoRefresh quotas
  • schema-dumps/2026-07-24/schema.sql:983 and :1032

Connections to Other Services

  • cms-api-go — audience CRUD, CSV upload, member listing and export.
  • worker-go — runs the scheduled refresh job: recomputes membership from filter_info, updates line_user.audience_ids, and writes the history to audience_member_log.
  • Audiences are the target of Campaigns (both multicast and narrowcast), drive Rich Menu switching, gate access in Content Taxonomy, and control category visibility in Bulletin.