|
| 1 | +import json |
| 2 | + |
| 3 | +from lfx.custom.custom_component.component import Component |
| 4 | +from lfx.inputs.inputs import BoolInput, DropdownInput, IntInput, MessageTextInput, SecretStrInput |
| 5 | +from lfx.schema.data import Data |
| 6 | +from lfx.schema.dataframe import DataFrame |
| 7 | +from lfx.template.field.base import Output |
| 8 | + |
| 9 | +from ._base import pubrio_post, split_csv |
| 10 | + |
| 11 | + |
| 12 | +class PubrioUpdateMonitorComponent(Component): |
| 13 | + display_name = "Pubrio Update Monitor" |
| 14 | + description = "Update an existing signal monitor configuration." |
| 15 | + icon = "activity" |
| 16 | + name = "PubrioUpdateMonitor" |
| 17 | + |
| 18 | + inputs = [ |
| 19 | + SecretStrInput(name="api_key", display_name="Pubrio API Key", required=True), |
| 20 | + MessageTextInput(name="query", display_name="Query", info="JSON with monitor_id and fields to update.", tool_mode=True), |
| 21 | + MessageTextInput(name="monitor_id", display_name="Monitor ID", info="Monitor UUID to update."), |
| 22 | + MessageTextInput(name="name", display_name="Name", advanced=True), |
| 23 | + DropdownInput(name="detection_mode", display_name="Detection Mode", options=["company_first", "signal_first"], value="company_first", advanced=True), |
| 24 | + MessageTextInput(name="signal_types", display_name="Signal Types", advanced=True), |
| 25 | + DropdownInput(name="destination_type", display_name="Destination Type", options=["webhook", "email", "sequences"], value="webhook", advanced=True), |
| 26 | + MessageTextInput(name="webhook_url", display_name="Webhook URL", advanced=True), |
| 27 | + MessageTextInput(name="companies", display_name="Companies", advanced=True), |
| 28 | + MessageTextInput(name="domains", display_name="Domains", advanced=True), |
| 29 | + MessageTextInput(name="linkedin_urls", display_name="LinkedIn URLs", advanced=True), |
| 30 | + BoolInput(name="is_active", display_name="Is Active", advanced=True), |
| 31 | + BoolInput(name="is_paused", display_name="Is Paused", advanced=True), |
| 32 | + IntInput(name="frequency_minute", display_name="Frequency (Minutes)", advanced=True), |
| 33 | + MessageTextInput(name="notification_email", display_name="Notification Email", advanced=True), |
| 34 | + ] |
| 35 | + |
| 36 | + outputs = [ |
| 37 | + Output(display_name="Result", name="result", method="update"), |
| 38 | + ] |
| 39 | + |
| 40 | + def update(self) -> DataFrame: |
| 41 | + body: dict = {} |
| 42 | + |
| 43 | + if self.query: |
| 44 | + try: |
| 45 | + body.update(json.loads(self.query)) |
| 46 | + except (json.JSONDecodeError, TypeError): |
| 47 | + pass |
| 48 | + |
| 49 | + if self.monitor_id: |
| 50 | + body["monitor_id"] = self.monitor_id |
| 51 | + |
| 52 | + for key in ("name", "detection_mode", "destination_type", "webhook_url", "notification_email"): |
| 53 | + val = getattr(self, key, None) |
| 54 | + if val: |
| 55 | + body[key] = val |
| 56 | + |
| 57 | + if self.signal_types: |
| 58 | + body["signal_types"] = split_csv(self.signal_types) |
| 59 | + for key in ("companies", "domains", "linkedin_urls"): |
| 60 | + val = getattr(self, key, None) |
| 61 | + if val: |
| 62 | + body[key] = split_csv(val) |
| 63 | + for key in ("is_active", "is_paused"): |
| 64 | + val = getattr(self, key, None) |
| 65 | + if val is not None: |
| 66 | + body[key] = val |
| 67 | + if self.frequency_minute is not None: |
| 68 | + body["frequency_minute"] = self.frequency_minute |
| 69 | + |
| 70 | + result = pubrio_post(self.api_key, "/monitors/update", body) |
| 71 | + data = [Data(text=json.dumps(result), data=result if isinstance(result, dict) else {"result": result})] |
| 72 | + self.status = data |
| 73 | + return DataFrame(data) |
0 commit comments