Skip to content

Add Slack webhook integration to demo form#1484

Merged
tgberkeley merged 5 commits intomainfrom
devin/1752180903-add-slack-webhook-integration
Jul 10, 2025
Merged

Add Slack webhook integration to demo form#1484
tgberkeley merged 5 commits intomainfrom
devin/1752180903-add-slack-webhook-integration

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jul 10, 2025

Add Slack webhook integration and optional phone number field to demo form

Summary

This PR adds Slack webhook integration to the existing demo form, allowing form submissions to be sent to both PostHog (existing) and a specified Slack channel simultaneously. Additionally, an optional phone number field has been added to the form.

Key Changes:

  • Added send_data_to_slack() function to send form data to Slack webhook
  • Modified send_demo_event() to call both PostHog and Slack webhooks in parallel
  • Added optional phone number field to the form UI with consistent styling
  • Updated DemoEvent dataclass to include phone number field
  • Added environment variable support for Slack webhook URL with fallback
  • Improved error handling and logging for webhook failures

Review & Testing Checklist for Human

⚠️ High Priority (5 items - comprehensive testing needed)

  • End-to-end form submission test: Fill out and submit the demo form on /pricing page to verify both PostHog and Slack receive the data correctly with all fields including phone number
  • Slack webhook payload verification: Check that the Slack channel receives the expected payload format with all fields (firstName, lastName, businessName, etc.) matching the original screenshot requirements
  • Phone number field testing: Test the optional phone number field with various formats (international, US format, empty, invalid characters) to ensure it handles edge cases gracefully
  • Environment variable configuration: Verify that SLACK_DEMO_WEBHOOK_URL environment variable is properly configured in production to avoid exposing the hardcoded fallback URL
  • Error handling verification: Test what happens when Slack webhook fails (e.g., temporarily break the webhook URL) to ensure form submission still completes successfully and errors are logged appropriately

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    subgraph "Form Submission Flow"
        A["pcweb/pages/pricing/header.py<br/>QuoteFormState.submit()"]:::major-edit
        B["pcweb/pages/pricing/header.py<br/>send_demo_event()"]:::major-edit
        C["pcweb/telemetry/postog_metrics.py<br/>send_data_to_posthog()"]:::context
        D["pcweb/telemetry/postog_metrics.py<br/>send_data_to_slack()"]:::major-edit
        E["pcweb/telemetry/postog_metrics.py<br/>DemoEvent dataclass"]:::major-edit
        F["pcweb/constants.py<br/>SLACK_DEMO_WEBHOOK_URL"]:::minor-edit
    end
    
    subgraph "External Services"
        G["PostHog API"]:::context
        H["Slack Webhook"]:::context
    end
    
    A --> B
    B --> C
    B --> D
    E --> C
    E --> D
    F --> D
    C --> G
    D --> H
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Session Details: Requested by tom@reflex.dev | Devin Session
  • Testing Screenshots: Local testing screenshots available at /home/ubuntu/screenshots/localhost_3000_215328.png and /home/ubuntu/screenshots/localhost_3000_215406.png showing successful form submission with phone number field
  • Code Review: Addressed automated code review comments including field mapping fix, improved error logging, and environment variable usage
  • Backward Compatibility: All existing form functionality remains unchanged; phone number field is optional and doesn't affect existing validation logic

- 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: tom@reflex.dev <tom@reflex.dev>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added Slack webhook integration for demo form submissions, with potential security and data mapping concerns that need addressing.

  • Hardcoded Slack webhook URL in pcweb/constants.py should be moved to environment variables for security
  • Incorrect data mapping in pcweb/telemetry/postog_metrics.py where company_email is mapped to businessName field
  • Basic error handling in send_data_to_slack() needs more detailed logging
  • New reusable DemoEvent object pattern in pcweb/pages/pricing/header.py improves code maintainability

3 files reviewed, 4 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +71 to +72
"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,

Comment on lines +90 to +91
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.

Comment on lines +212 to +213
# 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}")

# 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")

devin-ai-integration bot and others added 4 commits July 10, 2025 21:07
- 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: tom@reflex.dev <tom@reflex.dev>
- 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: tom@reflex.dev <tom@reflex.dev>
@tgberkeley tgberkeley merged commit 8a466ee into main Jul 10, 2025
9 checks passed
@tgberkeley tgberkeley deleted the devin/1752180903-add-slack-webhook-integration branch July 10, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant