Slackform is a Sinatra web application to receive Webhook requests from a Typeform form and invite new members to a Slack team with the data provided in the form answer (first name, last name and email).
For each Webhook request it receives, it sends an invitation to the user to join the configured Slack team.
The Typeform form needs to be configured to add a Webhook pointing to the URL where this app is hosted.
- Ruby 2.7.2
- Git (needed to clone the repo in order to install the gem)
Follow these steps to install:
- Clone this repository:
git clone https://github.com/MarsBased/slackform
- Install gems:
bundle install
- Configure environment variables. Use
.env.sample
to see the variables that need to be configured.
Just run ruby app.rb
. It will start listening on port 4567. If you want to test this with a real Typeform form you can use Ngrok to create a tunnel to your locally running server.
Slackform is configured by using environment variables. In development, it includes dotenv
to make it easier to configure, just create a .env
file with all the variables. These are the variables you need to configure:
- SLACK_API_KEY: You can find it in the Slack API page while you are logged in your Slack team. Go to the Slack Web API page and in the "Authentication" section you will be able to see or create the token for the team. Note that in this page you will see the API tokens for all the Slack teams where you are registered. Just copy the token of the team where you want to invite the new members.
- SLACK_TEAM: This is the name of the Slack team where you want to invite new members. This is just your Slack subdomain. For example, if you access Slack through
https://coolteam.slack.com
, then the Slack team iscoolteam
- EMAIL_FIELD_ID, FIRST_NAME_FIELD_ID and LAST_NAME_FIELD_ID: A Slack invitation consists of 3 parameters: an email (required), a first name (optional) and a last name (optional). This variables are used to specify the Typeform fields that are used to extract each of the parameters. For each invitation parameter you need to specify the Typeform field id that will be used. See how to check a typeform field id for details.
- STRIPE_SECRET: In order to automatically send receipt emails aftter the purchase, a key to Stripe is needed. Retrieve yours from the Stripe Dashboard. We recommend using restricted keys, whose permissions can be cherry-picked to not allow full access to all Stripe data. In this case, this library only needs read and write access to charges.
- TYPEFORM_SECRET: (Optional) The secret configured in the Typeform Webhook.
Follow these steps:
-
Check the HTML of the field. In Chrome and other browsers you can just "Inspect Element" on the field.
-
Find the parent
<li>
element for the field and check itsid
attribute, it should be something like:field-12345678
-
Finally remove the "field-" part and that's your id. For example, for "field-12345678" it would be "12345678".
NOTE: This is assuming you are using textfields in your form, if you use other type of fields (like text areas), then replace the "textfield" part by "textarea" or whatever type of field.
For each invitation, a notification to Slack is also sent. Each time it tries to invite someone (because there is a new answer in the Typeform) it will either send a "success" message or an "error" message to the Slack channel.
You can configure it to send a message to any Slack channel of any team (not necessarily the same team you are integrating Typeform with).
To configure notifications, add the following variable:
- SLACK_NOTIFICATIONS_WEBHOOK: a Slack "Incoming Webhook", which is like a regular URL, and tells Slack where to post the messages.
Follow these steps to configure a new Webhook:
- Open the Slack administration panel for the team where you want notifications to be posted. For example:
https://coolteam.slack.com/admin
- In the side menu go to "Integrations"
- Click "View" on "Incoming WebHooks"
Now you need to configure the integration:
- Select the channel where you want notifications to be posted
- Click on "Add Incoming WebHooks integration"
- Copy the "Webhook URL". This is the URL you need to use in the YAML configuration.
- In "Integration Settings", configure the details of the integration as you wish, the different settings are self-explanatory.
Bug reports and pull requests are welcome on GitHub at https://github.com/MarsBased/slackform.
Just ZIP everything and upload as a ZIP, remember to include all gems in the bundle and install any new gems with bundle install --path vendor/bundle
.