How to trigger a Control Room process from a Typeform submission
Typeform is a popular tool for creating and managing online forms. In this article, we will see how you can trigger a process in Control Room when a user submits a Typeform using Webhooks.
You will need:
- a Typeform account (this will work with a free account as well)
- a Robocorp account to access Control Room
- VS Code with Robocorp extensions installed
Get access to Typeform and create a form
Register or log in to your Typeform account and create a test form using the UI.
As an example, we have created a very simple form with three fields:
- an email field
- a text field
- a numeric field (opinion scale)
Create a new process in Control Room and enable API access
- Access Control Room, select your organization and workspace and create a new process under the
Processes
tab. For this example, we decided to set up a new workspace calledtypeform
. In it we have created a process calledtypeform example process
- Enable the API access for your workspace, check the
trigger_processes
permission, and create the key.
Generate a callback URL for triggering your process in Control Room
Click API Helper
from the top navigation. Select the following settings from the API Helper:
What Do You Want To Do?
->Start process with with a single work item payload
Choose Process
-> Select your process.Choose API Key
-> Choose the API key you created in the previous steps.
At the bottom of the API Helper, you see a generated curl
command. The command is generated based on your choices in the API Helper. It includes the Control Room callback URL and your API token (RC-WSKEY
).
Copy the URL part after POST
, without the quotes ("
). It looks something like this:
https://api.eu1.robocorp.com/process-v1/workspaces/abc123/processes/abc123/runs?
Replace the runs?
part like this:
https://api.eu1.robocorp.com/process-v1/workspaces/abc123/processes/abc123/runs-qs-authorization?token=your-token-here
Copy the token (after RC-WSKEY
) from the generated curl
command as the value of the token
parameter.
The most secure way to call Control Room APIs is to include the authorization information in the request headers. Since you can not do that in Typeform, there's a less secure way to include the token in the URL. That is what we use in this case.
Add the webhook to your form in Typeform
- In the Typeform admin UI, select the
Connect
button in the top bar. - Select the
Webhooks
button. - Add a new webhook and add the URL that you got in the previous step:
- Activate the webhook using the toggle button:
Create a new robot in VS Code
- Create a new robot and paste the following code in the
tasks.robot
file:
Robot code explained
- The
RPA.Robocorp.WorkItems
library allows us to access the data coming from Typeform via the webhook. ${payload}= Get Work Item Payload
: TheGet Work Item Payload
keyword gets the payload data coming from Typeform.Log ${payload}
: For now, we will just print out the content of what we get from Typeform to the log.
Upload the robot to Control Room
Add the robot step to the process in Control Room
In Control Room, select your process and add to it the robot you just uploaded:
Submit the Typeform and see the results in Control Room
Submit your form in Typeform. This will cause the webhook to fire, and Control Room will run your process!
When the process is complete, you can see the submitted values in the log:
You can also inspect the data that was passed to the process using the Control Room UI:
Next steps
Now you know how to set up Typeform and Control Room to run a robot when a form is submitted. Pretty neat!
You will probably want to do something with the data that you get from Typeform, so here are some pointers:
- Check the Typeform documentation about webhooks, and the Example webhooks payload in particular to get to know the schema of data that is sent over to Control Room.
- Set up the
RPA.Robocorp.WorkItems
library to work locally, so you can iterate on your robot code to extract the data and do whatever you need with it without having to trigger an actual form each time.