meta

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

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).

It reuses the WhatsApp Graph client (internal/whatsapp/meta) for the transport, its errors and the webhook's verification handshake and X-Hub-Signature-256. Every call made with a system user's or a Page's token carries appsecret_proof, so an app that requires it keeps working and a token on its own is useless to whoever reads it. It knows nothing about workspaces: internal/leads keeps the connection and its sealed credentials. metatest is an in-process Graph API for tests and the demo.

Index

Constants

View Source
const (
	DefaultBaseURL = wa.DefaultBaseURL
	DefaultVersion = wa.DefaultVersion
)

DefaultBaseURL and DefaultVersion are the WhatsApp client's: one Graph API version for every Meta call ReputeCast makes.

Variables

View Source
var ErrNotLeads = errors.New("meta: not a Page webhook")

ErrNotLeads is a delivery that isn't a Page's webhook.

View Source
var Permissions = []string{"leads_retrieval", "pages_show_list", "pages_read_engagement", "pages_manage_metadata", "ads_management"}

Permissions are what the system user's token needs, in the order the connect dialog lists them.

Functions

func Expired

func Expired(err error) bool

Expired reports whether the token expired.

func PermissionMissing

func PermissionMissing(err error) bool

PermissionMissing reports whether the token lacks a permission (10, 200 to 299) or lead access (Leads Access Manager answers with 100/33 or 200).

func Proof

func Proof(appSecret, token string) string

Proof is appsecret_proof for a token: the hex HMAC-SHA256 of the token with the app secret.

func RateLimited

func RateLimited(err error) bool

RateLimited reports whether Meta asks to slow down: the app, user, Page or lead ads rate limits.

func Sign

func Sign(appSecret string, body []byte) string

Sign is the X-Hub-Signature-256 of a body.

func SignatureShape

func SignatureShape(header string) bool

SignatureShape reports whether a header can be a signature at all.

func TokenRejected

func TokenRejected(err error) bool

TokenRejected reports whether Meta refused the token: it expired, was revoked or lost a permission.

func Unavailable

func Unavailable(err error) bool

Unavailable reports a failure worth retrying: no answer or a 5xx.

func VerifyChallenge

func VerifyChallenge(q url.Values, verifyToken string) (string, bool)

VerifyChallenge answers Meta's verification request (hub.challenge when hub.verify_token is ours, compared in constant time).

func VerifySignature

func VerifySignature(appSecret string, body []byte, header string) bool

VerifySignature checks X-Hub-Signature-256 over the raw body.

Types

type Answer

type Answer struct {
	Name   string   `json:"name"`
	Values []string `json:"values"`
}

Answer is one field of a lead: the question's key and its values.

type Checkbox

type Checkbox struct {
	Key      string `json:"key"`
	Text     string `json:"text"`
	Required bool   `json:"required"`
}

Checkbox is one of the custom disclaimer's checkboxes.

type Client

type Client struct {
	Creds Credentials
	// HTTP is the SSRF-guarded client in production, the in-process Graph
	// API in tests and the demo.
	HTTP *http.Client
	// BaseURL and Version default to the Graph API and DefaultVersion.
	BaseURL string
	Version string
}

Client calls the Graph API for one connection.

func (*Client) App

func (c *Client) App(ctx context.Context) (string, error)

App checks the app id and secret together: the app's name, read with the app's own token.

func (*Client) Form

func (c *Client) Form(ctx context.Context, p Page, formID string) (Form, error)

Form reads one lead form.

func (*Client) FormLeads

func (c *Client) FormLeads(ctx context.Context, p Page, formID string, since time.Time, after string) (LeadsPage, error)

FormLeads lists a form's leads created after since, a page at a time.

func (*Client) Forms

func (c *Client) Forms(ctx context.Context, p Page) ([]Form, error)

Forms lists a Page's lead forms with their questions and checkboxes.

func (*Client) GetLead

func (c *Client) GetLead(ctx context.Context, p Page, leadgenID string) (Lead, error)

GetLead reads one lead with the Page's token.

func (*Client) Me

func (c *Client) Me(ctx context.Context) (id, name string, err error)

Me checks the system user's token: its user's id and name.

func (*Client) Pages

func (c *Client) Pages(ctx context.Context) ([]Page, error)

Pages lists every Page the system user's token reaches, with its token.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, p Page) error

Subscribe installs the app on a Page for its leadgen webhook.

func (*Client) SubscribeApp

func (c *Client) SubscribeApp(ctx context.Context, callbackURL, verifyToken string) error

SubscribeApp subscribes the app to Pages' leadgen webhooks at callbackURL. Meta checks the address at once with a verification request carrying verifyToken, so the connection must already be stored.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, p Page) error

Unsubscribe removes the app from a Page.

type Credentials

type Credentials struct {
	AppID     string `json:"appId"`
	AppSecret string `json:"appSecret"`
	// Token is a system user's token for the app (no expiry).
	Token string `json:"token"`
}

Credentials are what connecting asks for, all write-only but the app id.

type Error

type Error = wa.Error

Error is a Graph API error, or a transport failure.

func AsError

func AsError(err error) (*Error, bool)

AsError returns the Graph API error inside err.

type Form

type Form struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Status string `json:"status"`
	Locale string `json:"locale"`
	// Questions and the custom disclaimer: its text and checkboxes.
	Questions  []Question `json:"questions"`
	Disclaimer string     `json:"disclaimer"`
	Checkboxes []Checkbox `json:"checkboxes"`
}

Form is a lead form as Meta lists it.

type Lead

type Lead struct {
	ID          string
	FormID      string
	AdID        string
	CreatedTime time.Time
	Fields      []Answer
	// Checked holds each custom disclaimer checkbox's answer by key.
	Checked map[string]bool
}

Lead is a person's answers to a lead form.

func (Lead) IsTest

func (l Lead) IsTest() bool

IsTest reports whether a lead came from Meta's Lead Ads Testing Tool: its email is Meta's test address, or an answer is the tool's placeholder ("<test lead: dummy data for full_name>").

func (Lead) Value

func (l Lead) Value(key string) string

Value is the first answer to a question ("" when there's none).

type LeadChange

type LeadChange struct {
	LeadgenID   string
	PageID      string
	FormID      string
	AdID        string
	CreatedTime time.Time
}

LeadChange is one new lead a webhook delivery names: ids only, never answers.

func ParseWebhook

func ParseWebhook(body []byte) ([]LeadChange, error)

ParseWebhook reads the leads a delivery names; changes to other fields are skipped.

type LeadsPage

type LeadsPage struct {
	Leads []Lead
	// Next is the cursor of the next page, "" at the end.
	Next string
}

LeadsPage is one page of a form's leads.

type Page

type Page struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	AccessToken string   `json:"access_token"`
	Tasks       []string `json:"tasks"`
}

Page is a Facebook Page the token reaches, with its own token.

type Question

type Question struct {
	Key   string `json:"key"`
	Label string `json:"label"`
	// Type is Meta's: EMAIL, FULL_NAME, FIRST_NAME, LAST_NAME, PHONE,
	// COMPANY_NAME, JOB_TITLE, CUSTOM…
	Type string `json:"type"`
}

Question is a lead form's question.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL