From f8982a9f8650c026daa50876721161eeadcb95d3 Mon Sep 17 00:00:00 2001 From: Daniel Upton Date: Tue, 3 Dec 2024 11:23:18 +0000 Subject: [PATCH] Support `resource.pull` webhooks --- webhook.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/webhook.go b/webhook.go index 5e5a25e..7f7f099 100644 --- a/webhook.go +++ b/webhook.go @@ -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. @@ -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. @@ -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 { @@ -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) }