Documentation
¶
Index ¶
- Constants
- Variables
- func CleanNotionID(id string) string
- func DetectCategory(labels []string) string
- func ExtractMessageBody(msg map[string]any) string
- func ExtractPlainTextBody(msg map[string]any) string
- func ExtractSenderName(from string) string
- func FormatSubjectFolder(subject, dateStr, msgID string) string
- func GetDriveAPICallCount() int64
- func GetGmailAPICallCount() int64
- func GetNotionAPICallCount() int64
- func JSONMarshal(v any) ([]byte, error)
- func JSONMarshalIndent(v any) ([]byte, error)
- func ParseEmailDate(dateStr string) time.Time
- func ResetDriveAPICallCount()
- func ResetGmailAPICallCount()
- func ResetNotionAPICallCount()
- func SanitizeFilename(name string) string
- func SanitizeFolderName(name string) string
- func StripHTML(html string) string
- type DriveClient
- func (c *DriveClient) DownloadFile(ctx context.Context, token, fileID string) ([]byte, error)
- func (c *DriveClient) ExportGoogleDoc(ctx context.Context, token, fileID, mimeType string) ([]byte, error)
- func (c *DriveClient) GetExportMimeType(mimeType string) string
- func (c *DriveClient) GetFile(ctx context.Context, token, fileID string) (*DriveFile, error)
- func (c *DriveClient) GetFileContent(ctx context.Context, token string, file *DriveFile) ([]byte, error)
- func (c *DriveClient) Integration() types.IntegrationName
- func (c *DriveClient) IsGoogleDoc(mimeType string) bool
- func (c *DriveClient) IsTextExtractable(mimeType string) bool
- func (c *DriveClient) ListFiles(ctx context.Context, token, query string, maxResults int) ([]*DriveFile, error)
- func (c *DriveClient) ParseFile(fileMap map[string]any) *DriveFile
- func (c *DriveClient) Request(ctx context.Context, token, path string, result any) error
- type DriveFile
- type GmailClient
- func (c *GmailClient) DetectCategory(labels []string) string
- func (c *GmailClient) ExtractMessageBody(msg map[string]any) string
- func (c *GmailClient) ExtractPlainTextBody(msg map[string]any) string
- func (c *GmailClient) GetMessage(ctx context.Context, token, msgID, format string) (map[string]any, error)
- func (c *GmailClient) Integration() types.IntegrationName
- func (c *GmailClient) ListMessages(ctx context.Context, token, query string, maxResults int) ([]string, error)
- func (c *GmailClient) ParseMessage(result map[string]any) *GmailMessage
- func (c *GmailClient) Request(ctx context.Context, token, path string, result any) error
- type GmailMessage
- type NotionBlock
- type NotionClient
- func (c *NotionClient) BlockToMarkdown(block *NotionBlock) string
- func (c *NotionClient) BlocksToText(blocks []*NotionBlock) string
- func (c *NotionClient) ExtractRichText(blockContent map[string]any) string
- func (c *NotionClient) ExtractTitle(obj map[string]any) string
- func (c *NotionClient) GetPage(ctx context.Context, token, pageID string) (*NotionPage, error)
- func (c *NotionClient) GetPageBlocks(ctx context.Context, token, pageID string) ([]*NotionBlock, error)
- func (c *NotionClient) Integration() types.IntegrationName
- func (c *NotionClient) ParsePage(obj map[string]any) *NotionPage
- func (c *NotionClient) PostRequest(ctx context.Context, token, path string, body any, result any) error
- func (c *NotionClient) Request(ctx context.Context, token, path string, result any) error
- func (c *NotionClient) Search(ctx context.Context, token string, query string, maxResults int) ([]*NotionPage, error)
- type NotionPage
- type PostHogClient
- func (c *PostHogClient) GetCohort(ctx context.Context, projectID, cohortID int) (*PostHogCohort, error)
- func (c *PostHogClient) GetCurrentKey(ctx context.Context) (*PostHogPersonalAPIKey, error)
- func (c *PostHogClient) GetEvent(ctx context.Context, projectID int, eventID string) (*PostHogEvent, error)
- func (c *PostHogClient) GetFeatureFlag(ctx context.Context, projectID, flagID int) (*PostHogFeatureFlag, error)
- func (c *PostHogClient) GetInsightByShortID(ctx context.Context, projectID int, shortID string) (*PostHogInsight, error)
- func (c *PostHogClient) GetProject(ctx context.Context, projectID int) (*PostHogProject, error)
- func (c *PostHogClient) ListCohorts(ctx context.Context, projectID int) ([]PostHogCohort, error)
- func (c *PostHogClient) ListEvents(ctx context.Context, projectID, limit int) ([]PostHogEvent, error)
- func (c *PostHogClient) ListFeatureFlags(ctx context.Context, projectID int) ([]PostHogFeatureFlag, error)
- func (c *PostHogClient) ListInsights(ctx context.Context, projectID int) ([]PostHogInsight, error)
- func (c *PostHogClient) ListProjects(ctx context.Context) ([]PostHogProject, error)
- func (c *PostHogClient) SearchCohorts(ctx context.Context, projectID int, search string) ([]PostHogCohort, error)
- func (c *PostHogClient) SearchEvents(ctx context.Context, projectID int, eventName string, limit int) ([]PostHogEvent, error)
- func (c *PostHogClient) SearchFeatureFlags(ctx context.Context, projectID int, search string) ([]PostHogFeatureFlag, error)
- func (c *PostHogClient) SearchInsights(ctx context.Context, projectID int, search string) ([]PostHogInsight, error)
- type PostHogCohort
- type PostHogEvent
- type PostHogFeatureFlag
- type PostHogInsight
- type PostHogPersonalAPIKey
- type PostHogProject
Constants ¶
const ( NotionAPIBase = "https://api.notion.com/v1" NotionAPIVersion = "2022-06-28" )
const (
DriveAPIBase = "https://www.googleapis.com/drive/v3"
)
const (
GmailAPIBase = "https://gmail.googleapis.com/gmail/v1"
)
Variables ¶
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
var ErrResourceNotFound = fmt.Errorf("resource not found")
ErrResourceNotFound is returned when a PostHog resource doesn't exist (HTTP 404).
var GmailCategories = []string{"unread", "inbox", "starred", "sent", "important"}
GmailCategories are the supported message categories
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
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
var UnsafeFilenameChars = regexp.MustCompile(`[<>:"/\\|?*\x00-\x1f]`)
UnsafeFilenameChars matches characters unsafe for filenames
Functions ¶
func DetectCategory ¶
DetectCategory determines the primary category for a message based on labels
func ExtractMessageBody ¶
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 ¶
ExtractPlainTextBody extracts plain text from a Gmail message payload
func ExtractSenderName ¶
ExtractSenderName extracts a clean sender name from a From header "noreply@calendly.com" -> "Calendly" "KAYAK <kayak@msg.kayak.com>" -> "KAYAK"
func FormatSubjectFolder ¶
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 JSONMarshalIndent ¶
JSONMarshalIndent marshals to indented JSON
func ParseEmailDate ¶
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 ¶
SanitizeFilename makes a filename safe for filesystem use
func SanitizeFolderName ¶
SanitizeFolderName makes a folder name safe with shorter limit
Types ¶
type DriveClient ¶
DriveClient provides shared Google Drive API functionality
func NewDriveClient ¶
func NewDriveClient() *DriveClient
NewDriveClient creates a new Google Drive API client
func (*DriveClient) DownloadFile ¶
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) 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
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 ¶
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
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 ¶
NotionBlock represents a Notion block
type NotionClient ¶
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) 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
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
PostHogProject represents a PostHog project (team).