Skip to content

Commit

Permalink
Support resource.pull webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
boxofrad committed Dec 3, 2024
1 parent 867959d commit f8982a9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const (
// WebhookTypeAction indicates that the agent needs an action to
// be executed (e.g., while following a procedure)
WebhookTypeActionExecute WebhookType = "action.execute"

// WebhookTypeResourcePull indicates that the agent wants to pull a resource.
WebhookTypeResourcePull WebhookType = "resource.pull"
)

// Webhook is an event delivered to your webhook endpoint.
Expand Down Expand Up @@ -92,11 +95,18 @@ func (w Webhook) ConversationFinished() (*ConversationFinishedEvent, bool) {
return e, ok
}

// ActionExecute returns the data for an `action.execute` event.
func (w Webhook) ActionExecute() (*ActionExecuteEvent, bool) {
e, ok := w.Data.(*ActionExecuteEvent)
return e, ok
}

// ResourcePull returns the data for an `resource.pull` event.
func (w Webhook) ResourcePull() (*ResourcePullEvent, bool) {
e, ok := w.Data.(*ResourcePullEvent)
return e, ok
}

// AgentMessageEvent contains the data for an `agent.message` webhook event.
type AgentMessageEvent struct {
// Conversation contains the details of the conversation the event relates to.
Expand Down Expand Up @@ -152,6 +162,15 @@ type ActionExecuteEvent struct {
Conversation WebhookConversation `json:"conversation"`
}

// ResourcePullEvent contains the data for a `resource.pull` event.
type ResourcePullEvent struct {
// ResourceType is the name of the resource type the agent wants to pull.
ResourceType string `json:"resource_type"`

// Conversation contains the details of the conversation the event relates to.
Conversation WebhookConversation `json:"conversation"`
}

// WebhookConversation contains the details of the conversation the webhook
// relates to.
type WebhookConversation struct {
Expand Down Expand Up @@ -206,6 +225,12 @@ func (c *Client) ParseWebhook(req *http.Request) (*Webhook, error) {
return nil, err
}
payload.Webhook.Data = &act
case WebhookTypeResourcePull:
var pull ResourcePullEvent
if err := json.Unmarshal(payload.Data, &pull); err != nil {
return nil, err
}
payload.Webhook.Data = &pull
default:
return nil, fmt.Errorf("unknown webhook event type received: %q", payload.Type)
}
Expand Down

0 comments on commit f8982a9

Please sign in to comment.