쿼리 라이브러리새 게시물 알림을 구독자에게 이메일로 보내기
새 게시물 알림을 구독자에게 이메일로 보내기
이 쿼리는 사이트에 새 게시물이 생성되었음을 모든 사용자에게 이메일로 알립니다.
이메일 목록에 구독한 사용자만 선택하는 기능도 포함되어 있으나, 해당 부분은 주석 처리되어 있습니다. (필요한 경우 주석을 해제하세요.) 구독한 사용자란 메타 email_list의 값이 new_posts인 사용자를 의미합니다.
이 쿼리를 실행하려면 엔드포인트에서 중첩 뮤테이션이 활성화되어 있어야 합니다.
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
}
}
}
}
}