diff --git a/conversation.go b/conversation.go new file mode 100644 index 0000000..e66bd61 --- /dev/null +++ b/conversation.go @@ -0,0 +1,18 @@ +package hubspot + +const ( + visitorIdentificationBasePath = "/conversations/v3/visitor-identification" +) + +type Conversation struct { + VisitorIdentification VisitorIdentificationService +} + +func newConversation(c *Client) *Conversation { + return &Conversation{ + VisitorIdentification: &VisitorIdentificationServiceOp{ + client: c, + basePath: visitorIdentificationBasePath, + }, + } +} diff --git a/conversation_visitor_identity.go b/conversation_visitor_identity.go new file mode 100644 index 0000000..f8866d0 --- /dev/null +++ b/conversation_visitor_identity.go @@ -0,0 +1,31 @@ +package hubspot + +type IdentificationTokenResponse struct { + Token string `json:"token"` +} + +type IdentificationTokenRequest struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + Email string `json:"email"` +} + +type VisitorIdentificationService interface { + GenerateIdentificationToken(option IdentificationTokenRequest) (*IdentificationTokenResponse, error) +} + +type VisitorIdentificationServiceOp struct { + client *Client + basePath string +} + +var _ VisitorIdentificationService = (*VisitorIdentificationServiceOp)(nil) + +func (s *VisitorIdentificationServiceOp) GenerateIdentificationToken(option IdentificationTokenRequest) (*IdentificationTokenResponse, error) { + response := &IdentificationTokenResponse{} + path := s.basePath + "/tokens/create" + if err := s.client.Post(path, option, response); err != nil { + return nil, err + } + return response, nil +} diff --git a/export_test.go b/export_test.go index aca5eee..83d8f2a 100644 --- a/export_test.go +++ b/export_test.go @@ -14,8 +14,9 @@ var ( ) var ( - ExportNewCRM = newCRM - ExportNewMarketing = newMarketing + ExportNewCRM = newCRM + ExportNewMarketing = newMarketing + ExportNewConversation = newConversation ExportSetupProperties = (*RequestQueryOption).setupProperties diff --git a/gohubspot.go b/gohubspot.go index c0d30a7..e026bc6 100644 --- a/gohubspot.go +++ b/gohubspot.go @@ -34,8 +34,9 @@ type Client struct { authenticator Authenticator - CRM *CRM - Marketing *Marketing + CRM *CRM + Marketing *Marketing + Conversation *Conversation } // RequestPayload is common request structure for HubSpot APIs. @@ -79,6 +80,7 @@ func NewClient(setAuthMethod AuthMethod, opts ...Option) (*Client, error) { // Since the baseURL and apiVersion may change, initialize the service after applying the options. c.CRM = newCRM(c) c.Marketing = newMarketing(c) + c.Conversation = newConversation(c) return c, nil } diff --git a/gohubspot_test.go b/gohubspot_test.go index 5d104b4..87e6553 100644 --- a/gohubspot_test.go +++ b/gohubspot_test.go @@ -152,6 +152,7 @@ func TestNewClient(t *testing.T) { want.ExportSetBaseURL(tt.settings.baseURL) want.CRM = hubspot.ExportNewCRM(want) want.Marketing = hubspot.ExportNewMarketing(want) + want.Conversation = hubspot.ExportNewConversation(want) tt.settings.authMethod(want) }