As you probably know, serverless computing is on the rise. It is not the solution to all our problems, but there are many use-cases, and some are a great fit to Lambdas (serverless functions on Amazon infrastructure). Asynchronous integrations between services are a perfect example.
We wanted to get more quality leads to grow our business and use Typeform for customer segmentation and qualification. This data, we aspired to process in our CRM software Infusionsoft to nurture leads and take them through the sales funnel.
Typeform delivers the results of forms through webhooks, which we can direct to our Lambda for processing. The call itself is lightweight and does not require a lot of resources (parsing data), and with Lambda functions you pay only per execution time (no need to pay for running containers, but also a lot of free processing time).
Setting up Serverless
We decided to use the popular Serverless Framework to deploy code to Amazon Web Services (AWS) as a cloud provider. The framework makes deployments a lot easier and has a lot of features including cross-cloud deployments, local emulators, and more.
To get started with Serverless we would need to install it globally:
npm i serverless -g
Then we need to create a file called
serverless.yml which will define structure of our cloud functions:
We define the name of the service, plugins that we would need, the cloud provider and the functions declaration.
As our integration is fairly easy and does not use any other components than the function itself, we do not need any plugins.
serverless-offline is only used for local testing and the emulator.
In order to install the plugin you need to do two things:
Install the node.js module (Because of the plugin is used for the development we will install it as dev dependency)
Add plugin to the plugins section of the serverless.yml file
npm install serverless-offline –save-dev
As we are on AWS, we use “aws” in the provider definition as well as node8.10 (yay, finally!) as runtime.
profile is the credential used to deploy the function (see serverless docs on credentials and profiles).
We are integrating a webhook from Typeform (see Typeform docs on webhooks), so we call our handler
typeform-webhook, setting the path accordingly and the function to be called. Then we specify on which events this function needs to be called — in our case we would like to call it when a POST request is performed to path
Deploying the function
Deployment of Serverless functions could not be easier. All that we need are the credentials to our cloud provider (see Creating AWS Access Keys), then we simply execute:
Once the function is deployed, you can see the URL to call the function in the serverless output. Copy that URL into the Typeform webhook configuration (Integrate → Webhooks on your form).
Typeform Webhook Configuration
We can easily test if the function is reachable and if it works as we expect it to, just by pressing “Test Webhook” button.
If all goes well, Typeform performs a test call and successfully submits test data. We can open our AWS console to see the result of the call.
The webhook payload is divided into two major parts:
definition contains the questions and response types;
answers includes the obvious: the data a visitor put into the form.
Although obvious, Typeform makes it a little tricky to extract the answers from the array. We took the easiest path using the indexes and ids of the definitions to retrieve the data we need for our Infusionsoft API call.
Once all the data is parsed, we can use any http/https client library such as r2 or axios to call the Infusionsoft API and create a new contact. We only need to retrieve an API token and set it as
Summary & Conclusion
Serverless technology makes it really easy and cheap to integrate different software products through their APIs or webhooks. It is possible to act or react to certain events. These integrations can go far beyond “If This Then That” or Zapier, as we can use any node.js library (machine learning, natural language processing, to name a few) and combine those with the simplicity of filling out a Typeform.