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.
Try this taskWhen it runs
- Occurs whenever a customer is created
- Occurs whenever a customer is updated
What you choose
- Text to watch for in the customer note
- Require a case sensitive match
- Customer tag to apply
- Staff notification email recipient
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.
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
shopify/customers/create
shopify/customers/update
How task subscriptions work
Option types and flags
- 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)
Task 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 %}
Mechanic Liquid reference