{
  "schema_version": "1.0.0",
  "id": "missed-call-text-back",
  "title": "Text back a missed CallRail call",
  "category": "speed-to-lead",
  "difficulty": "intermediate",
  "featured": true,
  "description": "When a tracked call goes unanswered, text the caller back with wording for open or closed hours, log it, and page the owner after hours.",
  "tags": [
    "missed-call",
    "callrail",
    "twilio",
    "sms",
    "speed-to-lead"
  ],
  "apps": [
    "CallRail",
    "Filter by Zapier",
    "Code by Zapier",
    "Paths by Zapier",
    "Twilio",
    "Google Sheets",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 10 steps after the trigger",
      "Filter by Zapier",
      "Paths by Zapier"
    ]
  },
  "tasks": {
    "typical": 0,
    "max": 5
  },
  "trigger": {
    "app": "CallRail",
    "event": "Post-Call",
    "kind": "instant",
    "title": "A tracked call ends",
    "why": "CallRail sends every finished call. The filter in the next step keeps only the ones nobody picked up.",
    "config": {
      "Company": "YOUR_CALLRAIL_COMPANY"
    },
    "outputs": [
      "call_id",
      "answered",
      "customer_phone_number",
      "customer_name",
      "start_time",
      "duration",
      "tracking_phone_number",
      "source",
      "first_call"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "missed",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only unanswered calls",
      "why": "Answered calls stop here. Most calls are answered, so most runs end at this step and use no tasks.",
      "conditions": [
        [
          {
            "field": "{{trigger.answered}}",
            "operator": "(Boolean) Is false"
          }
        ]
      ],
      "usually": false
    },
    {
      "key": "hours",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Check whether the office is open",
      "why": "The text promises a call in minutes only when someone is actually there to make it.",
      "code": {
        "language": "javascript",
        "module": "business-hours",
        "file": "code/business-hours.js"
      },
      "input_data": {
        "timestamp": "{{trigger.start_time}}",
        "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": "route",
      "kind": "paths",
      "app": "Paths by Zapier",
      "event": "Split into paths",
      "title": "Open or after hours",
      "why": "Two wordings, one decision. The rules test is_open both ways, so exactly one path runs.",
      "paths": [
        {
          "name": "Open",
          "conditions": [
            [
              {
                "field": "{{hours.is_open}}",
                "operator": "(Boolean) Is true"
              }
            ]
          ],
          "usually": true,
          "steps": [
            {
              "key": "sms_open",
              "kind": "code",
              "app": "Code by Zapier",
              "event": "Run JavaScript",
              "title": "Write the daytime text",
              "why": "Promises a call back within ten minutes and keeps the text to one segment.",
              "code": {
                "language": "javascript",
                "module": "fit-sms",
                "file": "code/fit-sms.js"
              },
              "input_data": {
                "template": "Hi {first_name}, sorry we missed your call to {business}. We are on another job and will call you back within 10 minutes. Reply here if texting is easier.",
                "first_name": "{{trigger.customer_name}}",
                "business": "YOUR_BUSINESS_NAME",
                "link": ""
              },
              "outputs": [
                "message",
                "encoding",
                "length",
                "segments",
                "trimmed"
              ]
            },
            {
              "key": "text_open",
              "kind": "action",
              "app": "Twilio",
              "event": "Send SMS",
              "title": "Text the caller",
              "why": "Replies from the Twilio number the team watches.",
              "fields": {
                "From Number": "YOUR_TWILIO_NUMBER",
                "To Number": "{{trigger.customer_phone_number}}",
                "Message": "{{sms_open.message}}",
                "Send Large Messages?": "No"
              },
              "outputs": [
                "sid",
                "status"
              ]
            },
            {
              "key": "log_open",
              "kind": "action",
              "app": "Google Sheets",
              "event": "Create Spreadsheet Row",
              "title": "Log the missed call",
              "why": "One row per missed call, so the weekly count is a filter on the sheet.",
              "fields": {
                "Drive": "My Google Drive",
                "Spreadsheet": "Calls",
                "Worksheet": "Missed",
                "Columns": {
                  "call_time": "{{trigger.start_time}}",
                  "caller": "{{trigger.customer_name}}",
                  "phone": "{{trigger.customer_phone_number}}",
                  "source": "{{trigger.source}}",
                  "first_call": "{{trigger.first_call}}",
                  "local_time": "{{hours.local_time}}",
                  "when": "open",
                  "texted": "{{text_open.status}}"
                }
              },
              "outputs": [
                "id",
                "row_number"
              ]
            }
          ]
        },
        {
          "name": "After hours",
          "conditions": [
            [
              {
                "field": "{{hours.is_open}}",
                "operator": "(Boolean) Is false"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "sms_closed",
              "kind": "code",
              "app": "Code by Zapier",
              "event": "Run JavaScript",
              "title": "Write the after-hours text",
              "why": "Names the next opening time instead of promising a call nobody will make tonight.",
              "code": {
                "language": "javascript",
                "module": "fit-sms",
                "file": "code/fit-sms.js"
              },
              "input_data": {
                "template": "Hi {first_name}, thanks for calling {business}. We are closed right now and will call you at {{hours.next_open}}. For a burst pipe or no heat, reply URGENT.",
                "first_name": "{{trigger.customer_name}}",
                "business": "YOUR_BUSINESS_NAME",
                "link": ""
              },
              "outputs": [
                "message",
                "encoding",
                "length",
                "segments",
                "trimmed"
              ]
            },
            {
              "key": "text_closed",
              "kind": "action",
              "app": "Twilio",
              "event": "Send SMS",
              "title": "Text the caller",
              "why": "Same Twilio number, after-hours wording.",
              "fields": {
                "From Number": "YOUR_TWILIO_NUMBER",
                "To Number": "{{trigger.customer_phone_number}}",
                "Message": "{{sms_closed.message}}",
                "Send Large Messages?": "No"
              },
              "outputs": [
                "sid",
                "status"
              ]
            },
            {
              "key": "log_closed",
              "kind": "action",
              "app": "Google Sheets",
              "event": "Create Spreadsheet Row",
              "title": "Log the missed call",
              "why": "Same sheet as the daytime path, marked after hours.",
              "fields": {
                "Drive": "My Google Drive",
                "Spreadsheet": "Calls",
                "Worksheet": "Missed",
                "Columns": {
                  "call_time": "{{trigger.start_time}}",
                  "caller": "{{trigger.customer_name}}",
                  "phone": "{{trigger.customer_phone_number}}",
                  "source": "{{trigger.source}}",
                  "first_call": "{{trigger.first_call}}",
                  "local_time": "{{hours.local_time}}",
                  "when": "after hours",
                  "texted": "{{text_closed.status}}"
                }
              },
              "outputs": [
                "id",
                "row_number"
              ]
            },
            {
              "key": "owner",
              "kind": "action",
              "app": "Slack",
              "event": "Send Channel Message",
              "title": "Tell the owner",
              "why": "After hours the owner decides whether it is worth a call tonight; first-time callers are the ones to watch.",
              "fields": {
                "Channel": "#missed-calls",
                "Message Text": ":telephone_receiver: After-hours missed call from {{trigger.customer_name}} {{trigger.customer_phone_number}} via {{trigger.source}} (first call: {{trigger.first_call}}). They were told we call at {{hours.next_open}}.",
                "Send as a bot?": "Yes",
                "Bot Name": "Zap alerts",
                "Include a link to this Zap?": "No"
              },
              "outputs": [
                "ts",
                "permalink"
              ]
            }
          ]
        }
      ]
    }
  ]
}
