Documentation
¶
Overview ¶
Package lunogram provides a Go client for the Lunogram Client API.
Create a client with your API key and use it to manage users, organizations, events, and scheduled resources in your Lunogram project.
client := lunogram.NewClient("your-api-key")
user, err := client.UpsertUser(ctx, &lunogram.UpsertUserRequest{...})
Index ¶
- func String(s string) *string
- type APIError
- type Client
- func (c *Client) AddOrganizationUser(ctx context.Context, req *OrganizationUserRequest) error
- func (c *Client) DeleteOrganization(ctx context.Context, req *DeleteOrganizationRequest) error
- func (c *Client) DeleteOrganizationScheduled(ctx context.Context, req *DeleteOrganizationScheduledRequest) error
- func (c *Client) DeleteUser(ctx context.Context, req *DeleteUserRequest) error
- func (c *Client) DeleteUserScheduled(ctx context.Context, req *DeleteUserScheduledRequest) error
- func (c *Client) PostOrganizationEvents(ctx context.Context, events []OrganizationEvent) error
- func (c *Client) PostUserEvents(ctx context.Context, events []Event) error
- func (c *Client) RemoveOrganizationUser(ctx context.Context, req *RemoveOrganizationUserRequest) error
- func (c *Client) UpsertOrganization(ctx context.Context, req *UpsertOrganizationRequest) (*Organization, error)
- func (c *Client) UpsertOrganizationScheduled(ctx context.Context, req *UpsertOrganizationScheduledRequest) (*ScheduledAccepted, error)
- func (c *Client) UpsertUser(ctx context.Context, req *UpsertUserRequest) (*User, error)
- func (c *Client) UpsertUserScheduled(ctx context.Context, req *UpsertUserScheduledRequest) (*ScheduledAccepted, error)
- type DeleteOrganizationRequest
- type DeleteOrganizationScheduledRequest
- type DeleteUserRequest
- type DeleteUserScheduledRequest
- type Event
- type ExternalID
- type ExternalIDResponse
- type Option
- type Organization
- type OrganizationEvent
- type OrganizationRef
- type OrganizationUserRequest
- type RemoveOrganizationUserRequest
- type ScheduledAccepted
- type UpsertOrganizationRequest
- type UpsertOrganizationScheduledRequest
- type UpsertUserRequest
- type UpsertUserScheduledRequest
- type User
- type UserRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the Lunogram Client API.
func (*Client) AddOrganizationUser ¶
func (c *Client) AddOrganizationUser(ctx context.Context, req *OrganizationUserRequest) error
AddOrganizationUser adds a user to an organization with optional organization-specific data (e.g. role, department).
func (*Client) DeleteOrganization ¶
func (c *Client) DeleteOrganization(ctx context.Context, req *DeleteOrganizationRequest) error
DeleteOrganization deletes an organization and removes all its memberships.
func (*Client) DeleteOrganizationScheduled ¶
func (c *Client) DeleteOrganizationScheduled(ctx context.Context, req *DeleteOrganizationScheduledRequest) error
DeleteOrganizationScheduled deletes all scheduled instances for an organization with the given resource name. This cancels any pending journey entrance states.
func (*Client) DeleteUser ¶
func (c *Client) DeleteUser(ctx context.Context, req *DeleteUserRequest) error
DeleteUser deletes a user by their external identifier(s).
func (*Client) DeleteUserScheduled ¶
func (c *Client) DeleteUserScheduled(ctx context.Context, req *DeleteUserScheduledRequest) error
DeleteUserScheduled deletes all scheduled instances for a user with the given resource name. This cancels any pending journey entrance states.
func (*Client) PostOrganizationEvents ¶
func (c *Client) PostOrganizationEvents(ctx context.Context, events []OrganizationEvent) error
PostOrganizationEvents sends one or more events for organizations. Events are processed asynchronously and can trigger journeys for all users in the targeted organization(s).
func (*Client) PostUserEvents ¶
PostUserEvents sends one or more events for users. Events are processed asynchronously and can trigger journeys or update virtual lists.
Each event is handled independently: if one fails, others may still succeed.
func (*Client) RemoveOrganizationUser ¶
func (c *Client) RemoveOrganizationUser(ctx context.Context, req *RemoveOrganizationUserRequest) error
RemoveOrganizationUser removes a user from an organization.
func (*Client) UpsertOrganization ¶
func (c *Client) UpsertOrganization(ctx context.Context, req *UpsertOrganizationRequest) (*Organization, error)
UpsertOrganization creates or updates an organization by external identifier(s).
func (*Client) UpsertOrganizationScheduled ¶
func (c *Client) UpsertOrganizationScheduled(ctx context.Context, req *UpsertOrganizationScheduledRequest) (*ScheduledAccepted, error)
UpsertOrganizationScheduled creates or updates a scheduled resource for an organization. This triggers journey entrance recalculation for any journeys that depend on the scheduled resource.
func (*Client) UpsertUser ¶
UpsertUser creates or updates a user profile. The user is identified by one or more external identifiers. If a user with any of the given identifiers already exists, it is updated; otherwise a new user is created.
func (*Client) UpsertUserScheduled ¶
func (c *Client) UpsertUserScheduled(ctx context.Context, req *UpsertUserScheduledRequest) (*ScheduledAccepted, error)
UpsertUserScheduled creates or updates a scheduled resource for a user. This triggers journey entrance recalculation for any journeys that depend on the scheduled resource.
type DeleteOrganizationRequest ¶
type DeleteOrganizationRequest struct {
Identifier []ExternalID `json:"identifier"`
}
DeleteOrganizationRequest deletes an organization by identifier.
type DeleteOrganizationScheduledRequest ¶
type DeleteOrganizationScheduledRequest struct {
// Name of the scheduled resource to delete.
Name string `json:"name"`
// Identifier targets a specific organization.
Identifier []ExternalID `json:"identifier"`
}
DeleteOrganizationScheduledRequest deletes all scheduled instances for an organization with the given name.
type DeleteUserRequest ¶
type DeleteUserRequest struct {
Identifier []ExternalID `json:"identifier"`
}
DeleteUserRequest deletes a user by identifier.
type DeleteUserScheduledRequest ¶
type DeleteUserScheduledRequest struct {
// Name of the scheduled resource to delete.
Name string `json:"name"`
// Identifier targets a specific user.
Identifier []ExternalID `json:"identifier,omitempty"`
}
DeleteUserScheduledRequest deletes all scheduled instances for a user with the given name.
type Event ¶
type Event struct {
// Name of the event (e.g. "purchase_completed").
Name string `json:"name"`
// Identifier targets a specific user. Mutually exclusive with Match.
Identifier []ExternalID `json:"identifier,omitempty"`
// Match is a JSONB containment filter to target users by data attributes.
// Mutually exclusive with Identifier.
Match map[string]any `json:"match,omitempty"`
// Data holds event-specific attributes.
Data map[string]any `json:"data"`
}
Event represents a user event to be ingested.
type ExternalID ¶
type ExternalID struct {
// Source of the identifier (e.g. "default", "anonymous", or a custom source).
// Defaults to "default" if empty.
Source string `json:"source,omitempty"`
// ExternalID is the identifier value in the external system.
ExternalID string `json:"external_id"`
// Metadata is optional key-value data associated with this identifier.
Metadata map[string]any `json:"metadata,omitempty"`
}
ExternalID identifies a user or organization by an external system identifier.
type ExternalIDResponse ¶
type ExternalIDResponse struct {
ID string `json:"id"`
Source string `json:"source"`
ExternalID string `json:"external_id"`
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ExternalIDResponse is an external identifier as returned in API responses.
type Option ¶
type Option func(*Client)
Option configures the Client.
func WithBaseURL ¶
WithBaseURL overrides the default API base URL.
func WithHTTPClient ¶
WithHTTPClient sets a custom http.Client for requests.
func WithTimeout ¶
WithTimeout sets the HTTP client timeout. Ignored if WithHTTPClient is also used.
type Organization ¶
type Organization struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
Identifier []ExternalIDResponse `json:"identifier"`
Name string `json:"name,omitempty"`
Data map[string]any `json:"data"`
Version int32 `json:"version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Organization represents an organization in Lunogram.
type OrganizationEvent ¶
type OrganizationEvent struct {
// Name of the event (e.g. "subscription_upgraded").
Name string `json:"name"`
// Identifier targets a specific organization. Mutually exclusive with Match.
Identifier []ExternalID `json:"identifier,omitempty"`
// Match is a JSONB containment filter to target organizations by data attributes.
// Mutually exclusive with Identifier.
Match map[string]any `json:"match,omitempty"`
// Data holds event-specific attributes.
Data map[string]any `json:"data,omitempty"`
}
OrganizationEvent represents an organization event to be ingested.
type OrganizationRef ¶
type OrganizationRef struct {
Identifier []ExternalID `json:"identifier"`
}
OrganizationRef identifies an organization by its external identifiers.
type OrganizationUserRequest ¶
type OrganizationUserRequest struct {
Organization OrganizationRef `json:"organization"`
User UserRef `json:"user"`
// Data holds organization-specific attributes for this user (e.g. role, department).
Data map[string]any `json:"data,omitempty"`
}
OrganizationUserRequest adds a user to an organization.
type RemoveOrganizationUserRequest ¶
type RemoveOrganizationUserRequest struct {
Organization OrganizationRef `json:"organization"`
User UserRef `json:"user"`
}
RemoveOrganizationUserRequest removes a user from an organization.
type ScheduledAccepted ¶
type ScheduledAccepted struct {
ID string `json:"id"`
Name string `json:"name"`
ScheduledAt time.Time `json:"scheduled_at"`
Data map[string]any `json:"data,omitempty"`
}
ScheduledAccepted is returned when a scheduled resource is accepted for processing.
type UpsertOrganizationRequest ¶
type UpsertOrganizationRequest struct {
Identifier []ExternalID `json:"identifier"`
Name *string `json:"name,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
UpsertOrganizationRequest creates or updates an organization.
type UpsertOrganizationScheduledRequest ¶
type UpsertOrganizationScheduledRequest struct {
// Name of the scheduled resource (e.g. "contract_renewal").
Name string `json:"name"`
// Identifier targets a specific organization.
Identifier []ExternalID `json:"identifier"`
// ScheduledAt is the trigger time for single schedules.
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
// StartAt is the start time for recurring schedules. Defaults to now if omitted.
StartAt *time.Time `json:"start_at,omitempty"`
// Interval for recurring schedules (e.g. "24h"). When set, the schedule becomes recurring.
Interval *string `json:"interval,omitempty"`
// Data holds scheduled resource attributes.
Data map[string]any `json:"data,omitempty"`
}
UpsertOrganizationScheduledRequest creates or updates a scheduled resource for an organization.
type UpsertUserRequest ¶
type UpsertUserRequest struct {
// Identifier contains one or more external identifiers for the user.
Identifier []ExternalID `json:"identifier"`
// Email address of the user.
Email *string `json:"email,omitempty"`
// Phone number in E.164 format (e.g. "+31612345678").
Phone *string `json:"phone,omitempty"`
// Timezone in IANA format (e.g. "Europe/Amsterdam").
Timezone *string `json:"timezone,omitempty"`
// Locale as a BCP 47 tag (e.g. "nl-NL").
Locale *string `json:"locale,omitempty"`
// Data holds arbitrary user attributes.
Data map[string]any `json:"data,omitempty"`
}
UpsertUserRequest creates or updates a user profile.
type UpsertUserScheduledRequest ¶
type UpsertUserScheduledRequest struct {
// Name of the scheduled resource (e.g. "renewal_date").
Name string `json:"name"`
// Identifier targets a specific user.
Identifier []ExternalID `json:"identifier,omitempty"`
// ScheduledAt is the trigger time for single schedules.
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
// StartAt is the start time for recurring schedules. Defaults to now if omitted.
StartAt *time.Time `json:"start_at,omitempty"`
// Interval for recurring schedules (e.g. "24h"). When set, the schedule becomes recurring.
Interval *string `json:"interval,omitempty"`
// Data holds scheduled resource attributes.
Data map[string]any `json:"data,omitempty"`
}
UpsertUserScheduledRequest creates or updates a scheduled resource for a user.
type User ¶
type User struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
Identifier []ExternalIDResponse `json:"identifier"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Data map[string]any `json:"data"`
Timezone string `json:"timezone,omitempty"`
Locale string `json:"locale,omitempty"`
HasPushDevice bool `json:"has_push_device"`
Version int32 `json:"version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
User represents a user profile in Lunogram.
type UserRef ¶
type UserRef struct {
Identifier []ExternalID `json:"identifier"`
}
UserRef identifies a user by its external identifiers.