{
  "schema_version": "1.0.0",
  "id": "new-lead-text-in-a-minute",
  "title": "Text a new lead within a minute",
  "category": "speed-to-lead",
  "difficulty": "intermediate",
  "featured": true,
  "description": "A website form posts to a webhook; the lead gets a one-segment SMS and a confirmation email within a minute, with a callback promise that fits open or closed hours.",
  "tags": [
    "speed-to-lead",
    "twilio",
    "sms",
    "webhooks",
    "gmail"
  ],
  "apps": [
    "Webhooks by Zapier",
    "Code by Zapier",
    "Formatter by Zapier",
    "Twilio",
    "Gmail"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 6 steps after the trigger",
      "Formatter by Zapier",
      "premium app: Webhooks by Zapier"
    ]
  },
  "tasks": {
    "typical": 5,
    "max": 5
  },
  "trigger": {
    "app": "Webhooks by Zapier",
    "event": "Catch Hook",
    "kind": "instant",
    "title": "Website form posts a lead",
    "why": "Your website form posts each submission to this Catch Hook URL. Most form builders (Webflow, WordPress form plugins, Framer) have a \"send to webhook\" option.",
    "config": {
      "Pick off a Child Key": "(leave blank)"
    },
    "outputs": [
      "submitted_at",
      "full_name",
      "email",
      "phone",
      "service",
      "message",
      "page_url"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "phone",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Format the phone number",
      "why": "Turns \"(415) 555-0123\" into +14155550123 so Twilio accepts it, and marks numbers that are too short to text.",
      "code": {
        "language": "javascript",
        "module": "normalize-phone",
        "file": "code/normalize-phone.js"
      },
      "input_data": {
        "phone": "{{trigger.phone}}",
        "default_country": "1"
      },
      "outputs": [
        "e164",
        "valid",
        "extension"
      ]
    },
    {
      "key": "hours",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Check whether the office is open",
      "why": "Uses an explicit UTC offset because Code by Zapier runs in UTC. The SMS wording depends on the answer.",
      "code": {
        "language": "javascript",
        "module": "business-hours",
        "file": "code/business-hours.js"
      },
      "input_data": {
        "timestamp": "{{trigger.submitted_at}}",
        "utc_offset": "-05:00",
        "open_time": "08:30",
        "close_time": "18:00",
        "open_days": "Mon-Fri"
      },
      "outputs": [
        "is_open",
        "local_day",
        "local_time",
        "next_open",
        "minutes_until_open"
      ]
    },
    {
      "key": "promise",
      "kind": "formatter",
      "app": "Formatter by Zapier",
      "event": "Utilities",
      "title": "Pick the callback promise",
      "why": "A two-row lookup table turns is_open into one sentence, so the text and the email never promise a call nobody can make.",
      "fields": {
        "Transform": "Lookup Table",
        "Lookup Key": "{{hours.is_open}}",
        "Lookup Table": {
          "true": "We will call you within 15 minutes.",
          "false": "We are closed right now and will call you first thing when we open."
        },
        "Fallback Value": "We will call you as soon as we can."
      },
      "outputs": [
        "output"
      ]
    },
    {
      "key": "sms",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Write a one-segment text",
      "why": "Fills the template, swaps curly quotes for plain ones, and trims to 160 GSM characters so the text costs one segment.",
      "code": {
        "language": "javascript",
        "module": "fit-sms",
        "file": "code/fit-sms.js"
      },
      "input_data": {
        "template": "Hi {first_name}, this is {business}. Thanks for your request about {{trigger.service}}. {{promise.output}} Reply STOP to opt out.",
        "first_name": "{{trigger.full_name}}",
        "business": "YOUR_BUSINESS_NAME",
        "link": ""
      },
      "outputs": [
        "message",
        "encoding",
        "length",
        "segments",
        "trimmed"
      ]
    },
    {
      "key": "text",
      "kind": "action",
      "app": "Twilio",
      "event": "Send SMS",
      "title": "Text the lead",
      "why": "Sends the fitted message from your Twilio number. Twilio rejects an invalid number, and Zapier shows that as an error on this step.",
      "fields": {
        "From Number": "YOUR_TWILIO_NUMBER",
        "To Number": "{{phone.e164}}",
        "Message": "{{sms.message}}",
        "Send Large Messages?": "No"
      },
      "outputs": [
        "sid",
        "status"
      ]
    },
    {
      "key": "email",
      "kind": "action",
      "app": "Gmail",
      "event": "Send Email",
      "title": "Confirm by email",
      "why": "Gives the lead the same promise in writing, with what they asked for, so the reply is easy to find later.",
      "fields": {
        "To": "{{trigger.email}}",
        "Subject": "We got your request about {{trigger.service}}",
        "Body Type": "plain",
        "Body": "Hi {{trigger.full_name}},\n\nThanks for reaching out about {{trigger.service}}. We just sent you a text from our business line. {{promise.output}}\n\nWhat you wrote:\n{{trigger.message}}\n\nYOUR_BUSINESS_NAME",
        "From Name": "YOUR_BUSINESS_NAME"
      },
      "outputs": [
        "id",
        "thread_id"
      ]
    }
  ]
}
