1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { Airtable } from "@trigger.dev/airtable";
3
import { Typeform } from "@trigger.dev/typeform";
5
const typeform = new Typeform({
7
token: process.env.TYPEFORM_TOKEN!,
10
const airtable = new Airtable({
12
token: process.env.AIRTABLE_TOKEN!,
20
emailContactEnabled: boolean;
25
id: "typeform-new-submission-update-airtable",
26
name: "On new Typeform submission update Airtable",
32
trigger: typeform.onFormResponse({
35
uid: "<your-form-id>",
38
run: async (payload, io, ctx) => {
40
const table = io.airtable
41
.base("<your-base-id>")
42
.table<Submission>("<your-table-name>");
44
if (payload.form_response.answers[0].type !== "text") {
45
throw new Error("The first answer is not a name");
47
const name = payload.form_response.answers[0].text;
49
if (payload.form_response.answers[1].type !== "email") {
50
throw new Error("The second answer is not an email");
52
const email = payload.form_response.answers[1].email;
54
if (payload.form_response.answers[2].type !== "choice") {
55
throw new Error("The third answer is not a choice");
57
const emailContactEnabled =
58
payload.form_response.answers[2].choice.label === "Yes";
61
const newRecords = await table.createRecords("create records", [
72
await io.logger.info("A new form submission was created.", {