Skip to content

Commit 8a466ee

Browse files
devin-ai-integration[bot]tgberkeleyTom Gotsman
authored
Add Slack webhook integration to demo form (#1484)
* Add Slack webhook integration to demo form - Add SLACK_DEMO_WEBHOOK_URL constant - Create send_data_to_slack function in postog_metrics.py - Update send_demo_event to call both PostHog and Slack webhooks - Maintain existing PostHog functionality while adding Slack integration Co-Authored-By: [email protected] <[email protected]> * Address PR review comments - Fix field mapping: use company_name for businessName instead of company_email - Improve error logging with detailed error messages - Add error handling around Slack webhook call to prevent blocking form submission - Use environment variable for webhook URL with fallback to hardcoded value - Add missing log import in header.py Co-Authored-By: [email protected] <[email protected]> * updates for making it work with a env var * Add optional phone number field to demo form - Add phone_number field to DemoEvent dataclass with default empty string - Add phone number input field to form UI using text_input_field helper - Update form submission handler to include phone number in DemoEvent - Update Slack webhook payload to include phoneNumber field - Phone number field is optional with tel input type and proper placeholder - Maintains consistent styling with existing form fields Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Tom Gotsman <[email protected]>
1 parent 620e37e commit 8a466ee

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

pcweb/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@
100100

101101
# Posthog
102102
POSTHOG_API_KEY = os.getenv("POSTHOG_API_KEY")
103+
104+
SLACK_DEMO_WEBHOOK_URL: str = os.environ.get("SLACK_DEMO_WEBHOOK_URL")

pcweb/pages/pricing/header.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import reflex as rx
55
from reflex.event import EventType
66
from reflex.experimental import ClientStateVar
7+
from reflex.utils.console import log
78

89
from pcweb.components.hosting_banner import HostingBannerState
910
from pcweb.components.new_button import button
1011
from pcweb.pages.framework.views.companies import pricing_page_companies
11-
from pcweb.telemetry.postog_metrics import DemoEvent, send_data_to_posthog
12+
from pcweb.telemetry.postog_metrics import DemoEvent, send_data_to_posthog, send_data_to_slack
1213

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

@@ -193,20 +194,28 @@ def submit(self, form_data: dict[str, Any]):
193194
async def send_demo_event(self, form_data: dict[str, Any]):
194195
first_name = form_data.get("first_name", "")
195196
last_name = form_data.get("last_name", "")
196-
await send_data_to_posthog(
197-
DemoEvent(
198-
distinct_id=f"{first_name} {last_name}",
199-
first_name=first_name,
200-
last_name=last_name,
201-
company_email=form_data.get("email", ""),
202-
linkedin_url=form_data.get("linkedin_url", ""), # Updated from phone_number
203-
job_title=form_data.get("job_title", ""),
204-
company_name=form_data.get("company_name", ""),
205-
num_employees=self.num_employees,
206-
internal_tools=form_data.get("internal_tools", ""),
207-
referral_source=self.referral_source,
208-
)
197+
demo_event = DemoEvent(
198+
distinct_id=f"{first_name} {last_name}",
199+
first_name=first_name,
200+
last_name=last_name,
201+
company_email=form_data.get("email", ""),
202+
linkedin_url=form_data.get("linkedin_url", ""),
203+
job_title=form_data.get("job_title", ""),
204+
company_name=form_data.get("company_name", ""),
205+
num_employees=self.num_employees,
206+
internal_tools=form_data.get("internal_tools", ""),
207+
referral_source=self.referral_source,
208+
phone_number=form_data.get("phone_number", ""),
209209
)
210+
211+
# Send to PostHog (existing)
212+
await send_data_to_posthog(demo_event)
213+
214+
# Send to Slack (new)
215+
try:
216+
await send_data_to_slack(demo_event)
217+
except Exception as e:
218+
log(f"Failed to send to Slack: {e}")
210219

211220

212221
def quote_input(placeholder: str, name: str, **props):
@@ -459,6 +468,13 @@ def custom_quote_form() -> rx.Component:
459468
input_type="url",
460469
),
461470
),
471+
text_input_field(
472+
"Phone number (optional)",
473+
"phone_number",
474+
"+1 (555) 123-4567",
475+
required=False,
476+
input_type="tel",
477+
),
462478
# Project Details
463479
textarea_field(
464480
"What are you looking to build?",

pcweb/telemetry/postog_metrics.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55
from posthog import Posthog
66
from reflex.utils.console import log
7-
from pcweb.constants import POSTHOG_API_KEY
7+
from pcweb.constants import POSTHOG_API_KEY, SLACK_DEMO_WEBHOOK_URL
88

99
try:
1010
posthog = Posthog(POSTHOG_API_KEY, host="https://us.i.posthog.com")
@@ -35,6 +35,7 @@ class DemoEvent(PosthogEvent):
3535
num_employees: str
3636
internal_tools: str
3737
referral_source: str
38+
phone_number: str = ""
3839

3940

4041
async def send_data_to_posthog(event_instance: PosthogEvent):
@@ -59,3 +60,34 @@ async def send_data_to_posthog(event_instance: PosthogEvent):
5960
response.raise_for_status()
6061
except Exception:
6162
log("Error sending data to PostHog")
63+
64+
65+
async def send_data_to_slack(event_instance: DemoEvent):
66+
"""Send demo form data to Slack webhook.
67+
68+
Args:
69+
event_instance: An instance of DemoEvent with form data.
70+
"""
71+
slack_payload = {
72+
"lookingToBuild": event_instance.internal_tools,
73+
"businessEmail": event_instance.company_email,
74+
"howDidYouHear": event_instance.referral_source,
75+
"linkedinUrl": event_instance.linkedin_url,
76+
"jobTitle": event_instance.job_title,
77+
"numEmployees": event_instance.num_employees,
78+
"companyName": event_instance.company_name,
79+
"firstName": event_instance.first_name,
80+
"lastName": event_instance.last_name,
81+
"phoneNumber": event_instance.phone_number
82+
}
83+
84+
try:
85+
async with httpx.AsyncClient() as client:
86+
response = await client.post(
87+
SLACK_DEMO_WEBHOOK_URL,
88+
json=slack_payload,
89+
headers={"Content-Type": "application/json"}
90+
)
91+
response.raise_for_status()
92+
except Exception as e:
93+
log(f"Error sending data to Slack webhook: {e}")

0 commit comments

Comments
 (0)