쿼리 라이브러리
쿼리 라이브러리새 게시물 생성 시 관리자에게 이메일로 알림 보내기

새 게시물 생성 시 관리자에게 이메일로 알림 보내기

이 쿼리는 사이트에 새 게시물이 생성되었음을 관리자 사용자에게 이메일로 알립니다:

query GetPostAndExportData($postId: ID!) {
  post(by: { id: $postId }, status: any) {
    content @export(as: "postContent")
    title @export(as: "postTitle")
    url @export(as: "postURL")
  }
}
 
query GetEmailData
  @depends(on: "GetPostAndExportData")
{
  adminEmail: optionValue(name: "admin_email")
    @export(as: "adminEmail")
 
  emailMessageTemplate: _strConvertMarkdownToHTML(
    text: """
 
There is a [new post on the site]({$postURL}):
 
**{$postTitle}**:
 
{$postContent}
 
    """
  )
  emailMessage: _strReplaceMultiple(
    search: ["{$postTitle}", "{$postContent}", "{$postURL}"],
    replaceWith: [$postTitle, $postContent, $postURL],
    in: $__emailMessageTemplate
  )
    @export(as: "emailMessage")
 
  emailSubject: _sprintf(
    string: "New post: \"%s\"",
    values: [$postTitle]
  )
    @export(as: "emailSubject")
}
 
mutation SendEmailToAdminAboutNewPost @depends(on: "GetEmailData") {
  _sendEmail(
    input: {
      to: $adminEmail
      subject: $emailSubject
      messageAs: {
        html: $emailMessage
      }
    }
  ) {
    status
  }
}