-
Notifications
You must be signed in to change notification settings - Fork 231
Add Slack webhook integration to demo form #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
134c8ee
adee532
302f8fd
1837ab0
6f8048e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||
|
||||||||||||||||||
| # 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}") |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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") | ||||||||||
|
|
@@ -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, | ||||||||||
|
||||||||||
| "lookingToBuild": event_instance.internal_tools, | |
| "businessName": event_instance.company_email, | |
| "lookingToBuild": event_instance.internal_tools, | |
| "businessName": event_instance.company_name, |
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)