Skip to content

Commit

Permalink
Add action.execute event to the go-client (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlathia authored Sep 17, 2024
2 parents f7759e9 + 4939e7b commit 76413e3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const (
// conversation with the customer and you should close any corresponding
// ticket, etc.
WebhookTypeConversationFinished WebhookType = "conversation.finished"

// WebhookTypeAction indicates that the agent needs an action to
// be executed (e.g., while following a procedure)
WebhookTypeActionExecute WebhookType = "action.execute"
)

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

func (w Webhook) ActionExecute() (*ActionExecuteEvent, bool) {
e, ok := w.Data.(*ActionExecuteEvent)
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 @@ -119,6 +128,18 @@ type ConversationFinishedEvent struct {
Conversation WebhookConversation `json:"conversation"`
}

// ActionExecuteEvent contains the data for a `action.execute` event.
type ActionExecuteEvent struct {
// Action is the name of the action to execute
Action string `json:"action"`

// Params are the arguments to execute the action with.
Params json.RawMessage `json:"params"`

// 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 @@ -167,6 +188,11 @@ func (c *Client) ParseWebhook(req *http.Request) (*Webhook, error) {
return nil, err
}
payload.Webhook.Data = &fin
case WebhookTypeActionExecute:
var act ActionExecuteEvent
if err := json.Unmarshal(payload.Data, &act); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unknown webhook event type received: %q", payload.Type)
}
Expand Down

0 comments on commit 76413e3

Please sign in to comment.