flow

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategorySignUp             = "SIGN_UP"
	CategorySignIn             = "SIGN_IN"
	CategoryAppointmentBooking = "APPOINTMENT_BOOKING"
	CategoryLeadGeneration     = "LEAD_GENERATION"
	CategoryContactUs          = "CONTACT_US"
	CategoryCustomerSupport    = "CUSTOMER_SUPPORT"
	CategorySurvey             = "SURVEY"
	CategoryOther              = "OTHER"
	StatusDraft                = "DRAFT"
	StatusPublished            = "PUBLISHED"
	StatusDeprecated           = "DEPRECATED"
	StatusBlocked              = "BLOCKED"
	StatusThrottled            = "THROTTLED"
	HealthStatusAvailable      = "AVAILABLE"
	HealthStatusLimited        = "LIMITED"
	HealthStatusBlocked        = "BLOCKED"
)
View Source
const (
	MetricEndpointRequestCount              metricEndpoint = "ENDPOINT_REQUEST_COUNT"
	MetricEndpointRequestError              metricEndpoint = "ENDPOINT_REQUEST_ERROR"
	MetricEndpointRequestErrorRate          metricEndpoint = "ENDPOINT_REQUEST_ERROR_RATE"
	MetricEndpointRequestLatencySecondsCeil metricEndpoint = "ENDPOINT_REQUEST_LATENCY_SECONDS_CEIL"
	MetricEndpointAvailability              metricEndpoint = "ENDPOINT_AVAILABILITY"
)
View Source
const (
	GranularityDay      granularity = "DAY"
	GranularityHour     granularity = "HOUR"
	GranularityLifetime granularity = "LIFETIME"
)

Variables

This section is empty.

Functions

func ConfigurePreviewURL

func ConfigurePreviewURL(response *PreviewResponse, options *PreviewURLConfigOptions) (string, error)

Types

type Asset

type Asset struct {
	Name        string `json:"name"`
	AssetType   string `json:"asset_type"`
	DownloadURL string `json:"download_url"`
}

type BaseClient

type BaseClient struct {
	Reader config.Reader
	Sender whttp.AnySender
}

func NewBaseClient

func NewBaseClient(reader config.Reader, sender whttp.AnySender) *BaseClient

func (*BaseClient) Create

func (client *BaseClient) Create(ctx context.Context, request CreateRequest) (*CreateResponse, error)

func (*BaseClient) Delete

func (client *BaseClient) Delete(ctx context.Context, id string) (*SuccessResponse, error)

func (*BaseClient) Deprecate

func (client *BaseClient) Deprecate(ctx context.Context, id string) (*SuccessResponse, error)

func (*BaseClient) GeneratePreview

func (client *BaseClient) GeneratePreview(ctx context.Context, request *PreviewRequest) (*PreviewResponse, error)

func (*BaseClient) Get

func (client *BaseClient) Get(ctx context.Context, request *GetRequest) (*SingleFlowResponse, error)

func (*BaseClient) GetFlowMetrics

func (client *BaseClient) GetFlowMetrics(ctx context.Context, request *MetricsRequest) (*MetricsAPIResponse, error)

func (*BaseClient) ListAll

func (client *BaseClient) ListAll(ctx context.Context) (*ListResponse, error)

func (*BaseClient) ListAssets

func (client *BaseClient) ListAssets(ctx context.Context, id string) (*RetrieveAssetsResponse, error)

func (*BaseClient) Publish

func (client *BaseClient) Publish(ctx context.Context, id string) (*SuccessResponse, error)

func (*BaseClient) Send

func (client *BaseClient) Send(ctx context.Context, conf *config.Config, req *BaseRequest) (*BaseResponse, error)

func (*BaseClient) Update

func (client *BaseClient) Update(ctx context.Context, id string, request UpdateRequest) (*UpdateResponse, error)

func (*BaseClient) UpdateFlowJSON

func (client *BaseClient) UpdateFlowJSON(ctx context.Context,
	request *UpdateFlowJSONRequest,
) (*UpdateFlowJSONResponse, error)

type BaseRequest

type BaseRequest struct {
	Type        whttp.RequestType
	Method      string
	Endpoints   []string // follows after baseURL/version
	QueryParams map[string]string
	Payload     any
}

type BaseResponse

type BaseResponse struct {
	ID                      string                 `json:"id,omitempty"`
	Success                 bool                   `json:"success,omitempty"`
	Data                    []*BaseResponseData    `json:"data,omitempty"`
	Paging                  *whttp.Paging          `json:"paging,omitempty"`
	ValidationErrors        []ValidationError      `json:"validation_errors,omitempty"`
	PreviewURL              string                 `json:"preview_url,omitempty"`
	ExpiresAt               string                 `json:"expires_at,omitempty"`
	Name                    string                 `json:"name,omitempty"`
	Status                  string                 `json:"status,omitempty"`
	Categories              []string               `json:"categories,omitempty"`
	JSONVersion             string                 `json:"json_version,omitempty"`
	DataAPIVersion          string                 `json:"data_api_version,omitempty"`
	EndpointURI             string                 `json:"endpoint_uri,omitempty"`
	Preview                 Preview                `json:"preview,omitempty"`
	WhatsAppBusinessAccount map[string]interface{} `json:"whatsapp_business_account,omitempty"` // Optional
	Application             map[string]interface{} `json:"application,omitempty"`               // Optional
	HealthStatus            HealthStatus           `json:"health_status,omitempty"`
}

func (*BaseResponse) FlowDetails

func (baseResp *BaseResponse) FlowDetails() *SingleFlowResponse

FlowDetails converts BaseResponse into a SingleFlowResponse.

func (*BaseResponse) ListAssetsResponse

func (baseResp *BaseResponse) ListAssetsResponse() *RetrieveAssetsResponse

func (*BaseResponse) ListResponse

func (baseResp *BaseResponse) ListResponse() *ListResponse

type BaseResponseData

type BaseResponseData struct {
	Name             string            `json:"name,omitempty"`
	AssetType        string            `json:"asset_type,omitempty"`
	DownloadURL      string            `json:"download_url,omitempty"`
	ID               string            `json:"id,omitempty"`
	Status           string            `json:"status,omitempty"`
	Categories       []string          `json:"categories,omitempty"`
	ValidationErrors []ValidationError `json:"validation_errors,omitempty"`
}

type CreateRequest

type CreateRequest struct {
	Name        string   `json:"name,omitempty"`
	Categories  []string `json:"categories,omitempty"`
	CloneFlowID string   `json:"clone_flow_id,omitempty"`
	EndpointURI string   `json:"endpoint_uri,omitempty"`
}

type CreateResponse

type CreateResponse struct {
	ID string `json:"id"`
}

type DataExchangeHandler

type DataExchangeHandler interface {
	Handle(ctx context.Context, request *DataExchangeRequest) (*Response, error)
}

type DataExchangeHandlerFunc

type DataExchangeHandlerFunc func(ctx context.Context, request *DataExchangeRequest) (*Response, error)

func (DataExchangeHandlerFunc) Handle

type DataExchangeHandlerImpl

type DataExchangeHandlerImpl struct {
	Handler          DataExchangeHandler
	PrivateKeyLoader func(ctx context.Context) (*rsa.PrivateKey, error)
}

func NewDataExchangeHandler

func NewDataExchangeHandler(loader func(ctx context.Context) (*rsa.PrivateKey, error),
	baseHandler DataExchangeHandler, mws ...DataExchangeRequestHandlerMiddleware,
) *DataExchangeHandlerImpl

func (*DataExchangeHandlerImpl) DecryptRequest

func (h *DataExchangeHandlerImpl) DecryptRequest(ctx context.Context, request *Request) (*DecryptedRequest, error)

func (*DataExchangeHandlerImpl) EncryptResponse

func (h *DataExchangeHandlerImpl) EncryptResponse(response *Response, request *DecryptedRequest) (string, error)

func (*DataExchangeHandlerImpl) Handle

func (h *DataExchangeHandlerImpl) Handle(w http.ResponseWriter, request *http.Request)

type DataExchangeRequest

type DataExchangeRequest struct {
	Version   string                 `json:"version"`
	Action    string                 `json:"action"`
	Screen    string                 `json:"screen"`
	Data      map[string]interface{} `json:"data"`
	FlowToken string                 `json:"flow_token"`
}

type DataExchangeRequestHandlerMiddleware

type DataExchangeRequestHandlerMiddleware func(handlerFunc DataExchangeHandlerFunc) DataExchangeHandlerFunc

type DataPoint

type DataPoint struct {
	Timestamp string        `json:"timestamp"`
	Data      []*MetricData `json:"data"`
}

type DecryptedRequest

type DecryptedRequest struct {
	FlowData      []byte
	AesKey        []byte
	InitialVector []byte
}

type EntityError

type EntityError struct {
	ErrorCode        int    `json:"error_code"`
	ErrorDescription string `json:"error_description"`
	PossibleSolution string `json:"possible_solution"`
}

type Event

type Event int
const (
	EventUserOpenFlow Event = iota
	EventUserSubmitScreen
	EventUserPressBackButton
	EventUserChangeComponent
	EventInvalidContentReply
	EventHealthCheck
)

type FinalScreenResponseData

type FinalScreenResponseData struct {
	FlowToken      string
	OptionalParams map[string]interface{}
}

type Flow

type Flow struct {
	ID               string            `json:"id"`
	Name             string            `json:"name"`
	Status           string            `json:"status"`
	Categories       []string          `json:"categories"`
	ValidationErrors []ValidationError `json:"validation_errors"`
}

type GetRequest

type GetRequest struct {
	FlowID string
	Fields []string
}

type HealthStatus

type HealthStatus struct {
	CanSendMessage string               `json:"can_send_message"`
	Entities       []HealthStatusEntity `json:"entities"`
}

type HealthStatusEntity

type HealthStatusEntity struct {
	EntityType     string        `json:"entity_type"`
	ID             string        `json:"id"`
	CanSendMessage string        `json:"can_send_message"`
	Errors         []EntityError `json:"errors,omitempty"`
	AdditionalInfo []string      `json:"additional_info,omitempty"`
}

type ListResponse

type ListResponse struct {
	Data   []*Flow       `json:"data"`
	Paging *whttp.Paging `json:"paging"`
}

type Metric

type Metric struct {
	Name        string       `json:"name"`
	Granularity string       `json:"granularity"`
	DataPoints  []*DataPoint `json:"data_points"`
}

type MetricData

type MetricData struct {
	Key   string `json:"key"`
	Value int64  `json:"value"`
}

type MetricsAPIResponse

type MetricsAPIResponse struct {
	ID     string  `json:"id"`
	Metric *Metric `json:"metric"`
}

type MetricsRequest

type MetricsRequest struct {
	FlowID      string         `json:"flow_id"`         // Flow ID to get metrics for
	MetricName  metricEndpoint `json:"name"`            // Metric name (e.g., ENDPOINT_REQUEST_ERROR)
	Granularity granularity    `json:"granularity"`     // Time granularity (DAY, HOUR, LIFETIME)
	Since       time.Time      `json:"since,omitempty"` // Start of the time period (optional, YYYY-MM-DD)
	Until       time.Time      `json:"until,omitempty"` // End of the time period (optional, YYYY-MM-DD)
}

type NextScreenResponseData

type NextScreenResponseData struct {
	Screen       string
	Data         map[string]interface{}
	ErrorMessage string
}

type Preview

type Preview struct {
	PreviewURL string `json:"preview_url"`
	ExpiresAt  string `json:"expires_at"`
}

type PreviewRequest

type PreviewRequest struct {
	FlowID     string `json:"flow_id"`    // The ID of the flow being previewed.
	Invalidate bool   `json:"invalidate"` // If true, it invalidates the previous preview and generates a new one.
}

type PreviewResponse

type PreviewResponse struct {
	PreviewURL string `json:"preview_url"` // The URL to visualize the Flow.
	ExpiresAt  string `json:"expires_at"`  // The expiration time of the preview URL.
	ID         string `json:"id"`          // The ID of the flow.
}

PreviewResponse represents the response from the API when generating a preview URL for a Flow.

type PreviewURLConfigOptions

type PreviewURLConfigOptions struct {
	Interactive       bool   // If true, the preview will run in interactive mode.
	FlowToken         string // Token sent with requests for Flows with an endpoint.
	FlowAction        string // The initial action: "navigate" or "data_exchange".
	FlowActionPayload string // JSON-encoded initial screen data.
	PhoneNumber       string // Phone number used for sending the Flow (used for encryption).
	Debug             bool   // Show actions in a separate panel while interacting with the preview.
}

type Request

type Request struct {
	EncryptedFlowData string `json:"encrypted_flow_data"`
	EncryptedAesKey   string `json:"encrypted_aes_key"`
	InitialVector     string `json:"initial_vector"`
}

type Response

type Response struct {
	Screen string                 `json:"screen,omitempty"`
	Data   map[string]interface{} `json:"data"`
}

func CreateErrorAcknowledgmentResponse

func CreateErrorAcknowledgmentResponse(acknowledged bool) *Response

func CreateFinalScreenResponse

func CreateFinalScreenResponse(finalScreenData FinalScreenResponseData) *Response

func CreateHealthCheckResponse

func CreateHealthCheckResponse(status string) *Response

func CreateNextScreenResponse

func CreateNextScreenResponse(nextScreenData NextScreenResponseData) *Response

type RetrieveAssetsResponse

type RetrieveAssetsResponse struct {
	Data   []*Asset      `json:"data"`
	Paging *whttp.Paging `json:"paging"`
}

type Sender

type Sender interface {
	Send(ctx context.Context, conf *config.Config, req *BaseRequest) (*BaseResponse, error)
}

type SenderFunc

type SenderFunc func(ctx context.Context, conf *config.Config, req *BaseRequest) (*BaseResponse, error)

func (SenderFunc) Send

func (fn SenderFunc) Send(ctx context.Context, conf *config.Config, req *BaseRequest) (*BaseResponse, error)

type SenderMiddleware

type SenderMiddleware func(sender SenderFunc) SenderFunc

type Service

type Service interface {
	Create(ctx context.Context, request CreateRequest) (*CreateResponse, error)
	Update(ctx context.Context, id string, request UpdateRequest) (*UpdateResponse, error)
	UpdateFlowJSON(ctx context.Context, request *UpdateFlowJSONRequest) (*UpdateFlowJSONResponse, error)
	ListAll(ctx context.Context) (*ListResponse, error)
	ListAssets(ctx context.Context, id string) (*RetrieveAssetsResponse, error)
	Publish(ctx context.Context, id string) (*SuccessResponse, error)
	Delete(ctx context.Context, id string) (*SuccessResponse, error)
	Deprecate(ctx context.Context, id string) (*SuccessResponse, error)
	GeneratePreview(ctx context.Context, request *PreviewRequest) (*PreviewResponse, error)
	Get(ctx context.Context, request *GetRequest) (*SingleFlowResponse, error)
	GetFlowMetrics(ctx context.Context, request *MetricsRequest) (*MetricsAPIResponse, error)
}

type SingleFlowResponse

type SingleFlowResponse struct {
	ID                      string                 `json:"id"`
	Name                    string                 `json:"name"`
	Status                  string                 `json:"status"`
	Categories              []string               `json:"categories"`
	ValidationErrors        []ValidationError      `json:"validation_errors"`
	JSONVersion             string                 `json:"json_version"`
	DataAPIVersion          string                 `json:"data_api_version"`
	EndpointURI             string                 `json:"endpoint_uri"`
	Preview                 Preview                `json:"preview"`
	WhatsAppBusinessAccount map[string]interface{} `json:"whatsapp_business_account,omitempty"` // Optional
	Application             map[string]interface{} `json:"application,omitempty"`               // Optional
	HealthStatus            HealthStatus           `json:"health_status"`
}

type SuccessResponse

type SuccessResponse struct {
	Success bool `json:"success"`
}

type UpdateFlowJSONRequest

type UpdateFlowJSONRequest struct {
	Name string
	File string
}

type UpdateFlowJSONResponse

type UpdateFlowJSONResponse struct {
	Success          bool              `json:"success"`
	ValidationErrors []ValidationError `json:"validation_errors"`
}

type UpdateRequest

type UpdateRequest struct {
	Name          string   `json:"name,omitempty"`
	Categories    []string `json:"categories,omitempty"`
	EndpointURI   string   `json:"endpoint_uri,omitempty"`
	ApplicationID string   `json:"application_id,omitempty"`
}

type UpdateResponse

type UpdateResponse struct {
	Success bool `json:"success"`
}

type ValidationError

type ValidationError struct {
	Error       string `json:"error"`
	ErrorType   string `json:"error_type"`
	Message     string `json:"message"`
	LineStart   int    `json:"line_start"`
	LineEnd     int    `json:"line_end"`
	ColumnStart int    `json:"column_start"`
	ColumnEnd   int    `json:"column_end"`
}

Jump to

Keyboard shortcuts

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