Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pcweb/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@

# Posthog
POSTHOG_API_KEY = os.getenv("POSTHOG_API_KEY")

SLACK_DEMO_WEBHOOK_URL: str = "https://hooks.slack.com/triggers/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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Move webhook URL to environment variable like other sensitive URLs in this file (e.g. line 102's POSTHOG_API_KEY)

Suggested change
SLACK_DEMO_WEBHOOK_URL: str = "https://hooks.slack.com/triggers/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"
SLACK_DEMO_WEBHOOK_URL: str = os.environ.get("SLACK_DEMO_WEBHOOK_URL")

32 changes: 18 additions & 14 deletions pcweb/pages/pricing/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pcweb.components.hosting_banner import HostingBannerState
from pcweb.components.new_button import button
from pcweb.pages.framework.views.companies import pricing_page_companies
from pcweb.telemetry.postog_metrics import DemoEvent, send_data_to_posthog
from pcweb.telemetry.postog_metrics import DemoEvent, send_data_to_posthog, send_data_to_slack

ThankYouDialogState = ClientStateVar.create("thank_you_dialog_state", False)

Expand Down Expand Up @@ -193,20 +193,24 @@ def submit(self, form_data: dict[str, Any]):
async def send_demo_event(self, form_data: dict[str, Any]):
first_name = form_data.get("first_name", "")
last_name = form_data.get("last_name", "")
await send_data_to_posthog(
DemoEvent(
distinct_id=f"{first_name} {last_name}",
first_name=first_name,
last_name=last_name,
company_email=form_data.get("email", ""),
linkedin_url=form_data.get("linkedin_url", ""), # Updated from phone_number
job_title=form_data.get("job_title", ""),
company_name=form_data.get("company_name", ""),
num_employees=self.num_employees,
internal_tools=form_data.get("internal_tools", ""),
referral_source=self.referral_source,
)
demo_event = DemoEvent(
distinct_id=f"{first_name} {last_name}",
first_name=first_name,
last_name=last_name,
company_email=form_data.get("email", ""),
linkedin_url=form_data.get("linkedin_url", ""),
job_title=form_data.get("job_title", ""),
company_name=form_data.get("company_name", ""),
num_employees=self.num_employees,
internal_tools=form_data.get("internal_tools", ""),
referral_source=self.referral_source,
)

# Send to PostHog (existing)
await send_data_to_posthog(demo_event)

# Send to Slack (new)
await send_data_to_slack(demo_event)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider adding error handling around the Slack call since webhook failures shouldn't block the form submission

Suggested change
# Send to Slack (new)
await send_data_to_slack(demo_event)
# Send to Slack (new)
try:
await send_data_to_slack(demo_event)
except Exception as e:
# Log error but don't block form submission
print(f"Failed to send to Slack: {e}")



def quote_input(placeholder: str, name: str, **props):
Expand Down
32 changes: 31 additions & 1 deletion pcweb/telemetry/postog_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import httpx
from posthog import Posthog
from reflex.utils.console import log
from pcweb.constants import POSTHOG_API_KEY
from pcweb.constants import POSTHOG_API_KEY, SLACK_DEMO_WEBHOOK_URL

try:
posthog = Posthog(POSTHOG_API_KEY, host="https://us.i.posthog.com")
Expand Down Expand Up @@ -59,3 +59,33 @@ async def send_data_to_posthog(event_instance: PosthogEvent):
response.raise_for_status()
except Exception:
log("Error sending data to PostHog")


async def send_data_to_slack(event_instance: DemoEvent):
"""Send demo form data to Slack webhook.

Args:
event_instance: An instance of DemoEvent with form data.
"""
slack_payload = {
"lookingToBuild": event_instance.internal_tools,
"businessName": event_instance.company_email,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Field mapping appears incorrect - company_email is being mapped to businessName. This may cause confusion in Slack notifications.

Suggested change
"lookingToBuild": event_instance.internal_tools,
"businessName": event_instance.company_email,
"lookingToBuild": event_instance.internal_tools,
"businessName": event_instance.company_name,

"howDidYouHear": event_instance.referral_source,
"linkedinUrl": event_instance.linkedin_url,
"jobTitle": event_instance.job_title,
"numEmployees": event_instance.num_employees,
"companyName": event_instance.company_name,
"firstName": event_instance.first_name,
"lastName": event_instance.last_name
}

try:
async with httpx.AsyncClient() as client:
response = await client.post(
SLACK_DEMO_WEBHOOK_URL,
json=slack_payload,
headers={"Content-Type": "application/json"}
)
response.raise_for_status()
except Exception:
log("Error sending data to Slack webhook")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider logging the actual error details to help with debugging webhook failures.