How to send survey responses to Slack
Jun 26, 2024
It's useful to send survey responses from your users to Slack. This way you're notified as soon as they respond to a survey. There are two options for setting this up: PostHog webhooks or our new realtime destinations.
The requirement for both is that you created a survey. Our docs cover how to do this, so we won't go into detail here. We also have framework-specific tutorials.
Option 1: Using PostHog webhooks
Step 1: Create an app in Slack
To use PostHog webhooks, the first step is configure an app in Slack that will send messages with the survey responses.
Go to the Slack developer dashboard, click Create New App, and then click From scratch. Name your app "PostHog", connect it to the workspace of your choice, and click Create App.
Optional: Feel free to use an image from here as the app's logo.
Step 2: Create a webhook in Slack
Go to the Incoming Webhooks page for your newly-created app and toggle Activate Incoming Webhooks to turn it on. Then click Add New Webhook to Workspace and select the channel that the you want to send survey responses to.
Once created, copy the URL for your new webhook.
Step 3: Connect your webhook to PostHog
Go to Integration section in your PostHog project settings and paste the URL from the previous step in the Webhook integration field.
Click Test & Save and you should receive a message in Slack from your app.
Note: In your project settings, you'll also see a "Slack integration" section. You can ignore this as it is not required for setting up the Slack webhook. It's only required for setting up subscriptions to receive regular reports for any insight or dashboard.
Step 4: Create an action for your survey responses
In PostHog, navigate to actions in the Data management tab. Click the New action button in the top right and then From event or pageview.
Then under Match Group #1, click on the Other events tab and set the Event name to survey sent
.
Lastly, check the box for Post to webhook when this action is triggered and set the Slack message format to New response for [event.properties.$survey_name] from [person]: "[event.properties.$survey_response]"
.
Altogether it should look like this:
And we're done! Now whenever a user responds to your surveys, you'll receive a message in Slack
Option 2: Using realtime destinations
Our new realtime destinations are currently in preview. These provide customizable destinations, more formatting options, a revamped configuration UI. We can use them to send survey responses to Slack or any other destination that supports webhooks.
To do this, start by enabling the Pipeline destinations 3000 feature preview.
Next, go to the data pipeline destinations tab and search for the Slack destination and click + Create. On the creation screen:
Follow the steps to integrate with your Slack workspace if you haven't already and then select it.
Make sure the PostHog integration is added to the channel you want to send messages to and select it.
Under Match event and actions, select survey sent.
Under Blocks, modify the text to include the survey name and response. For example:
{"text": {"text": "*{person.name}* sent a response to {event.properties.$survey_name}: {event.properties.$survey_response}","type": "mrkdwn"},"type": "section"},
- Customize the name and description, and press Create & enable.
You can then test the destination and it will start sending survey responses to Slack.
Further reading
- How to set up surveys in Next.js
- How to show a survey after a delay
- How to analyze surveys with ChatGPT