clients

package
v0.1.78 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotionAPIBase    = "https://api.notion.com/v1"
	NotionAPIVersion = "2022-06-28"
)
View Source
const (
	DriveAPIBase = "https://www.googleapis.com/drive/v3"
)
View Source
const (
	GmailAPIBase = "https://gmail.googleapis.com/gmail/v1"
)

Variables

View Source
var CategoryQueries = map[string]string{
	"unread":    "q=is:unread",
	"inbox":     "labelIds=INBOX",
	"starred":   "labelIds=STARRED",
	"sent":      "labelIds=SENT",
	"important": "labelIds=IMPORTANT",
}

CategoryQueries maps category names to Gmail API query/label

View Source
var ErrResourceNotFound = fmt.Errorf("resource not found")

ErrResourceNotFound is returned when a PostHog resource doesn't exist (HTTP 404).

View Source
var GmailCategories = []string{"unread", "inbox", "starred", "sent", "important"}

GmailCategories are the supported message categories

View Source
var GoogleDocsExportTypes = map[string]string{
	"application/vnd.google-apps.document":     "text/plain",
	"application/vnd.google-apps.spreadsheet":  "text/csv",
	"application/vnd.google-apps.presentation": "text/plain",
}

Google Docs export MIME types

View Source
var TextMimeTypes = map[string]bool{
	"text/plain":             true,
	"text/html":              true,
	"text/css":               true,
	"text/javascript":        true,
	"application/json":       true,
	"application/xml":        true,
	"text/xml":               true,
	"text/markdown":          true,
	"text/csv":               true,
	"application/x-yaml":     true,
	"application/javascript": true,
}

Text-extractable MIME types

View Source
var UnsafeFilenameChars = regexp.MustCompile(`[<>:"/\\|?*\x00-\x1f]`)

UnsafeFilenameChars matches characters unsafe for filenames

Functions

func CleanNotionID

func CleanNotionID(id string) string

CleanID removes dashes from a Notion ID

func DetectCategory

func DetectCategory(labels []string) string

DetectCategory determines the primary category for a message based on labels

func ExtractMessageBody

func ExtractMessageBody(msg map[string]any) string

ExtractMessageBody extracts the best available text body from a Gmail message, trying text/plain first, then falling back to text/html converted to plain text

func ExtractPlainTextBody

func ExtractPlainTextBody(msg map[string]any) string

ExtractPlainTextBody extracts plain text from a Gmail message payload

func ExtractSenderName

func ExtractSenderName(from string) string

ExtractSenderName extracts a clean sender name from a From header "noreply@calendly.com" -> "Calendly" "KAYAK <kayak@msg.kayak.com>" -> "KAYAK"

func FormatSubjectFolder

func FormatSubjectFolder(subject, dateStr, msgID string) string

FormatSubjectFolder creates a folder name from subject, date, and ID

func GetDriveAPICallCount

func GetDriveAPICallCount() int64

GetDriveAPICallCount returns the current API call count

func GetGmailAPICallCount

func GetGmailAPICallCount() int64

GetGmailAPICallCount returns the current API call count

func GetNotionAPICallCount

func GetNotionAPICallCount() int64

GetNotionAPICallCount returns the current API call count

func JSONMarshal

func JSONMarshal(v any) ([]byte, error)

JSONMarshal marshals to JSON

func JSONMarshalIndent

func JSONMarshalIndent(v any) ([]byte, error)

JSONMarshalIndent marshals to indented JSON

func ParseEmailDate

func ParseEmailDate(dateStr string) time.Time

ParseEmailDate parses various email date formats

func ResetDriveAPICallCount

func ResetDriveAPICallCount()

ResetDriveAPICallCount resets the API call counter

func ResetGmailAPICallCount

func ResetGmailAPICallCount()

ResetGmailAPICallCount resets the API call counter

func ResetNotionAPICallCount

func ResetNotionAPICallCount()

ResetNotionAPICallCount resets the API call counter

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename makes a filename safe for filesystem use

func SanitizeFolderName

func SanitizeFolderName(name string) string

SanitizeFolderName makes a folder name safe with shorter limit

func StripHTML

func StripHTML(html string) string

StripHTML removes HTML tags from a string

Types

type DriveClient

type DriveClient struct {
	HTTPClient *http.Client
}

DriveClient provides shared Google Drive API functionality

func NewDriveClient

func NewDriveClient() *DriveClient

NewDriveClient creates a new Google Drive API client

func (*DriveClient) DownloadFile

func (c *DriveClient) DownloadFile(ctx context.Context, token, fileID string) ([]byte, error)

DownloadFile downloads file content

func (*DriveClient) ExportGoogleDoc

func (c *DriveClient) ExportGoogleDoc(ctx context.Context, token, fileID, mimeType string) ([]byte, error)

ExportGoogleDoc exports a Google Doc as text

func (*DriveClient) GetExportMimeType

func (c *DriveClient) GetExportMimeType(mimeType string) string

GetExportMimeType returns the export MIME type for a Google Doc

func (*DriveClient) GetFile

func (c *DriveClient) GetFile(ctx context.Context, token, fileID string) (*DriveFile, error)

GetFile fetches metadata for a single file

func (*DriveClient) GetFileContent

func (c *DriveClient) GetFileContent(ctx context.Context, token string, file *DriveFile) ([]byte, error)

GetFileContent fetches file content, handling Google Docs export automatically

func (*DriveClient) Integration

func (c *DriveClient) Integration() types.IntegrationName

Integration returns the integration name

func (*DriveClient) IsGoogleDoc

func (c *DriveClient) IsGoogleDoc(mimeType string) bool

IsGoogleDoc returns true if the file is a Google Docs type that can be exported

func (*DriveClient) IsTextExtractable

func (c *DriveClient) IsTextExtractable(mimeType string) bool

IsTextExtractable returns true if the file's text content can be extracted

func (*DriveClient) ListFiles

func (c *DriveClient) ListFiles(ctx context.Context, token, query string, maxResults int) ([]*DriveFile, error)

ListFiles lists files from Drive

func (*DriveClient) ParseFile

func (c *DriveClient) ParseFile(fileMap map[string]any) *DriveFile

ParseFile extracts structured data from a Drive API response

func (*DriveClient) Request

func (c *DriveClient) Request(ctx context.Context, token, path string, result any) error

Request makes a GET request to the Drive API

type DriveFile

type DriveFile struct {
	ID           string
	Name         string
	MimeType     string
	Size         int64
	ModifiedTime time.Time
	Parents      []string
	WebViewLink  string
	IsFolder     bool
}

DriveFile represents a Google Drive file

type GmailClient

type GmailClient struct {
	HTTPClient *http.Client
}

GmailClient provides shared Gmail API functionality

func NewGmailClient

func NewGmailClient() *GmailClient

NewGmailClient creates a new Gmail API client

func (*GmailClient) DetectCategory

func (c *GmailClient) DetectCategory(labels []string) string

DetectCategory determines the primary category for a message

func (*GmailClient) ExtractMessageBody

func (c *GmailClient) ExtractMessageBody(msg map[string]any) string

ExtractMessageBody extracts the best available text body from a Gmail message, trying text/plain first, then falling back to text/html converted to plain text

func (*GmailClient) ExtractPlainTextBody

func (c *GmailClient) ExtractPlainTextBody(msg map[string]any) string

ExtractPlainTextBody extracts plain text from a Gmail message payload

func (*GmailClient) GetMessage

func (c *GmailClient) GetMessage(ctx context.Context, token, msgID, format string) (map[string]any, error)

GetMessage fetches a single message with metadata

func (*GmailClient) Integration

func (c *GmailClient) Integration() types.IntegrationName

Integration returns the integration name

func (*GmailClient) ListMessages

func (c *GmailClient) ListMessages(ctx context.Context, token, query string, maxResults int) ([]string, error)

ListMessages lists message IDs with optional query

func (*GmailClient) ParseMessage

func (c *GmailClient) ParseMessage(result map[string]any) *GmailMessage

ParseMessage extracts structured data from a Gmail API response

func (*GmailClient) Request

func (c *GmailClient) Request(ctx context.Context, token, path string, result any) error

type GmailMessage

type GmailMessage struct {
	ID            string
	ThreadID      string
	From          string
	To            string
	Subject       string
	Date          string
	Snippet       string
	Labels        []string
	SenderFolder  string // Sanitized sender for folder name
	SubjectFolder string // Sanitized subject with date and ID
}

GmailMessage represents a parsed Gmail message

type NotionBlock

type NotionBlock struct {
	ID      string
	Type    string
	Content map[string]any
}

NotionBlock represents a Notion block

type NotionClient

type NotionClient struct {
	HTTPClient *http.Client
}

NotionClient provides shared Notion API functionality

func NewNotionClient

func NewNotionClient() *NotionClient

NewNotionClient creates a new Notion API client

func (*NotionClient) BlockToMarkdown

func (c *NotionClient) BlockToMarkdown(block *NotionBlock) string

BlockToMarkdown converts a single block to markdown

func (*NotionClient) BlocksToText

func (c *NotionClient) BlocksToText(blocks []*NotionBlock) string

BlocksToText converts Notion blocks to plain text

func (*NotionClient) ExtractRichText

func (c *NotionClient) ExtractRichText(blockContent map[string]any) string

ExtractRichText extracts plain text from a Notion rich text array

func (*NotionClient) ExtractTitle

func (c *NotionClient) ExtractTitle(obj map[string]any) string

ExtractTitle extracts the title from a Notion object

func (*NotionClient) GetPage

func (c *NotionClient) GetPage(ctx context.Context, token, pageID string) (*NotionPage, error)

GetPage fetches a single page

func (*NotionClient) GetPageBlocks

func (c *NotionClient) GetPageBlocks(ctx context.Context, token, pageID string) ([]*NotionBlock, error)

GetPageBlocks fetches the blocks of a page

func (*NotionClient) Integration

func (c *NotionClient) Integration() types.IntegrationName

Integration returns the integration name

func (*NotionClient) ParsePage

func (c *NotionClient) ParsePage(obj map[string]any) *NotionPage

ParsePage extracts structured data from a Notion API response

func (*NotionClient) PostRequest

func (c *NotionClient) PostRequest(ctx context.Context, token, path string, body any, result any) error

PostRequest makes a POST request to the Notion API

func (*NotionClient) Request

func (c *NotionClient) Request(ctx context.Context, token, path string, result any) error

Request makes a GET request to the Notion API

func (*NotionClient) Search

func (c *NotionClient) Search(ctx context.Context, token string, query string, maxResults int) ([]*NotionPage, error)

Search searches for all accessible content

type NotionPage

type NotionPage struct {
	ID             string
	Type           string // "page" or "database"
	Title          string
	URL            string
	LastEditedTime time.Time
}

NotionPage represents a Notion page or database

type PostHogClient added in v0.1.32

type PostHogClient struct {
	// contains filtered or unexported fields
}

PostHogClient is an HTTP client for the PostHog REST API.

func NewPostHogClient added in v0.1.32

func NewPostHogClient(apiKey, host string) *PostHogClient

NewPostHogClient creates a new PostHog API client. If host is empty, defaults to https://app.posthog.com.

func (*PostHogClient) GetCohort added in v0.1.32

func (c *PostHogClient) GetCohort(ctx context.Context, projectID, cohortID int) (*PostHogCohort, error)

GetCohort retrieves a cohort by numeric ID. Uses: GET /api/projects/{id}/cohorts/{cohortID}/

func (*PostHogClient) GetCurrentKey added in v0.1.57

func (c *PostHogClient) GetCurrentKey(ctx context.Context) (*PostHogPersonalAPIKey, error)

GetCurrentKey validates the API key by calling GET /api/personal_api_keys/@current/. This works for any valid personal API key regardless of scopes.

func (*PostHogClient) GetEvent added in v0.1.32

func (c *PostHogClient) GetEvent(ctx context.Context, projectID int, eventID string) (*PostHogEvent, error)

GetEvent retrieves a single event by its UUID. Uses: GET /api/projects/{id}/events/{eventID}/

func (*PostHogClient) GetFeatureFlag added in v0.1.32

func (c *PostHogClient) GetFeatureFlag(ctx context.Context, projectID, flagID int) (*PostHogFeatureFlag, error)

GetFeatureFlag retrieves a feature flag by numeric ID. Uses: GET /api/projects/{id}/feature_flags/{flagID}/

func (*PostHogClient) GetInsightByShortID added in v0.1.32

func (c *PostHogClient) GetInsightByShortID(ctx context.Context, projectID int, shortID string) (*PostHogInsight, error)

GetInsightByShortID retrieves an insight by short_id using the API filter. Uses: GET /api/projects/{id}/insights/?short_id={shortID}&limit=1

func (*PostHogClient) GetProject added in v0.1.57

func (c *PostHogClient) GetProject(ctx context.Context, projectID int) (*PostHogProject, error)

GetProject retrieves a single project by ID. Uses: GET /api/projects/{id}/ which is a project-scoped endpoint and works with project-scoped API keys (unlike ListProjects).

func (*PostHogClient) ListCohorts added in v0.1.32

func (c *PostHogClient) ListCohorts(ctx context.Context, projectID int) ([]PostHogCohort, error)

ListCohorts returns all cohorts for a project.

func (*PostHogClient) ListEvents added in v0.1.32

func (c *PostHogClient) ListEvents(ctx context.Context, projectID, limit int) ([]PostHogEvent, error)

ListEvents returns recent events for a project.

func (*PostHogClient) ListFeatureFlags added in v0.1.32

func (c *PostHogClient) ListFeatureFlags(ctx context.Context, projectID int) ([]PostHogFeatureFlag, error)

ListFeatureFlags returns all feature flags for a project.

func (*PostHogClient) ListInsights added in v0.1.32

func (c *PostHogClient) ListInsights(ctx context.Context, projectID int) ([]PostHogInsight, error)

ListInsights returns all insights (saved queries) for a project.

func (*PostHogClient) ListProjects added in v0.1.32

func (c *PostHogClient) ListProjects(ctx context.Context) ([]PostHogProject, error)

ListProjects returns all projects (teams) accessible with the API key.

func (*PostHogClient) SearchCohorts added in v0.1.32

func (c *PostHogClient) SearchCohorts(ctx context.Context, projectID int, search string) ([]PostHogCohort, error)

SearchCohorts searches cohorts by name. Uses: GET /api/projects/{id}/cohorts/?search={search}&limit=200

func (*PostHogClient) SearchEvents added in v0.1.32

func (c *PostHogClient) SearchEvents(ctx context.Context, projectID int, eventName string, limit int) ([]PostHogEvent, error)

SearchEvents searches events, optionally filtered by event name. If eventName is empty, returns recent events. Uses: GET /api/projects/{id}/events/

func (*PostHogClient) SearchFeatureFlags added in v0.1.32

func (c *PostHogClient) SearchFeatureFlags(ctx context.Context, projectID int, search string) ([]PostHogFeatureFlag, error)

SearchFeatureFlags searches feature flags by name/key. Uses: GET /api/projects/{id}/feature_flags/?search={search}&limit=200

func (*PostHogClient) SearchInsights added in v0.1.32

func (c *PostHogClient) SearchInsights(ctx context.Context, projectID int, search string) ([]PostHogInsight, error)

SearchInsights searches insights by name. Uses: GET /api/projects/{id}/insights/?search={search}&limit=200

type PostHogCohort added in v0.1.32

type PostHogCohort struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Count int    `json:"count"`
}

PostHogCohort represents a PostHog cohort.

type PostHogEvent added in v0.1.32

type PostHogEvent struct {
	ID         string         `json:"id"`
	Event      string         `json:"event"`
	Timestamp  string         `json:"timestamp"`
	Properties map[string]any `json:"properties"`
}

PostHogEvent represents a PostHog event.

type PostHogFeatureFlag added in v0.1.32

type PostHogFeatureFlag struct {
	ID     int    `json:"id"`
	Key    string `json:"key"`
	Name   string `json:"name"`
	Active bool   `json:"active"`
}

PostHogFeatureFlag represents a PostHog feature flag.

type PostHogInsight added in v0.1.32

type PostHogInsight struct {
	ID          int    `json:"id"`
	ShortID     string `json:"short_id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

PostHogInsight represents a PostHog insight (saved query).

type PostHogPersonalAPIKey added in v0.1.57

type PostHogPersonalAPIKey struct {
	ID                  string   `json:"id"`
	Label               string   `json:"label"`
	Scopes              []string `json:"scopes"`
	ScopedTeams         []int    `json:"scoped_teams"`
	ScopedOrganizations []string `json:"scoped_organizations"`
}

PostHogPersonalAPIKey represents the response from GET /api/personal_api_keys/@current/.

type PostHogProject added in v0.1.32

type PostHogProject struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

PostHogProject represents a PostHog project (team).

Jump to

Keyboard shortcuts

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