Monitor customer note for certain information, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Monitor customer note for certain information

Use this task to keep an eye on the contents of a customer's note. When the text you want to watch for is added (e.g. "Authorization number:", or "VAT Registration Number:", or anything else!), Mechanic will add the tag of your choice to the customer, and optionally send you a notification email.

Runs Occurs whenever a customer is created and Occurs whenever a customer is updated. Configuration includes text to watch for in the customer note, require a case sensitive match, customer tag to apply, and staff notification email recipient.

15-day free trial – unlimited tasks

Documentation

Use this task to keep an eye on the contents of a customer's note. When the text you want to watch for is added (e.g. "Authorization number:", or "VAT Registration Number:", or anything else!), Mechanic will add the tag of your choice to the customer, and optionally send you a notification email.

Please note: Mechanic uses the absence of this task's tag to determine if any work should be done. This means that if the tag Mechanic adds is later removed, and if the customer note still has the matching text, Mechanic will re-tag the customer (and re-send a notification email, if configured) the next time the customer is updated.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
shopify/customers/create
shopify/customers/update
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
text to watch for in the customer note (required), require a case sensitive match (boolean), customer tag to apply (required), staff notification email recipient (email)
Code
{% comment %}
  Express an opinion about option order:

  {{ options.text_to_watch_for_in_the_customer_note__required }}
  {{ options.require_a_case_sensitive_match__boolean }}
  {{ options.customer_tag_to_apply__required }}
  {{ options.staff_notification_email_recipient__email }}
{% endcomment %}

{% assign match_text = options.text_to_watch_for_in_the_customer_note__required | strip %}

{% assign customer_qualifies = false %}
{% assign customer_tags = customer.tags | split: ", " %}

{% assign case_sensitive = options.require_a_case_sensitive_match__boolean %}

{% unless customer_tags contains options.customer_tag_to_apply__required %}
  {% if options.require_a_case_sensitive_match__boolean %}
    {% if customer.note contains match_text %}
      {% assign customer_qualifies = true %}
    {% endif %}
  {% else %}
    {% assign customer_note_downcased = customer.note | downcase %}
    {% assign match_text_downcased = match_text | downcase %}
    {% if customer_note_downcased contains match_text_downcased %}
      {% assign customer_qualifies = true %}
    {% endif %}
  {% endif %}
{% endunless %}

{% if event.preview or customer_qualifies %}
  {% if options.staff_notification_email_recipient__email != blank %}
    {% capture email_subject %}
      [{{ shop.name }}] Customer {{ customer.email }} has {{ match_text | json }} in their note
    {% endcapture %}

    {% assign replacement = "<b>" | append: match_text | append: "</b>" %}

    {% capture email_body %}
      Hi there,

      The customer note for {{ customer.email }} was found to contain some matching text:

      <blockquote>{{ customer.note | replace: match_text, replacement | default: "(preview of customer note)" }}</blockquote>

      View this customer's details:

      https://{{ shop.domain }}/admin/customers/{{ customer.id }}

      Thanks,
      Mechanic (for {{ shop.name }})
    {% endcapture %}

    {% action "email" %}
      {
        "to": {{ options.staff_notification_email_recipient__email | json }},
        "subject": {{ email_subject | strip | json }},
        "body": {{ email_body | unindent | strip | newline_to_br | json }},
        "reply_to": {{ shop.customer_email | json }},
        "from_display_name": {{ shop.name | json }}
      }
    {% endaction %}
  {% endif %}

  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ customer.admin_graphql_api_id | default: "gid://shopify/Customer/1234567890" | json }}
        tags: {{ options.customer_tag_to_apply__required | json }}
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more