Gato GraphQL automation demo

Automatically sending an email to all subscribers notifying of a new post

Whenever creating a new post on the WordPress site, automatically send a notification email to all subscriber users.

Leonardo Losoviz
Leonardo Losoviz -
Gato GraphQL logo
Image
Target Image

We can use Gato GraphQL to automatically send a notification email to all users subscribed to an email list, whenever a new post is created on the site.

In the demo video, we first execute persisted query Send email to users about post and test sending an email with the content of a specific post.

We test it by passing GraphQL variable $postId with value 1 in the JSON dictionary, and executing the GraphQL query. When checking in Mailpit (which intercepts all emails), we verify that a personalized email was indeed sent to all users.

For instance, user "Blogger Davenport" received the following email:

Notification email about new post sent to user
Notification email about new post sent to user

By default, that GraphQL persisted query sends the email to all users. We can also specify which users to send the email to, such as those who have been subscribed to some email list. This is done by uncommenting the users(filter:) input in the query:

{
  users
  # # Retrieve only users subscribed to an email list (uncomment if needed)
  # (
  #   filter: {
  #     metaQuery: {
  #       key: "email_list",
  #       compareBy: {
  #         arrayValue: {
  #           value: "new_posts",
  #           operator: IN
  #         }
  #       }
  #     }
  #   }
  # )
}

This filter then retrieves those users who have meta email_list (which is an array of list names) with value new_posts.

When executing the query again, this time the email was sent to 3 users (those subscribed to that email list).

Finally we automate the process, so that whenever there is a new post on the site, the notification email is automatically sent. For that, we publish automation rule Send notification email to users when there is a new post.

This automation rule is triggered on hook gatographql:draft_to_publish. As such, whenever the status of a post is switched from draft to publish, a notification email is automatically sent to the users.


Want more demo videos?

Receive timely updates as we keep improving Gato GraphQL.

No spam. You can unsubscribe at any time.