nylas

package module
v0.14.1-0...-14c41cf Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 20 Imported by: 0

README

Nylas API v2 Go client

Build Status GoDoc Go Report Card License MIT

Provides access to the Nylas Platform v2 REST API.

This library does not currently cover all endpoints and will be implemented as and when they are needed by our internal projects. Check the GoDoc or Status for current implementation status.

This is not an official SDK for the Nylas Platform, for the official SDKs visit Nylas SDKs.

Installation

go get github.com/teamwork/nylas-go

Usage

package main

import (
    "context"
    "log"
    "net/http"
    "time"

    nylas "github.com/teamwork/nylas-go"
)

const (
    clientID     = "..."
    clientSecret = "..."
    accessToken  = "..."
)

func main() {
    client := nylas.NewClient(clientID, clientSecret,
        nylas.WithHTTPClient(&http.Client{
            Timeout: 3 * time.Second,
        }),
        nylas.WithAccessToken(accessToken), // not required for account management endpoints
    )

    ctx := context.Background()
    deltaResp, err := client.Deltas(ctx, cursor, &nylas.DeltasOptions{
        View:         nylas.ViewExpanded,
        IncludeTypes: []string{"thread"},
    })
    if err != nil {
        log.Fatalf("get thread deltas: %v", err)
    }

    for _, d := range deltaResp.Deltas {
        log.Printf("%+v", d)
    }
}

Examples

See the example directory.

Contributing

We would like to make this library feature complete with the offical SDK projects and contributions are welcome.

Following the existing code style and conventions and submit a PR.

Status

The following features are implemented in the client:

Authentication
Hosted Authentication
  • GET /oauth/authorize
  • POST /oauth/token
  • POST /oauth/revoke
Native Authentication
  • POST /connect/authorize
  • POST /connect/token
Apps & Accounts
Accounts
  • GET /account
Account Management
  • GET /a/{client_id}/accounts
  • GET /a/{client_id}/accounts/{id}
  • POST /a/{client_id}/accounts/{id}/downgrade
  • POST /a/{client_id}/accounts/{id}/upgrade
  • POST /a/{client_id}/accounts/{id}/revoke-all
  • GET /a/{client_id}/ip_addresses
  • POST /a/{client_id}/accounts/{id}/token-info
Application Management
  • GET /a/{client_id}
  • POST /a/{client_id}
Threads
  • GET /threads
  • GET /threads/{id}
  • PUT /threads/{id}
Messages
  • GET /messages
  • GET /messages/{id}
  • PUT /messages/{id}
  • GET /messages/{id} (raw message content)
Folders
  • GET /folders
  • GET /folders/{id}
  • POST /folders
  • PUT /folders/{id}
  • DEL /folders/{id}
Labels
  • GET /labels
  • GET /labels/{id}
  • POST /labels
  • PUT /labels/{id}
  • DEL /labels/{id}
Drafts
  • GET /drafts
  • GET /drafts/{id}
  • POST /drafts
  • PUT /drafts/{id}
  • DEL /drafts/{id}
Sending
  • POST /send#drafts
  • POST /send#directly
  • POST /send#raw
Files
  • GET /files
  • GET /files/{id}
  • GET /files/{id}/download
  • POST /files
  • DEL /files/{id}
Calendars
  • GET /calendars
  • GET /calendars/{id}
  • POST /calendars/free-busy
Events
  • GET /events
  • GET /events/{id}
  • POST /events
  • PUT /events/{id}
  • DEL /events/{id}
  • POST /send-rsvp
Room Resources
  • GET /resources
Contacts
  • GET /contacts
  • GET /contacts/{id}
  • POST /contacts
  • PUT /contacts/{id}
  • DEL /contacts/{id}
  • GET /contacts/{id}/picture
  • GET /contacts/groups
  • GET /threads/search
  • GET /messages/search
Webhooks
  • Listener client
  • GET /webhooks
  • POST /webhooks
  • GET /webhooks/{id}
  • PUT /webhooks/{id}
  • DEL /webhooks/{id}
Deltas
  • POST /delta/latest_cursor
  • GET /delta
  • GET /delta/longpoll
  • GET /delta/streaming

Documentation

Overview

Package nylas provides an API Client for working with the v2 of the Nylas API.

See https://docs.nylas.com/ for full documentation of the API which this package makes requests to.

Index

Constants

View Source
const (
	BillingStateCancelled = "cancelled"
	BillingStatePaid      = "paid"
	BillingStateDeleted   = "deleted"
)

BillingState constants, for more info see: https://docs.nylas.com/reference#aclient_idaccounts

View Source
const (
	OrganizationUnitFolder = "folder"
	OrganizationUnitLabel  = "label"
)

OrganizationUnit constants specify either "label" or "folder", depending on the provider capabilities.

View Source
const (
	ViewCount    = "count"
	ViewExpanded = "expanded"
	ViewIDs      = "ids"
)

View constants for more info, see: https://docs.nylas.com/reference#views

View Source
const (
	MailboxInbox     = "inbox"
	MailboxAll       = "all"
	MailboxTrash     = "trash"
	MailboxArchive   = "archive"
	MailboxDrafts    = "drafts"
	MailboxSent      = "sent"
	MailboxSpam      = "spam"
	MailboxImportant = "important"
)

Label/Folder mailbox name constants, for more info see: https://docs.nylas.com/reference#get-labels https://docs.nylas.com/reference#get-folders https://tools.ietf.org/html/rfc6154

Variables

View Source
var ErrAccessTokenNotSet = errors.New("access token not set on client")

ErrAccessTokenNotSet is returned when Client methods are called that require an access token to be set.

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to the given bool value.

func NewError

func NewError(resp *http.Response) error

NewError creates a new Error from an API response.

func String

func String(v string) *string

String returns a pointer to the given string value.

func WebhookHandler

func WebhookHandler(clientSecret string, fn func(WebhookDelta) error) http.Handler

WebhookHandler returns a new http.Handler for handling Nylas webhooks.

The X-Nylas-Signature will be verified and any non-nil error returned from fn will result in a 500 response with the error message.

When mounting this route it should be called for both GET and POST requests to handle the initial webhook setup.

See: https://docs.nylas.com/reference#receiving-notifications

Types

type Account

type Account struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`

	Name             string `json:"name"`
	EmailAddress     string `json:"email_address"`
	Provider         string `json:"provider"`
	OrganizationUnit string `json:"organization_unit"`
	SyncState        string `json:"sync_state"`
	LinkedAt         int    `json:"linked_at"`

	// Only populated after a call to ConnectAccount
	AccessToken  string `json:"access_token"`
	BillingState string `json:"billing_state"`
}

Account contains the details of an account which corresponds to an email address, mailbox, and optionally a calendar.

type AuthorizeRequest

type AuthorizeRequest struct {
	Name         string
	EmailAddress string
	Settings     AuthorizeSettings
	Scopes       []string
	// contains filtered or unexported fields
}

AuthorizeRequest used to start the process of connecting an account to Nylas. See: https://docs.nylas.com/reference#connectauthorize

func (AuthorizeRequest) MarshalJSON

func (r AuthorizeRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

type AuthorizeSettings

type AuthorizeSettings interface {
	// Provider returns the provider value to be used in a connect request.
	Provider() string
}

AuthorizeSettings provides settings for a native authentication connect request and should JSON marshal into the desired object. See: https://docs.nylas.com/reference#section-provider-specific-settings

type Client

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

Client for working with the Nylas API.

func NewClient

func NewClient(clientID, clientSecret string, opts ...Option) *Client

NewClient returns a new client for working with the Nylas API.

func (*Client) Account

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

Account returns the account information for the user the client is authenticated as. See: https://docs.nylas.com/reference#account

func (*Client) Accounts

func (c *Client) Accounts(ctx context.Context) ([]ManagementAccount, error)

Accounts returns the account information for all accounts. See: https://docs.nylas.com/reference#aclient_idaccounts

func (*Client) As

func (c *Client) As(accessToken string) *Client

As returns a copy of the Client with the given access token set.

func (*Client) CancelAccount

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

CancelAccount cancels a paid account. See: https://docs.nylas.com/reference#cancel-an-account

func (*Client) ConnectAccount

func (c *Client) ConnectAccount(ctx context.Context, authReq AuthorizeRequest) (Account, error)

ConnectAccount to Nylas with Native Authentication. See: https://docs.nylas.com/docs/native-authentication

func (*Client) CreateDraft

func (c *Client) CreateDraft(ctx context.Context, draftReq DraftRequest) (Draft, error)

CreateDraft creates a new draft. See: https://docs.nylas.com/reference#post-draft

func (*Client) DeleteDraft

func (c *Client) DeleteDraft(ctx context.Context, id string, version int) error

DeleteDraft deletes draft matching the id, version must be the latest version of the draft. See: https://docs.nylas.com/reference#draftsid

func (*Client) DeleteFile

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

DeleteFile removes an existing file identified by the specified file ID. See: https://docs.nylas.com/reference#files-delete

func (*Client) Deltas

func (c *Client) Deltas(
	ctx context.Context, cursor string, opts *DeltasOptions,
) (DeltaResponse, error)

Deltas requests a set of changes starting at cursor for a users mailbox.

Note: this may not return all the changes that have happened since the start of the cursor and so you should keep requesting using DeltaResponse.CursorEnd until a response is given with CursorStart equal to CursorEnd.

See: https://docs.nylas.com/reference#requesting-a-set-of-deltas

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, id string) (io.ReadCloser, error)

DownloadFile downloads a file attachment.

If the returned error is nil, you are expected to read the io.ReadCloser to EOF and close.

See: https://docs.nylas.com/reference#filesiddownload

func (*Client) Draft

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

Draft returns a draft by id. See: https://docs.nylas.com/reference#get-draft

func (*Client) Drafts

func (c *Client) Drafts(ctx context.Context, opts *DraftsOptions) ([]Draft, error)

Drafts returns drafts which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-drafts

func (*Client) DraftsCount

func (c *Client) DraftsCount(ctx context.Context, opts *DraftsOptions) (int, error)

DraftsCount returns the count of drafts which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-drafts

func (*Client) File

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

File returns a files metadata by id. See: https://docs.nylas.com/reference#get-metadata

func (*Client) Folders

func (c *Client) Folders(ctx context.Context, opts *FoldersOptions) ([]Folder, error)

Folders returns folders which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-folders

func (*Client) FoldersCount

func (c *Client) FoldersCount(ctx context.Context) (int, error)

FoldersCount returns the count of folders. See: https://docs.nylas.com/reference#get-folders

func (*Client) Labels

func (c *Client) Labels(ctx context.Context, opts *LabelsOptions) ([]Label, error)

Labels returns labels which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-labels

func (*Client) LabelsCount

func (c *Client) LabelsCount(ctx context.Context) (int, error)

LabelsCount returns the count of labels. See: https://docs.nylas.com/reference#get-labels

func (*Client) LatestDeltaCursor

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

LatestDeltaCursor returns latest delta cursor for a users mailbox. See: https://docs.nylas.com/reference#obtaining-a-delta-cursor

func (*Client) Message

func (c *Client) Message(ctx context.Context, id string, expanded bool) (Message, error)

Message returns a message by id. See: https://docs.nylas.com/reference#messagesid

func (*Client) Messages

func (c *Client) Messages(ctx context.Context, opts *MessagesOptions) ([]Message, error)

Messages returns messages which match the filter specified by parameters. See: https://docs.nylas.com/reference#messages-1

func (*Client) MessagesCount

func (c *Client) MessagesCount(ctx context.Context, opts *MessagesOptions) (int, error)

MessagesCount returns the count of messages which match the filter specified by parameters. See: https://docs.nylas.com/reference#messages-1

func (*Client) RawMessage

func (c *Client) RawMessage(ctx context.Context, id string) ([]byte, error)

RawMessage returns the raw message in RFC-2822 format. See: https://docs.nylas.com/reference#raw-message-contents

func (*Client) ReactivateAccount

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

ReactivateAccount re-enables a cancelled account to make it activate again. See: https://docs.nylas.com/reference#re-activate-an-account.

func (*Client) RevokeAccountTokens

func (c *Client) RevokeAccountTokens(ctx context.Context, id string, keepToken *string) error

RevokeAccountTokens revokes all account tokens, optionally excluding one. See: https://docs.nylas.com/reference#revoke-all

func (*Client) SendDirectly

func (c *Client) SendDirectly(ctx context.Context, draftRequest DraftRequest) (Message, error)

SendDirectly a message without creating a draft first. See: https://docs.nylas.com/reference#sending-directly

func (*Client) SendDraft

func (c *Client) SendDraft(ctx context.Context, id string, version int) (Message, error)

SendDraft sends an existing drafted with the given id and version. Version must be the most recent version of the draft or the request will fail. See: https://docs.nylas.com/reference#sending-drafts

func (*Client) StreamDeltas

func (c *Client) StreamDeltas(ctx context.Context, cursor string, fn func(Delta)) error

StreamDeltas streams deltas for a users mailbox with a long lived connection calling the provided function with each delta.

This method will block until the context is cancelled or an error occurs. Ensure you set a http.Client with appropriate timeout settings, e.g:

  &http.Client{
	Transport: &http.Transport{
		Dial: (&net.Dialer{
			Timeout: 5 * time.Second,
		}).Dial,
		ResponseHeaderTimeout: 10 * time.Second,
		TLSHandshakeTimeout:   5 * time.Second,
	},
  }

See: https://docs.nylas.com/reference#streaming-delta-updates

func (*Client) Thread

func (c *Client) Thread(ctx context.Context, id string, expanded bool) (Thread, error)

Thread returns a thread by id. See: https://docs.nylas.com/reference#threadsid

func (*Client) Threads

func (c *Client) Threads(ctx context.Context, opts *ThreadsOptions) ([]Thread, error)

Threads returns threads which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-threads

func (*Client) ThreadsCount

func (c *Client) ThreadsCount(ctx context.Context, opts *ThreadsOptions) (int, error)

ThreadsCount returns the count of threads which match the filter specified by parameters. See: https://docs.nylas.com/reference#get-threads

func (*Client) UpdateDraft

func (c *Client) UpdateDraft(
	ctx context.Context, id string, updateReq UpdateDraftRequest,
) (Draft, error)

UpdateDraft updates a draft with the id.

Updating a draft returns a draft with the same ID but different Version. When submitting subsequent send or save actions, you must use this new version. See: https://docs.nylas.com/reference#put-draft

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(
	ctx context.Context, id string, updateReq UpdateMessageRequest,
) (Message, error)

UpdateMessage updates a message with the id. See: https://docs.nylas.com/reference#messagesid-1

func (*Client) UpdateThread

func (c *Client) UpdateThread(
	ctx context.Context, id string, updateReq UpdateThreadRequest,
) (Thread, error)

UpdateThread updates a thread with the id. See: https://docs.nylas.com/reference#threadsid-1

func (*Client) UploadFile

func (c *Client) UploadFile(
	ctx context.Context, filename string, file io.Reader,
) (File, error)

UploadFile uploads a file to be used as an attachment. See: https://docs.nylas.com/reference#upload

type Delta

type Delta struct {
	ID     string `json:"id"`
	Object string `json:"object"`

	Event      string          `json:"event"`
	Cursor     string          `json:"cursor"`
	Attributes json.RawMessage `json:"attributes"`
}

Delta represents a change in the Nylas system. See: https://docs.nylas.com/reference#deltas

func (Delta) Message

func (d Delta) Message() (Message, error)

Message unmarshals the receivers Attributes field into a Message.

func (Delta) Thread

func (d Delta) Thread() (Thread, error)

Thread unmarshals the receivers Attributes field into a Thread.

type DeltaResponse

type DeltaResponse struct {
	CursorStart string  `json:"cursor_start"`
	CursorEnd   string  `json:"cursor_end"`
	Deltas      []Delta `json:"deltas"`
}

DeltaResponse contains the response of a Delta API request.

type DeltasOptions

type DeltasOptions struct {
	IncludeTypes []string `url:"include_types,comma,omitempty"`
	ExcludeTypes []string `url:"exclude_types,comma,omitempty"`
	View         string   `url:"view,omitempty"`
}

DeltasOptions provides optional parameters to the Deltas method.

type Draft

type Draft struct {
	Message
	ReplyToMessageID string `json:"reply_to_message_id"`
	Version          int    `json:"version"`
}

Draft is a special kind of message which has not been sent, and therefore it's body contents and recipients are still mutable. See: https://docs.nylas.com/reference#drafts

type DraftRequest

type DraftRequest struct {
	Subject          string        `json:"subject"`
	From             []Participant `json:"from"`
	To               []Participant `json:"to"`
	CC               []Participant `json:"cc"`
	BCC              []Participant `json:"bcc"`
	ReplyTo          []Participant `json:"reply_to"`
	ReplyToMessageID string        `json:"reply_to_message_id,omitempty"`
	Body             string        `json:"body"`
	FileIDs          []string      `json:"file_ids"`
	Tracking         *Tracking     `json:"tracking,omitempty"`
}

DraftRequest contains the request parameters required to create a draft or send it directly. See: https://docs.nylas.com/reference#drafts

type DraftsOptions

type DraftsOptions struct {
	View   string `url:"view,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`

	// Return messages belonging to a specific thread
	ThreadID string `url:"thread_id,omitempty"`

	// Return drafts that have been sent or received from the list of
	// email addresses. A maximum of 25 emails may be specified
	AnyEmail []string `url:"any_email,comma,omitempty"`
}

DraftsOptions provides optional parameters to the Drafts method.

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Body       []byte `json:"-"`

	Message     string `json:"message"`
	Type        string `json:"type"`
	ServerError string `json:"server_error"`
}

Error returned from the Nylas API. See: https://docs.nylas.com/reference#errors See: https://docs.nylas.com/reference#section-sending-errors

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

type ExchangeAuthorizeSettings

type ExchangeAuthorizeSettings struct {
	Username      string `json:"username"`
	Password      string `json:"password"`
	EASServerHost string `json:"eas_server_host"`
}

ExchangeAuthorizeSettings implements AuthorizeSettings.

func (ExchangeAuthorizeSettings) Provider

func (ExchangeAuthorizeSettings) Provider() string

Provider returns the provider value to be used in a connect request.

type File

type File struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`

	ContentType        string `json:"content_type"`
	ContentID          string `json:"content_id"`
	ContentDisposition string `json:"content_disposition"`
	Filename           string `json:"filename"`
	Size               int    `json:"size"`
}

File represents a file in the Nylas system.

type Folder

type Folder struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`

	// Localized name of the folder
	DisplayName string `json:"display_name"`

	// Standard categories type, based on RFC-6154, can be one of the
	// Mailbox* constants, e.g MailboxInbox or empty if user created.
	// See: https://tools.ietf.org/html/rfc6154
	Name string `json:"name"`
}

Folder represents a folder in the Nylas system.

type FoldersOptions

type FoldersOptions struct {
	Limit  int `url:"limit,omitempty"`
	Offset int `url:"offset,omitempty"`
}

FoldersOptions provides optional parameters to the Folders method.

type GmailAuthorizeSettings

type GmailAuthorizeSettings struct {
	GoogleClientID     string `json:"google_client_id"`
	GoogleClientSecret string `json:"google_client_secret"`
	GoogleRefreshToken string `json:"google_refresh_token"`
}

GmailAuthorizeSettings implements AuthorizeSettings.

func (GmailAuthorizeSettings) Provider

func (GmailAuthorizeSettings) Provider() string

Provider returns the provider value to be used in a connect request.

type IMAPAuthorizeSettings

type IMAPAuthorizeSettings struct {
	IMAPHost     string `json:"imap_host"`
	IMAPPort     int    `json:"imap_port"`
	IMAPUsername string `json:"imap_username"`
	IMAPPassword string `json:"imap_password"`
	SMTPHost     string `json:"smtp_host"`
	SMTPPort     int    `json:"smtp_port"`
	SMTPUsername string `json:"smtp_username"`
	SMTPPassword string `json:"smtp_password"`
	SSLRequired  bool   `json:"ssl_required"`
}

IMAPAuthorizeSettings implements AuthorizeSettings.

func (IMAPAuthorizeSettings) Provider

func (IMAPAuthorizeSettings) Provider() string

Provider returns the provider value to be used in a connect request.

type Label

type Label struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`

	// Localized name of the label
	DisplayName string `json:"display_name"`

	// Standard categories type, based on RFC-6154, can be one of the
	// Mailbox* constants, e.g MailboxInbox or empty if user created.
	// See: https://tools.ietf.org/html/rfc6154
	Name string `json:"name"`
}

Label represents a label in the Nylas system.

type LabelsOptions

type LabelsOptions struct {
	Limit  int `url:"limit,omitempty"`
	Offset int `url:"offset,omitempty"`
}

LabelsOptions provides optional parameters to the Labels method.

type ManagementAccount

type ManagementAccount struct {
	ID        string `json:"id"`
	AccountID string `json:"account_id"`

	BillingState string `json:"billing_state"`
	Email        string `json:"email"`
	Provider     string `json:"provider"`
	SyncState    string `json:"sync_state"`
	Trial        bool   `json:"trial"`
}

ManagementAccount contains the details of an account and is used when working with the Account Management endpoints. See: https://docs.nylas.com/reference#account-management

type Message

type Message struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`
	ThreadID  string `json:"thread_id"`

	From    []Participant `json:"from"`
	To      []Participant `json:"to"`
	CC      []Participant `json:"cc"`
	BCC     []Participant `json:"bcc"`
	ReplyTo []Participant `json:"reply_to"`

	// Only available in expanded view, see:
	// https://docs.nylas.com/reference#views
	Headers struct {
		InReplyTo  string   `json:"In-Reply-To"`
		MessageID  string   `json:"Message-Id"`
		References []string `json:"References"`
	} `json:"headers"`

	Subject string `json:"subject"`
	Date    int64  `json:"date"`
	Body    string `json:"body"`
	Snippet string `json:"snippet"`

	Events []interface{} `json:"events"`
	Files  []File        `json:"files"`
	Folder Folder        `json:"folder"`
	Labels []Label       `json:"labels"`

	Starred bool `json:"starred"`
	Unread  bool `json:"unread"`
}

Message contains all the details of a single email message. See: https://docs.nylas.com/reference#messages

type MessagesOptions

type MessagesOptions struct {
	View   string `url:"view,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
	// Return messages with a matching literal subject
	Subject string `url:"subject,omitempty"`
	// Return messages that have been sent or received from the list of
	// email addresses. A maximum of 25 emails may be specified
	AnyEmail []string `url:"any_email,comma,omitempty"`
	// Return  messages sent to this email address
	To string `url:"to,omitempty"`
	// Return  messages sent from this email address
	From string `url:"from,omitempty"`
	// Return  messages that were CC'd to this email address
	CC string `url:"cc,omitempty"`
	// Return messages that were BCC'd to this email address, likely sent
	// from the parent account.
	// (Most SMTP gateways remove BCC information.)
	BCC string `url:"bcc,omitempty"`
	// Return messages in a given folder, or with a given label.
	// This parameter supports the name, display_name, or id of a folder or
	// label.
	In      string `url:"in,omitempty"`
	Unread  *bool  `url:"unread,omitempty"`
	Starred *bool  `url:"starred,omitempty"`
	// Return messages belonging to a specific thread
	ThreadID string `url:"thread_id,omitempty"`
	Filename string `url:"filename,omitempty"`
	// Return messages received before this Unix-based timestamp.
	ReceivedBefore int64 `url:"received_before,omitempty"`
	// Return messages received after this Unix-based timestamp.
	ReceivedAfter int64 `url:"received_after,omitempty"`
	HasAttachment *bool `url:"has_attachment,omitempty"`
}

MessagesOptions provides optional parameters to the Messages method.

type Office365AuthorizeSettings

type Office365AuthorizeSettings struct {
	MicrosoftClientSecret string `json:"microsoft_client_secret"`
	MicrosoftRefreshToken string `json:"microsoft_refresh_token"`
	RedirectURI           string `json:"redirect_uri"`
}

Office365AuthorizeSettings implements AuthorizeSettings.

func (Office365AuthorizeSettings) Provider

Provider returns the provider value to be used in a connect request.

type Option

type Option func(*Client)

Option sets an optional setting on the Client.

func WithAccessToken

func WithAccessToken(token string) Option

WithAccessToken returns an option to set the access token to be used. This token is used for user mailbox specific methods.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL returns an Option to set the base URL to be used.

func WithErrorHandler

func WithErrorHandler(f func(e error) error) Option

WithErrorHandler returns an Option to set the error handler to be used.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient returns an Option to set the http.Client to be used.

type OutlookAuthorizeSettings

type OutlookAuthorizeSettings struct {
	Username      string `json:"username"`
	Password      string `json:"password"`
	EASServerHost string `json:"eas_server_host"`
}

OutlookAuthorizeSettings implements AuthorizeSettings.

func (OutlookAuthorizeSettings) Provider

func (OutlookAuthorizeSettings) Provider() string

Provider returns the provider value to be used in a connect request.

type Participant

type Participant struct {
	Email string `json:"email"`
	Name  string `json:"name"`
}

Participant in a Message/Thread.

type Thread

type Thread struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	AccountID string `json:"account_id"`

	Folders        []Folder `json:"folders"`
	HasAttachments bool     `json:"has_attachments"`

	FirstMessageTimestamp        int64 `json:"first_message_timestamp"`
	LastMessageReceivedTimestamp int64 `json:"last_message_received_timestamp"`
	LastMessageSentTimestamp     int64 `json:"last_message_sent_timestamp"`
	LastMessageTimestamp         int64 `json:"last_message_timestamp"`

	MessageIDs []string `json:"message_ids"`
	DraftIDs   []string `json:"draft_ids"`

	// Only available in expanded view and the body will be missing, see:
	// https://docs.nylas.com/reference#views
	Messages []Message `json:"messages"`
	Drafts   []Message `json:"drafts"`

	Participants []Participant `json:"participants"`
	Labels       []Label       `json:"labels"`
	Snippet      string        `json:"snippet"`
	Starred      bool          `json:"starred"`
	Subject      string        `json:"subject"`
	Unread       bool          `json:"unread"`
	Version      int           `json:"version"`
}

Thread combines multiple messages from the same conversation into a single first-class object that is similar to what users expect from email clients. See: https://docs.nylas.com/reference#threads

type ThreadsOptions

type ThreadsOptions struct {
	View   string `url:"view,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
	// Return threads with a matching literal subject
	Subject string `url:"subject,omitempty"`
	// Return threads that have been sent or received from the list of email
	// addresses. A maximum of 25 emails may be specified
	AnyEmail []string `url:"any_email,comma,omitempty"`
	// Return threads containing messages sent to this email address
	To string `url:"to,omitempty"`
	// Return threads containing messages sent from this email address
	From string `url:"from,omitempty"`
	// Return threads containing messages that were CC'd to this email address
	CC string `url:"cc,omitempty"`
	// Return threads containing messages that were BCC'd to this email
	// address, likely sent from the parent account. (Most SMTP gateways
	// remove BCC information.)
	BCC string `url:"bcc,omitempty"`
	// Return threads in a given folder, or with a given label.
	// This parameter supports the name, display_name, or id of a folder or
	// label.
	In string `url:"in,omitempty"`
	// Return threads with one or more unread messages
	Unread   *bool  `url:"unread,omitempty"`
	Filename string `url:"filename,omitempty"`
	// Return threads whose most recent message was received before this
	// Unix-based timestamp.
	LastMessageBefore int64 `url:"last_message_before,omitempty"`
	// Return threads whose most recent message was received after this
	// Unix-based timestamp.
	LastMessageAfter int64 `url:"last_message_after,omitempty"`
	// Return threads whose first message was received before this
	// Unix-based timestamp.
	StartedBefore int64 `url:"started_before,omitempty"`
	// Return threads whose first message was received after this
	// Unix-based timestamp.
	StartedAfter int64 `url:"started_after,omitempty"`
}

ThreadsOptions provides optional parameters to the Threads method.

type Tracking

type Tracking struct {
	Links         bool   `json:"links,omitempty"`
	Opens         bool   `json:"opens,omitempty"`
	ThreadReplies bool   `json:"thread_replies,omitempty"`
	Payload       string `json:"payload,omitempty"`
}

Tracking contains the requst parameters required to track an email See: https://docs.nylas.com/docs/message-tracking

type UpdateDraftRequest

type UpdateDraftRequest struct {
	Subject          *string        `json:"subject,omitempty"`
	From             *[]Participant `json:"from,omitempty"`
	To               *[]Participant `json:"to,omitempty"`
	CC               *[]Participant `json:"cc,omitempty"`
	BCC              *[]Participant `json:"bcc,omitempty"`
	ReplyTo          *[]Participant `json:"reply_to,omitempty"`
	ReplyToMessageID *string        `json:"reply_to_message_id,omitempty"`
	Body             *string        `json:"body,omitempty"`
	FileIDs          *[]string      `json:"file_ids,omitempty"`

	Version int `json:"version"`
}

UpdateDraftRequest contains the request parameters required to update a draft.

Version is required to specify the version of the draft you wish to update, other fields are optional and will overwrite previous values if given.

type UpdateMessageRequest

type UpdateMessageRequest struct {
	Unread  *bool `json:"unread,omitempty"`
	Starred *bool `json:"starred,omitempty"`
	// FolderID to move this message to.
	FolderID *string `json:"folder_id,omitempty"`
	// LabelIDs to overwrite any previous labels with, you must provide
	// existing labels such as sent/drafts.
	LabelIDs *[]string `json:"label_ids,omitempty"`
}

UpdateMessageRequest contains the request parameters required to update a message.

type UpdateThreadRequest

type UpdateThreadRequest struct {
	Unread  *bool `json:"unread,omitempty"`
	Starred *bool `json:"starred,omitempty"`
	// FolderID to move this thread to.
	FolderID *string `json:"folder_id,omitempty"`
	// LabelIDs to overwrite any previous labels with, you must provide
	// existing labels such as sent/drafts.
	LabelIDs *[]string `json:"label_ids,omitempty"`
}

UpdateThreadRequest contains the request parameters required to update a thread.

type WebhookDelta

type WebhookDelta struct {
	Date       int    `json:"date"`
	Object     string `json:"object"`
	Type       string `json:"type"`
	ObjectData struct {
		ID          string `json:"id"`
		Object      string `json:"object"`
		AccountID   string `json:"account_id"`
		NamespaceID string `json:"namespace_id"`

		Attributes struct {
			ThreadID     string `json:"thread_id"`
			ReceivedDate int    `json:"received_date"`
		} `json:"attributes"`

		// used for tracking, see:
		// https://docs.nylas.com/reference#understanding-tracking-notifications
		Metadata map[string]interface{} `json:"metadata"`
	} `json:"object_data"`
}

WebhookDelta represents a change in a users mailbox from a webhook request.

type WebhookListener

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

WebhookListener receives requests from a Nylas webhook. See: https://docs.nylas.com/reference#webhooks

func NewWebhookListener

func NewWebhookListener(clientSecret string) *WebhookListener

NewWebhookListener returns a new WebhookListener..

func (*WebhookListener) Listen

func (l *WebhookListener) Listen(addr string, fn func(WebhookDelta) error) error

Listen for webhooks on the given address. The callback will be called for each webhook and a non-nil error will respond with a 500 including the error message.

Note: the callback is handled synchronously, so if you need to do slow work in response to a webhook return nil and handle it in another routine.

See: https://docs.nylas.com/reference#receiving-notifications

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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