Send email alerts by event topic
This task allows you to receive an email alert for any event topic supported by Mechanic. Configure the task with a list of email addresses to notify, an email subject, and one or more event topics, each paired with an email body that supports liquid output tags for the main object of each event (e.g. shopify/products/create can use attributes like {{ product.id }} or {{ product.title }})
Try this taskWhen it runs
- Occurs whenever a product is created
- Occurs whenever a customer is created
What you choose
- Emails to notify
- General email subject
- Append event topic to email subject
- Event topics and email bodies
Documentation
This task allows you to receive an email alert for any event topic supported by Mechanic. Configure the task with a list of email addresses to notify, an email subject, and one or more event topics, each paired with an email body that supports liquid output tags for the main object of each event (e.g. shopify/products/create can use attributes like {{ product.id }} or {{ product.title }})
The task comes preloaded with the customers and products create event topics, along with sample email bodies. Configure to taste :) The full list of supported event topics can be found here.
Note:
- The task will replace the OBJECT_LINK string within the email body if present (and where it makes sense to do so) with an admin link to the Shopify object related to the event topic.
- Some event topics, like shopify/products/update and shopify/inventory_levels/update, can generate a lot of emails, so they should be used with caution.
- When using the shopify/orders/edited event topic, the original order can be referenced using {{ order_edit.order }}.
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
{{ options.event_topics_and_email_bodies__keyval_multiline_required | keys | join: newline }}
How task subscriptions work
Option types and flags
- Emails to notify (array, required)
- General email subject (required)
- Append event topic to email subject (boolean)
- Event topics and email bodies (keyval, multiline, required)
Task code
{% comment %}
Preferred option order:
{{ options.emails_to_notify__array_required }}
{{ options.general_email_subject__required }}
{{ options.append_event_topic_to_email_subject__boolean }}
{{ options.event_topics_and_email_bodies__keyval_multiline_required }}
{% endcomment %}
{% assign email_recipients = options.emails_to_notify__array_required %}
{% for keyval in options.event_topics_and_email_bodies__keyval_multiline_required %}
{% assign configured_event_topic = keyval.first %}
{% if event.topic == configured_event_topic %}
{% assign email_subject = options.general_email_subject__required %}
{% assign email_body = keyval.last %}
{% if options.append_event_topic_to_email_subject__boolean %}
{% assign email_subject = email_subject | append: " [" | append: configured_event_topic | append: "]" %}
{% endif %}
{% capture admin_link %}https://{{ shop.myshopify_domain }}/admin/{% endcapture %}
{% assign object_link = nil %}
{% if event.topic contains "shopify/collections/" %}
{% capture object_link %}collections/{{ collection.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/customers/" %}
{% capture object_link %}customers/{{ customer.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/draft_orders/" %}
{% capture object_link %}draft_orders/{{ draft_order.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/fulfillment_events/" %}
{% capture object_link %}orders/{{ fulfillment_event.order.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/fulfillments/" %}
{% capture object_link %}orders/{{ fulfillment.order.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/orders/" %}
{% capture object_link %}orders/{{ order.id | default: order_edit.order.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/products/" %}
{% capture object_link %}products/{{ product.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/refunds/" %}
{% capture object_link %}orders/{{ refund.order.id | default: 1234567890 }}{% endcapture %}
{% elsif event.topic contains "shopify/themes/" %}
{% capture object_link %}themes/{{ theme.id | default: 1234567890 }}{% endcapture %}
{% endif%}
{% if object_link != blank %}
{% assign object_link = admin_link | append: object_link %}
{% else %}
{% assign object_link = "[<small>Object link could not be generated</small>]" %}
{% endif %}
{% assign email_body = email_body | replace: "OBJECT_LINK", object_link %}
{% action "email" %}
{
"to": {{ email_recipients | join: ", " | json }},
"subject": {{ email_subject | json }},
"body": {{ email_body | unindent | newline_to_br | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}
{% endfor %}
Mechanic Liquid reference
Default option values
- General email subject
ALERT- Append event topic to email subject
true- Event topics and email bodies
{"shopify/products/create" => "Hi,\n\nProduct {{ product.id }} was created\n\nView the details in Shopify:\nOBJECT_LINK", "shopify/customers/create" => "Hi\n\nCustomer {{ customer.id }} was created\n\nView the details in Shopify:\nOBJECT_LINK"}