Skip to content

Commit

Permalink
Merge pull request #49 from wakflo/feature/web-710-calendly-connector
Browse files Browse the repository at this point in the history
Feature/web 710 calendly connector
  • Loading branch information
raff-wakflo authored Oct 3, 2024
2 parents 852cfb6 + e03416a commit 8cf9911
Show file tree
Hide file tree
Showing 7 changed files with 605 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/wakflo/extensions/internal/connectors/airtable"
"github.com/wakflo/extensions/internal/connectors/asana"
"github.com/wakflo/extensions/internal/connectors/calculator"
"github.com/wakflo/extensions/internal/connectors/calendly"
"github.com/wakflo/extensions/internal/connectors/cin7"
"github.com/wakflo/extensions/internal/connectors/clickup"
"github.com/wakflo/extensions/internal/connectors/cryptography"
Expand Down Expand Up @@ -89,6 +90,7 @@ func RegisterConnectors() []*sdk.ConnectorPlugin {
jsonconverter.NewConnector, // Json
trackingmore.NewConnector, // TrackingMore
freshworkscrm.NewConnector, // Freshworks CRM
calendly.NewConnector, // Calendly
shippo.NewConnector, // Shippo
easyship.NewConnector, // EasyShip
dropbox.NewConnector, // Dropbox
Expand Down
36 changes: 36 additions & 0 deletions internal/connectors/calendly/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package calendly

// Copyright 2022-present Wakflo
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import (
sdk "github.com/wakflo/go-sdk/connector"
)

func NewConnector() (*sdk.ConnectorPlugin, error) {
return sdk.CreateConnector(&sdk.CreateConnectorArgs{
Name: "Calendly",
Description: "All-in-one productivity platform",
Logo: "simple-icons:calendly",
Version: "0.0.1",
Category: sdk.Apps,
Authors: []string{"Wakflo <integrations@wakflo.com>"},
Triggers: []sdk.ITrigger{},
Operations: []sdk.IOperation{
NewListEventsOperation(),
NewGetEventOperation(),
NewCreateSingleUseScheduleLinkOperation(),
},
})
}
46 changes: 46 additions & 0 deletions internal/connectors/calendly/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package calendly

import "time"

type User struct {
URI string `json:"uri"`
Name string `json:"name"`
Slug string `json:"slug"`
Email string `json:"email"`
SchedulingURL string `json:"scheduling_url"`
Timezone string `json:"timezone"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CurrentOrganization string `json:"current_organization"`
AvatarURL string `json:"avatar_url"`
}
type UsersResponse struct {
Users []User `json:"collection"`
}

type CurrentUserResponse struct {
Resource User `json:"resource"`
}

type EventsResponse struct {
Events []Event `json:"collection"`
}

type Event struct {
URI string `json:"uri"`
Name string `json:"name"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
}

type EventTypesResponse struct {
Collection []EventType `json:"collection"`
}

type EventType struct {
URI string `json:"uri"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
Duration int `json:"duration"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package calendly

import (
"errors"
"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type createSingleUseScheduleLinkOperationProps struct {
User string `json:"user"`
MaxEventCount int `json:"max_event_count"`
Owner string `json:"owner"`
}

type CreateSingleUseScheduleLinkOperation struct {
options *sdk.OperationInfo
}

func NewCreateSingleUseScheduleLinkOperation() *CreateSingleUseScheduleLinkOperation {
return &CreateSingleUseScheduleLinkOperation{
options: &sdk.OperationInfo{
Name: "Create Single Use Schedule Link",
Description: "Create a single use schedule link",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"user": getCurrentCalendlyUserInput("User", "Select a user", true),
"max_event_count": autoform.NewNumberField().
SetDisplayName("Max Event Count").
SetDescription("Maximum number of events that can be scheduled using the schedule link").
SetRequired(true).
Build(),
"owner": getCalendlyEventTypeInput("Event Type", "Select an event type", false),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *CreateSingleUseScheduleLinkOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
if ctx.Auth.AccessToken == "" {
return nil, errors.New("missing calendly auth token")
}
accessToken := ctx.Auth.AccessToken

input := sdk.InputToType[createSingleUseScheduleLinkOperationProps](ctx)

if input.User == "" {
return nil, errors.New("user is required")
}

if input.MaxEventCount <= 0 {
return nil, errors.New("max event count is required")
}

if input.Owner == "" {
return nil, errors.New("owner is required")
}

scheduleLink, _ := createSingleUseLink(accessToken, input.Owner, input.MaxEventCount)

return scheduleLink, nil

}

func (c *CreateSingleUseScheduleLinkOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *CreateSingleUseScheduleLinkOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
67 changes: 67 additions & 0 deletions internal/connectors/calendly/operation_get_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package calendly

import (
"errors"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type getEventOperatioinProps struct {
User string `json:"user"`
EventID string `json:"event-id"`
}

type GetEventOperation struct {
options *sdk.OperationInfo
}

func NewGetEventOperation() *GetEventOperation {
return &GetEventOperation{
options: &sdk.OperationInfo{
Name: "Get Event",
Description: "Get Event",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"user": getCurrentCalendlyUserInput("User", "Select a user", true),
"event-id": getCalendlyEventInput("Event", "Select event", true),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *GetEventOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
if ctx.Auth.AccessToken == "" {
return nil, errors.New("missing calendly auth token")
}
accessToken := ctx.Auth.AccessToken

input := sdk.InputToType[getEventOperatioinProps](ctx)

println("event-ud", input.EventID)
println("accessToken", accessToken)

if input.User == "" {
return nil, errors.New("user is required")
}

if input.EventID == "" {
return nil, errors.New("event id is required")
}

event, _ := getEvent(accessToken, input.EventID)

return event, nil
}

func (c *GetEventOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *GetEventOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
72 changes: 72 additions & 0 deletions internal/connectors/calendly/operation_list_events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package calendly

import (
"errors"

"github.com/wakflo/go-sdk/autoform"
sdk "github.com/wakflo/go-sdk/connector"
sdkcore "github.com/wakflo/go-sdk/core"
)

type listEventOperationProps struct {
User string `json:"user"`
Status string `json:"status"`
}

type ListEventsOperation struct {
options *sdk.OperationInfo
}

func NewListEventsOperation() *ListEventsOperation {
return &ListEventsOperation{
options: &sdk.OperationInfo{
Name: "List Events",
Description: "List Events",
RequireAuth: true,
Auth: sharedAuth,
Input: map[string]*sdkcore.AutoFormSchema{
"user": getCurrentCalendlyUserInput("User", "Select a user", true),
"status": autoform.NewSelectField().
SetDisplayName("Status").
SetDescription("Event Status").
SetOptions(calendlyEventStatusType).
SetRequired(true).
Build(),
},
ErrorSettings: sdkcore.StepErrorSettings{
ContinueOnError: false,
RetryOnError: false,
},
},
}
}

func (c *ListEventsOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) {
if ctx.Auth.AccessToken == "" {
return nil, errors.New("missing calendly auth token")
}
accessToken := ctx.Auth.AccessToken

input := sdk.InputToType[listEventOperationProps](ctx)

if input.Status == "" {
return nil, errors.New("status is required")
}

if input.User == "" {
return nil, errors.New("user is required")
}

reqURL := baseURL + "/scheduled_events"
events, _ := listEvents(accessToken, reqURL, input.Status, input.User)

return events, nil
}

func (c *ListEventsOperation) Test(ctx *sdk.RunContext) (sdk.JSON, error) {
return c.Run(ctx)
}

func (c *ListEventsOperation) GetInfo() *sdk.OperationInfo {
return c.options
}
Loading

0 comments on commit 8cf9911

Please sign in to comment.