{
  "schema_version": "1.0.0",
  "id": "inbound-sms-to-hubspot",
  "title": "Log an inbound text against the right HubSpot contact",
  "category": "speed-to-lead",
  "difficulty": "intermediate",
  "featured": false,
  "description": "Match each text to your Twilio number to a HubSpot contact by phone; log it as a note, or create the contact and alert the team when it is new.",
  "tags": [
    "twilio",
    "hubspot",
    "sms",
    "crm",
    "slack"
  ],
  "apps": [
    "Twilio",
    "HubSpot",
    "Paths by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 5 steps after the trigger",
      "Paths by Zapier"
    ]
  },
  "tasks": {
    "typical": 2,
    "max": 3
  },
  "trigger": {
    "app": "Twilio",
    "event": "New Received SMS",
    "kind": "polling",
    "title": "Text received",
    "why": "Fires for each text that arrives on your Twilio number.",
    "config": {
      "Phone Number": "YOUR_TWILIO_NUMBER"
    },
    "outputs": [
      "message_sid",
      "from_number",
      "to_number",
      "body",
      "received_at"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "contact",
      "kind": "search",
      "app": "HubSpot",
      "event": "Find Contact",
      "title": "Find the contact by phone",
      "why": "Twilio gives the number in E.164; store phone numbers the same way in HubSpot for the match to work.",
      "fields": {
        "First search property name": "Phone Number",
        "First search property value": "{{trigger.from_number}}",
        "Should this step be considered a \"success\" when nothing is found?": "Yes"
      },
      "outputs": [
        "id",
        "firstname",
        "email",
        "hubspot_owner_id",
        "_zap_search_was_found_status"
      ]
    },
    {
      "key": "route",
      "kind": "paths",
      "app": "Paths by Zapier",
      "event": "Split into paths",
      "title": "Known contact or new number",
      "why": "The rules test the search result both ways, so one path runs.",
      "paths": [
        {
          "name": "Known contact",
          "conditions": [
            [
              {
                "field": "{{contact._zap_search_was_found_status}}",
                "operator": "(Boolean) Is true"
              }
            ]
          ],
          "usually": true,
          "steps": [
            {
              "key": "note",
              "kind": "action",
              "app": "HubSpot",
              "event": "Create Engagement",
              "title": "Log the text as a note",
              "why": "The text shows on the contact timeline next to calls and emails.",
              "fields": {
                "Type": "Note",
                "Associated Contact ID": "{{contact.id}}",
                "Body": "Inbound SMS from {{trigger.from_number}} at {{trigger.received_at}}:\n{{trigger.body}}"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "New number",
          "conditions": [
            [
              {
                "field": "{{contact._zap_search_was_found_status}}",
                "operator": "(Boolean) Is false"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "create",
              "kind": "action",
              "app": "HubSpot",
              "event": "Create or Update Contact",
              "title": "Create the contact",
              "why": "Creates a contact keyed on the phone number with the first message as context.",
              "fields": {
                "Phone Number": "{{trigger.from_number}}",
                "Lead Status": "New",
                "Original Source Drill-Down 1": "Inbound SMS",
                "Message": "{{trigger.body}}"
              },
              "outputs": [
                "id",
                "is_new"
              ]
            },
            {
              "key": "alert",
              "kind": "action",
              "app": "Slack",
              "event": "Send Channel Message",
              "title": "Alert the team",
              "why": "A text from a number HubSpot does not know is usually a new lead.",
              "fields": {
                "Channel": "#sales",
                "Message Text": ":speech_balloon: Text from a new number {{trigger.from_number}}: \"{{trigger.body}}\". Contact created: https://app.hubspot.com/contacts/YOUR_PORTAL_ID/contact/{{create.id}}",
                "Send as a bot?": "Yes",
                "Bot Name": "Zap alerts",
                "Include a link to this Zap?": "No"
              },
              "outputs": [
                "ts",
                "permalink"
              ]
            }
          ]
        }
      ]
    }
  ]
}
