From ad6fb749f09ffca4c507f10c03ab595ac6b28f3e Mon Sep 17 00:00:00 2001 From: Robi9 Date: Thu, 19 Oct 2023 18:20:58 -0300 Subject: [PATCH] Add handle for weniGPTCalled type events --- core/handlers/wenigpt_called.go | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 core/handlers/wenigpt_called.go diff --git a/core/handlers/wenigpt_called.go b/core/handlers/wenigpt_called.go new file mode 100644 index 000000000..77835a216 --- /dev/null +++ b/core/handlers/wenigpt_called.go @@ -0,0 +1,41 @@ +package handlers + +import ( + "context" + + "github.com/jmoiron/sqlx" + "github.com/nyaruka/goflow/flows" + "github.com/nyaruka/goflow/flows/events" + "github.com/nyaruka/mailroom/core/hooks" + "github.com/nyaruka/mailroom/core/models" + "github.com/nyaruka/mailroom/runtime" + "github.com/sirupsen/logrus" +) + +func init() { + models.RegisterEventHandler(events.TypeWeniGPTCalled, handleWeniGPTCalled) +} + +type WeniGPTCall struct { + NodeUUID flows.NodeUUID + Event *events.WeniGPTCalledEvent +} + +func handleWeniGPTCalled(ctx context.Context, rt *runtime.Runtime, tx *sqlx.Tx, oa *models.OrgAssets, scene *models.Scene, e flows.Event) error { + event := e.(*events.WeniGPTCalledEvent) + logrus.WithFields(logrus.Fields{ + "contact_uuid": scene.ContactUUID(), + "session_id": scene.SessionID(), + "url": event.URL, + "status": event.Status, + "elapsed_ms": event.ElapsedMS, + "extraction": event.Extraction, + }).Debug("wenigpt called") + + _, step := scene.Session().FindStep(e.StepUUID()) + + // pass node and response time to the hook that monitors webhook health + scene.AppendToEventPreCommitHook(hooks.MonitorWebhooks, WeniGPTCall{NodeUUID: step.NodeUUID(), Event: event}) + + return nil +}