Documentation
¶
Overview ¶
Package leads is Facebook and Instagram Lead Ads in ReputeCast (M66, G-41): a workspace connects its own Meta app with a system user's token, chooses the Pages whose lead forms it collects, and maps each form to contact fields, lists, tags and a consent mode. Meta posts each new lead's ids to /hooks/meta-leads/{token}; the delivery is verified, stored as it came and answered at once, and a River job fetches the lead with the Page's token and signs the person up, once per lead, with the form's consent as evidence. When the webhook is quiet (or the instance can't be reached from the internet), active forms are polled every 15 minutes; a refused token turns the connection to Needs attention and tells the people who can manage integrations.
Meta is reached through internal/leads/meta only. Never stored: a lead's answers (they go to the contact, or are dropped) and the credentials in clear. Leads aren't audited (their consent records are the evidence); everything a person changes is.
Index ¶
- Constants
- func ConsentSource(formID uuid.UUID) string
- func Erasure() erasure.Source
- func Register(h huma.API, s *Service)
- func RegisterJobs(reg *jobs.Registry, s *Service)
- type ApplyArgs
- type ApplyWorker
- type HealthArgs
- type HealthWorker
- type ImportArgs
- type ImportWorker
- type LeadAdsActivity
- type LeadAdsActivityItem
- type LeadAdsCheckbox
- type LeadAdsConnectInput
- type LeadAdsConnection
- type LeadAdsConnectionItem
- type LeadAdsConnectionList
- type LeadAdsConnectionPath
- type LeadAdsContactRef
- type LeadAdsCredentialsInput
- type LeadAdsFieldOption
- type LeadAdsForm
- type LeadAdsFormDetail
- type LeadAdsFormPath
- type LeadAdsImport
- type LeadAdsListOption
- type LeadAdsListRef
- type LeadAdsMappingInput
- type LeadAdsPage
- type LeadAdsPageChoice
- type LeadAdsPageChoices
- type LeadAdsPagesInput
- type LeadAdsQuestion
- type LeadAdsReceiving
- type LeadAdsSetup
- type LeadAdsWebhook
- type Service
- func (s *Service) Activity(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsActivity, error)
- func (s *Service) ApplyEvent(ctx context.Context, id uuid.UUID) error
- func (s *Service) Check(ctx context.Context, c store.LeadConnection, reachable bool) error
- func (s *Service) ChoosePages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LeadAdsConnection, error)
- func (s *Service) Confirmed(ctx context.Context, tx pgx.Tx, ws *store.Workspace, contactID uuid.UUID, ...) error
- func (s *Service) Connect(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (LeadAdsConnection, error)
- func (s *Service) Disconnect(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
- func (s *Service) FormDetail(ctx context.Context, ws *store.Workspace, id uuid.UUID) (LeadAdsFormDetail, error)
- func (s *Service) Get(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
- func (s *Service) Health(ctx context.Context) error
- func (s *Service) Import(ctx context.Context, formID uuid.UUID, last bool) error
- func (s *Service) List(ctx context.Context, ws *store.Workspace) (LeadAdsConnectionList, error)
- func (s *Service) PageChoices(ctx context.Context, ws *store.Workspace, id uuid.UUID) (LeadAdsPageChoices, error)
- func (s *Service) Refresh(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
- func (s *Service) ReplaceCredentials(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LeadAdsConnection, error)
- func (s *Service) Requeue(ctx context.Context) error
- func (s *Service) Routes(r chi.Router)
- func (s *Service) SaveMapping(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LeadAdsFormDetail, error)
- func (s *Service) SetFormStatus(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LeadAdsFormDetail, error)
- func (s *Service) Setup(ctx context.Context, ws *store.Workspace) (LeadAdsSetup, error)
- func (s *Service) StartImport(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsFormDetail, error)
- func (s *Service) Summary(ctx context.Context, ws *store.Workspace) (Summary, bool, error)
- type Summary
- type TickArgs
- type TickWorker
Constants ¶
const ( TargetEmail = "email" TargetFirstName = "first_name" TargetLastName = "last_name" TargetFullName = "full_name" TargetCompany = "company" TargetPhone = "phone" )
What a question can be saved as (lead_forms.mapping values); custom fields are "field:<key>".
const ( StatusConnected = "connected" StatusAttention = "attention" StatusDisconnected = "disconnected" )
Statuses of a connection.
const ( ProblemTokenRejected = "token_rejected" ProblemTokenExpired = "token_expired" ProblemAppRejected = "app_rejected" ProblemPermissionMissing = "permission_missing" )
Problems of a connection that needs attention (status_detail).
const ( PollingNotSubscribed = "not_subscribed" PollingQuiet = "quiet" PollingUnreachable = "unreachable" )
Why leads are polled (polling_reason).
const ( OutcomeCreated = "created" OutcomeUpdated = "updated" OutcomePending = "pending" OutcomeBlocked = "blocked" OutcomeInvalid = "invalid" OutcomeDeclined = "declined" OutcomeTest = "test" )
Outcomes of a lead (lead_entries.outcome).
const ( SourceWebhook = "webhook" SourcePoll = "poll" SourceImport = "import" )
Where a lead came from (lead_entries.source).
const ( // HealthEvery is how often connections are checked, their forms // refreshed and, when the webhook is quiet, polled. HealthEvery = 15 * time.Minute // QuietAfter is how long without a delivery, while forms are active, // before leads are polled. QuietAfter = 24 * time.Hour // Kept is how long Meta's deliveries are kept. Kept = 30 * 24 * time.Hour // ImportWindow is how far back Import past leads goes. ImportWindow = 90 * 24 * time.Hour // RateLimitWait is how long Meta's rate limits pause a connection's calls. RateLimitWait = 15 * time.Minute )
Timings.
const ( MaxBody = 1 << 20 MaxRejected = 2048 )
MaxBody is the largest delivery accepted; MaxRejected how much of a refused one is kept.
const ConsentSourcePrefix = "lead_ad:"
ConsentSourcePrefix starts a lead's consent source: "lead_ad:<form id>".
const Platform = "meta"
Platform is the only lead ads platform (lead_connections.platform).
Variables ¶
This section is empty.
Functions ¶
func ConsentSource ¶
ConsentSource is a lead form's consent source.
func Erasure ¶
Erasure is what lead ads keep about a contact: which lead form they sent and when. The entries stay without the contact, so a later import of past leads never brings an erased person back (their lead's id is recorded). Meta's deliveries hold only ids, never answers, and go after 30 days.
func Register ¶
Register adds the lead ads operations: reading needs integrations:view, every change integrations:manage and a signed-in member.
func RegisterJobs ¶
RegisterJobs adds the lead ads workers and their schedules: deliveries applied as they arrive (and requeued every minute when a job was lost), every connection checked every 15 minutes (its token, its forms, and its active forms polled while the webhook is quiet), past leads imported on request.
Types ¶
type ApplyArgs ¶
type ApplyArgs struct {
EventID string `json:"event_id"`
}
ApplyArgs applies one stored delivery.
func (ApplyArgs) InsertOpts ¶
func (ApplyArgs) InsertOpts() river.InsertOpts
InsertOpts runs on the events queue.
type ApplyWorker ¶
type ApplyWorker struct {
river.WorkerDefaults[ApplyArgs]
S *Service
}
ApplyWorker applies stored deliveries.
type HealthArgs ¶
type HealthArgs struct{}
HealthArgs checks every connection.
func (HealthArgs) InsertOpts ¶
func (HealthArgs) InsertOpts() river.InsertOpts
InsertOpts: one check at a time.
type HealthWorker ¶
type HealthWorker struct {
river.WorkerDefaults[HealthArgs]
S *Service
}
HealthWorker checks connections.
func (*HealthWorker) Work ¶
func (w *HealthWorker) Work(ctx context.Context, _ *river.Job[HealthArgs]) error
Work implements river.Worker.
type ImportArgs ¶
type ImportArgs struct {
FormID string `json:"form_id"`
}
ImportArgs imports a form's leads of the last 90 days.
func (ImportArgs) InsertOpts ¶
func (ImportArgs) InsertOpts() river.InsertOpts
InsertOpts runs on the default queue.
type ImportWorker ¶
type ImportWorker struct {
river.WorkerDefaults[ImportArgs]
S *Service
}
ImportWorker imports past leads.
func (*ImportWorker) Work ¶
func (w *ImportWorker) Work(ctx context.Context, job *river.Job[ImportArgs]) error
Work implements river.Worker.
type LeadAdsActivity ¶
type LeadAdsActivity struct {
Items []LeadAdsActivityItem `json:"items"`
}
LeadAdsActivity is a connection's recent leads.
type LeadAdsActivityItem ¶
type LeadAdsActivityItem struct {
ID string `json:"id"`
At time.Time `json:"at" doc:"When ReputeCast recorded it"`
LeadAt time.Time `json:"leadAt" doc:"When the person sent the form"`
FormID string `json:"formId"`
FormName string `json:"formName"`
Page string `json:"page"`
Outcome string `json:"outcome" enum:"created,updated,pending,blocked,invalid,declined,test"`
Source string `json:"source" enum:"webhook,poll,import"`
// Contact is set for people who may see contacts; Hidden says there
// is one they may not see ("a contact").
Contact *LeadAdsContactRef `json:"contact,omitempty"`
Hidden bool `json:"hidden"`
}
LeadAdsActivityItem is one lead: when, which form, what happened and the contact. Answers aren't shown.
type LeadAdsCheckbox ¶
type LeadAdsCheckbox struct {
Key string `json:"key"`
Text string `json:"text"`
Required bool `json:"required"`
}
LeadAdsCheckbox is one of the custom disclaimer's checkboxes.
type LeadAdsConnectInput ¶
type LeadAdsConnectInput struct {
Name string `json:"name" minLength:"1" maxLength:"80" example:"Acme Marketing"`
AppID string `json:"appId" minLength:"1" maxLength:"32" pattern:"^[0-9]+$" doc:"The Meta app's id, from App settings › Basic"`
AppSecret string `json:"appSecret" minLength:"16" maxLength:"64" doc:"The app secret, from App settings › Basic (write-only)"`
Token string `json:"token" minLength:"20" maxLength:"1024" doc:"A system user's token for the app, with no expiry (write-only)"`
}
LeadAdsConnectInput is the connect dialog's second step.
type LeadAdsConnection ¶
type LeadAdsConnection struct {
ID string `json:"id"`
Name string `json:"name" example:"Acme Marketing"`
Platform string `json:"platform" enum:"meta"`
// AppID is the Meta app's id (not a secret).
AppID string `json:"appId" example:"481516234200"`
Status string `json:"status" enum:"connected,attention,disconnected"`
// Problem says why it needs attention: Meta refused the token (or it
// expired), the app id and secret, or a permission.
Problem string `json:"problem,omitempty" enum:"token_rejected,token_expired,app_rejected,permission_missing,"`
// Receiving says how leads arrive: Meta's webhook, or polling every 15
// minutes and why.
Receiving LeadAdsReceiving `json:"receiving"`
// RateLimitedUntil: Meta asked to slow down; calls resume then.
RateLimitedUntil *time.Time `json:"rateLimitedUntil,omitempty"`
CheckedAt *time.Time `json:"checkedAt,omitempty" doc:"When the token was last checked"`
CreatedAt time.Time `json:"createdAt"`
CreatedBy string `json:"createdBy"`
DisconnectedAt *time.Time `json:"disconnectedAt,omitempty"`
Pages []LeadAdsPage `json:"pages" doc:"The chosen Pages and their lead forms"`
Leads30d int64 `json:"leads30d" doc:"Leads in the last 30 days, Meta's test leads left out"`
// Webhook is the callback URL and verify token, for setting the
// subscription by hand in Meta's app dashboard: only for people who
// can manage integrations.
Webhook *LeadAdsWebhook `json:"webhook,omitempty"`
// CanManage: the caller holds integrations:manage; Helpers are who
// hold it (named for everyone, up to two).
CanManage bool `json:"canManage"`
Helpers []string `json:"helpers"`
}
LeadAdsConnection is Settings › Integrations › Meta Lead Ads.
type LeadAdsConnectionItem ¶
type LeadAdsConnectionItem struct {
ID string `json:"id"`
Name string `json:"name" example:"Acme Marketing"`
Status string `json:"status" enum:"connected,attention,disconnected"`
CreatedAt time.Time `json:"createdAt"`
}
LeadAdsConnectionItem is one connection in the list.
type LeadAdsConnectionList ¶
type LeadAdsConnectionList struct {
Items []LeadAdsConnectionItem `json:"items"`
}
LeadAdsConnectionList is the workspace's Meta connections, the live one first.
type LeadAdsConnectionPath ¶
type LeadAdsConnectionPath struct {
api.WorkspaceInput
ID string `path:"id" doc:"The connection's id"`
}
LeadAdsConnectionPath names a connection in a path.
type LeadAdsContactRef ¶
type LeadAdsContactRef struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Erased bool `json:"erased"`
}
LeadAdsContactRef names a lead's contact.
type LeadAdsCredentialsInput ¶
type LeadAdsCredentialsInput struct {
Name string `json:"name,omitempty" maxLength:"80"`
AppID string `json:"appId,omitempty" maxLength:"32" pattern:"^[0-9]*$"`
AppSecret string `json:"appSecret,omitempty" maxLength:"64"`
Token string `json:"token,omitempty" maxLength:"1024"`
}
LeadAdsCredentialsInput replaces a connection's name or credentials; a blank secret keeps the stored one.
type LeadAdsFieldOption ¶
type LeadAdsFieldOption struct {
Key string `json:"key"`
Label string `json:"label"`
Type string `json:"type"`
}
LeadAdsFieldOption is a custom field a question can be saved as.
type LeadAdsForm ¶
type LeadAdsForm struct {
ID string `json:"id"`
FormID string `json:"formId" doc:"Meta's id of the form"`
Name string `json:"name" example:"Spring webinar signup"`
PageID string `json:"pageId"`
Page string `json:"page" example:"Acme Inc"`
// MetaStatus is the form's status in Meta: ACTIVE, ARCHIVED, DELETED
// or DRAFT.
MetaStatus string `json:"metaStatus"`
// Status: active or paused; Mapped: it has been mapped, so it collects.
Status string `json:"status" enum:"active,paused"`
Mapped bool `json:"mapped"`
Leads30d int64 `json:"leads30d"`
Lists []LeadAdsListRef `json:"lists"`
Tags []string `json:"tags"`
ConsentMode string `json:"consentMode" enum:"double,single"`
Questions int `json:"questions"`
// Waiting counts leads that arrived while the form wasn't mapped or
// was paused (not stored: Import past leads brings them in).
Waiting int32 `json:"waiting"`
Import LeadAdsImport `json:"import"`
LastLeadAt *time.Time `json:"lastLeadAt,omitempty"`
}
LeadAdsForm is a lead form and how it's collected.
type LeadAdsFormDetail ¶
type LeadAdsFormDetail struct {
Form LeadAdsForm `json:"form"`
Questions []LeadAdsQuestion `json:"questions"`
Checkboxes []LeadAdsCheckbox `json:"checkboxes"`
Disclaimer string `json:"disclaimer" doc:"The custom disclaimer's text"`
// The form's mapping: lists, tags and consent (the questions carry
// their targets).
ListIDs []string `json:"listIds"`
ConsentKey string `json:"consentKey,omitempty"`
ConsentText string `json:"consentText,omitempty" doc:"Single opt-in: the checkbox's text the leads agreed to"`
// Options: the workspace's lists and custom fields.
Lists []LeadAdsListOption `json:"lists"`
Fields []LeadAdsFieldOption `json:"fields"`
}
LeadAdsFormDetail is the mapping dialog: the form's questions and consent checkboxes as Meta returns them, how it's mapped, and what it can be mapped to.
type LeadAdsFormPath ¶
type LeadAdsFormPath struct {
api.WorkspaceInput
FormID string `path:"formId" doc:"The lead form's id in ReputeCast"`
}
LeadAdsFormPath names a lead form in a path.
type LeadAdsImport ¶
type LeadAdsImport struct {
State string `json:"state" enum:"running,done,failed,"`
Count int32 `json:"count" doc:"Leads read so far, or in the finished import"`
At *time.Time `json:"at,omitempty" doc:"When the last import finished"`
}
LeadAdsImport is a form's Import past leads.
type LeadAdsListOption ¶
type LeadAdsListOption struct {
ID string `json:"id"`
Name string `json:"name"`
// DoubleOptIn is the list's default for new signups; a lead form's
// consent mode decides for its leads.
DoubleOptIn bool `json:"doubleOptIn"`
}
LeadAdsListOption is a list leads can join.
type LeadAdsListRef ¶
LeadAdsListRef is a list a form's leads join.
type LeadAdsMappingInput ¶
type LeadAdsMappingInput struct {
// Mapping is question key → email, first_name, last_name, full_name,
// company, phone or field:<custom field key>; questions left out aren't
// kept.
Mapping map[string]string `json:"mapping" maxProperties:"60"`
ListIDs []string `json:"listIds" minItems:"1" maxItems:"20"`
Tags []string `json:"tags,omitempty" maxItems:"10"`
ConsentMode string `json:"consentMode" enum:"double,single"`
// ConsentKey is the checkbox that is the consent, for single opt-in.
ConsentKey string `json:"consentKey,omitempty" maxLength:"200"`
}
LeadAdsMappingInput maps a form.
type LeadAdsPage ¶
type LeadAdsPage struct {
ID string `json:"id"`
PageID string `json:"pageId" doc:"Meta's id of the Page"`
Name string `json:"name" example:"Acme Inc"`
SubscribedAt *time.Time `json:"subscribedAt,omitempty"`
Forms []LeadAdsForm `json:"forms"`
}
LeadAdsPage is a chosen Facebook Page.
type LeadAdsPageChoice ¶
type LeadAdsPageChoice struct {
PageID string `json:"pageId"`
Name string `json:"name" example:"Acme Inc"`
Chosen bool `json:"chosen"`
// Forms is the Page's lead forms (left out past the first 25 Pages).
Forms *int `json:"forms,omitempty"`
}
LeadAdsPageChoice is one Page the token reaches.
type LeadAdsPageChoices ¶
type LeadAdsPageChoices struct {
Items []LeadAdsPageChoice `json:"items"`
}
LeadAdsPageChoices are the Pages the token reaches, for choosing.
type LeadAdsPagesInput ¶
type LeadAdsPagesInput struct {
PageIDs []string `json:"pageIds" maxItems:"100" doc:"Meta's ids of the chosen Pages"`
}
LeadAdsPagesInput chooses the Pages whose leads are collected.
type LeadAdsQuestion ¶
type LeadAdsQuestion struct {
Key string `json:"key" example:"full_name"`
Label string `json:"label" example:"Full name"`
Type string `json:"type" example:"FULL_NAME" doc:"Meta's question type"`
// Target is the mapping ("" when not kept); Suggested what ReputeCast
// proposes for a form not mapped yet.
Target string `json:"target"`
Suggested string `json:"suggested"`
}
LeadAdsQuestion is one of a form's questions and what it's saved as.
type LeadAdsReceiving ¶
type LeadAdsReceiving struct {
Mode string `json:"mode" enum:"webhook,polling"`
// Reason is why leads are polled: Meta refused the app's webhook
// subscription, no delivery for 24 hours while forms are active, or
// the instance isn't reachable from the internet.
Reason string `json:"reason,omitempty" enum:"not_subscribed,quiet,unreachable,"`
URL string `json:"url" doc:"The instance's public URL"`
LastEventAt *time.Time `json:"lastEventAt,omitempty" doc:"Meta's last delivery"`
LastLeadAt *time.Time `json:"lastLeadAt,omitempty"`
LastPolledAt *time.Time `json:"lastPolledAt,omitempty"`
SubscribedAt *time.Time `json:"subscribedAt,omitempty" doc:"When Meta accepted the app's webhook subscription"`
}
LeadAdsReceiving is how leads arrive.
type LeadAdsSetup ¶
type LeadAdsSetup struct {
Permissions []string `json:"permissions"`
URL string `json:"url" doc:"The instance's public URL"`
Reachable bool `json:"reachable" doc:"Meta can reach it, so leads arrive within seconds; otherwise they're polled every 15 minutes"`
// Connection is the workspace's live connection, when there is one:
// one Meta connection per workspace.
Connection *LeadAdsConnectionItem `json:"connection,omitempty"`
}
LeadAdsSetup is what the connect dialog's first step shows: the permissions the token needs and whether Meta can reach this server.
type LeadAdsWebhook ¶
type LeadAdsWebhook struct {
CallbackURL string `json:"callbackUrl"`
VerifyToken string `json:"verifyToken"`
}
LeadAdsWebhook is the callback Meta posts leads to.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Box *secrets.Box
Log *slog.Logger
URLs publicurl.Builder
Audience *audience.Service
Jobs func() *jobs.Client
// HTTP reaches Meta's Graph API through the SSRF guard (the in-process
// Graph API in tests).
HTTP *http.Client
// Demo is the in-process Graph API the demo's connection answers from.
Demo func() *metatest.Fake
// Kick wakes the automations engine after a lead queued an event.
Kick func(ctx context.Context)
// Reachable says whether Meta can reach the instance's public URL,
// and the URL.
Reachable func(ctx context.Context) (url string, ok bool)
Now func() time.Time
}
Service is the lead ads domain.
func (*Service) Activity ¶
func (s *Service) Activity(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsActivity, error)
Activity is a connection's last 50 leads. Contacts are named only for people who may see them.
func (*Service) ApplyEvent ¶
ApplyEvent applies one stored delivery: each lead it names is fetched with its Page's token and recorded once. A delivery Meta can't be asked about now (rate limit, refused token) stays pending; one that can't be read fails for good.
func (*Service) Check ¶
Check checks one connection: its token (a refused one needs attention and is told about once), its Pages' forms, and whether the webhook works. While Meta doesn't push leads (the subscription was refused, the instance isn't reachable, or nothing came for 24 hours while forms are active) the active forms are polled.
func (*Service) ChoosePages ¶
func (s *Service) ChoosePages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in LeadAdsPagesInput) (LeadAdsConnection, error)
ChoosePages subscribes the app to the chosen Pages' leads and lists their forms; Pages left out are unsubscribed (their mappings stay).
func (*Service) Confirmed ¶
func (s *Service) Confirmed(ctx context.Context, tx pgx.Tx, ws *store.Workspace, contactID uuid.UUID, lists []uuid.UUID, at time.Time) error
Confirmed starts "Submitted a lead ad form" for a contact's double opt-in leads once their confirmation joined one of the form's lists (inside the confirmation's transaction).
func (*Service) Connect ¶
func (s *Service) Connect(ctx context.Context, ws *store.Workspace, p *authz.Principal, in LeadAdsConnectInput) (LeadAdsConnection, error)
Connect checks the credentials with Meta, keeps them sealed and subscribes the app to the Pages' leads at the connection's callback URL. Meta checks that address at once, so the connection is stored first; a subscription Meta refuses leaves the connection polling.
func (*Service) Disconnect ¶
func (s *Service) Disconnect(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
Disconnect stops collecting: the Pages are unsubscribed (as far as Meta answers), the credentials and Page tokens deleted and the callback URL stops working. Contacts, their consent and the leads' record stay.
func (*Service) FormDetail ¶
func (s *Service) FormDetail(ctx context.Context, ws *store.Workspace, id uuid.UUID) (LeadAdsFormDetail, error)
FormDetail is the mapping dialog. The form's questions and checkboxes are read from Meta when it answers, so they are current.
func (*Service) Get ¶
func (s *Service) Get(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
Get is a connection's page.
func (*Service) Health ¶
Health checks every connection (the demo's is never polled) and purges deliveries older than 30 days.
func (*Service) Import ¶
Import reads a form's leads of the last 90 days and records each once. Leads already recorded are skipped, so a retried import carries on; a finished one clears the count of leads that waited for the mapping.
func (*Service) PageChoices ¶
func (s *Service) PageChoices(ctx context.Context, ws *store.Workspace, id uuid.UUID) (LeadAdsPageChoices, error)
PageChoices lists the Pages the token reaches, the chosen ones marked.
func (*Service) Refresh ¶
func (s *Service) Refresh(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (LeadAdsConnection, error)
Refresh lists the chosen Pages' forms again (new forms, new questions).
func (*Service) ReplaceCredentials ¶
func (s *Service) ReplaceCredentials(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in LeadAdsCredentialsInput) (LeadAdsConnection, error)
ReplaceCredentials checks and keeps new credentials, then subscribes the app and the chosen Pages again with them. A connection that needed attention is connected again.
func (*Service) Requeue ¶
Requeue applies deliveries still pending two minutes after they arrived (a lost job, or a connection that works again). ApplyEvent leaves those of a connection that's held as they are.
func (*Service) SaveMapping ¶
func (s *Service) SaveMapping(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in LeadAdsMappingInput) (LeadAdsFormDetail, error)
SaveMapping maps a form: each question to a field, its lists and tags, and its consent. Single opt-in needs one of the form's consent checkboxes: its text, as Meta returns it, becomes the consent text and its hash the version. A form mapped for the first time starts collecting.
func (*Service) SetFormStatus ¶
func (s *Service) SetFormStatus(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, status string) (LeadAdsFormDetail, error)
SetFormStatus pauses or resumes a form.
type Summary ¶
type Summary struct {
ID uuid.UUID
Name string
Pages int
Leads30d int64
Polling bool
Problem string
}
Summary is the catalog card's facts about the workspace's connection.
type TickArgs ¶
type TickArgs struct{}
TickArgs runs every minute.
func (TickArgs) InsertOpts ¶
func (TickArgs) InsertOpts() river.InsertOpts
InsertOpts: one tick at a time.
type TickWorker ¶
type TickWorker struct {
river.WorkerDefaults[TickArgs]
S *Service
}
TickWorker requeues deliveries left unapplied.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package meta reads Facebook and Instagram lead ads over Meta's Graph API (M66): the Pages a system user's token reaches and their own tokens, the app's and the Pages' leadgen webhook subscriptions, the Pages' lead forms with their questions and consent checkboxes, one lead by its id, and a form's leads since a moment (polling and importing past leads).
|
Package meta reads Facebook and Instagram lead ads over Meta's Graph API (M66): the Pages a system user's token reaches and their own tokens, the app's and the Pages' leadgen webhook subscriptions, the Pages' lead forms with their questions and consent checkboxes, one lead by its id, and a form's leads since a moment (polling and importing past leads). |
|
metatest
Package metatest is an in-process Graph API for lead ads, with Meta's payloads: the Pages a system user's token reaches and their tokens, the app's and the Pages' webhook subscriptions, lead forms, leads and the webhook bodies Meta posts.
|
Package metatest is an in-process Graph API for lead ads, with Meta's payloads: the Pages a system user's token reaches and their tokens, the app's and the Pages' webhook subscriptions, lead forms, leads and the webhook bodies Meta posts. |