trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

Airtable webhook support

Open matt-aitken opened this issue 2 years ago • 0 comments

Todo

  • [ ] Remove key column from TriggerEvent
  • [ ] Add lastDelivery and version columns to ExternalSource
  • [ ] Use a cursor for getting Airtable payloads
  • [ ] Verify the Airtable webhook using the raw body
  • [ ] Amalgamate changes into a structure that's good for users
  • [ ] Create convenient functions so user's can convert between fieldIds and names in their workflows

Desired payload format

const payload = {
  recordId: "dsfgh",
  type: "update",
  fields: {
    Author: {
      fieldId: "dfg6y464hg43",
      previous: "123",
      current: "456",
    },
  },
};

Workflow usage

const orgChart = airtable.tableSchema({
  dfg6y464hg43: {
    name: "Last contacted",
    type: airtable.CollaboratorSchema
  },
});

new Trigger({
  id: "airtable-webhook-9",
  name: "Airtable table change",
  apiKey: "trigger_dev_zC25mKNn6c0q",
  on: airtable.events.tableEvent({
    baseId: "appX9X9X9X9X9X9X9",
    tableId: "tblX9X9X9X9X9X9X9",
    tableSchema: orgChart,
  }),
  run: async (event, ctx) => {
    
    const lastContactedField = orgChart.f("Last contacted");
    const lastContactedValue = event.fields[lastContactedField]).current;

    return {};
  },
}).listen();

matt-aitken avatar Jan 23 '23 18:01 matt-aitken