Biblioteca de queriesEnviar un email a los suscriptores notificando de un nuevo post
Enviar un email a los suscriptores notificando de un nuevo post
Esta consulta envía un email a todos los usuarios, notificando de la creación de un nuevo post en el sitio.
Incluye la capacidad de seleccionar usuarios que se suscribieron a una lista de correo, sin embargo esta porción de la consulta está comentada. (Por favor, descoméntala si es necesario.) Los usuarios suscritos son aquellos con el meta email_list con valor new_posts.
Esta consulta requiere que el endpoint tenga habilitadas las Mutaciones Anidadas.
query GetPostAndExportData($postId: ID!) {
post(by: { id: $postId }) {
content @export(as: "postContent")
title @export(as: "postTitle")
url @export(as: "postURL")
}
hasPost: _notNull(value: $__post)
@export(as: "doSendEmail")
}
query GetEmailData
@depends(on: "GetPostAndExportData")
@include(if: $doSendEmail)
{
siteName: optionValue(name: "blogname")
@export(as: "siteName")
emailSubject: _sprintf(
string: "There is a new post: \"%s\"",
values: [$postTitle]
)
@export(as: "emailSubject")
}
mutation SendEmailToUsersAboutNewPost
@depends(on: "GetEmailData")
@include(if: $doSendEmail)
{
users
# # Retrieve only users subscribed to an email list (uncomment if needed)
# (
# filter: {
# metaQuery: {
# key: "email_list",
# compareBy: {
# arrayValue: {
# value: "new_posts",
# operator: IN
# }
# }
# }
# }
# )
{
displayName
email
emailMessageTemplate: _strConvertMarkdownToHTML(
text: """
Hi {$userDisplayName},
There is a new post on the **{$siteName}** website:
[**{$postTitle}**]({$postURL})
{$postContent}
"""
)
@remove
emailMessage: _strReplaceMultiple(
search: ["{$userDisplayName}", "{$siteName}", "{$postTitle}", "{$postContent}", "{$postURL}"],
replaceWith: [$__displayName, $siteName, $postTitle, $postContent, $postURL],
in: $__emailMessageTemplate
)
@remove
_sendEmail(
input: {
to: $__email
subject: $emailSubject
messageAs: {
html: $__emailMessage
}
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
}
}
}