Thư viện Queries
Thư viện QueriesGửi email cá nhân hóa đến người dùng của bạn

Gửi email cá nhân hóa đến người dùng của bạn

Query này lấy danh sách người dùng, thu thập dữ liệu của họ (tên, email và số tín dụng còn lại, được lưu dưới dạng meta), rồi gửi email cá nhân hóa đến từng người.

Query này yêu cầu endpoint phải bật Nested Mutations.

mutation SendPersonalizedEmailToUsers {
  users {
    email
    displayName
    credits: metaValue(key: "credits")
    
    # If the user does not have meta entry "credits", use `0` credits
    hasNoCreditsEntry: _isNull(value: $__credits)
    remainingCredits: _if(condition: $__hasNoCreditsEntry, then: 0, else: $__credits)
 
    emailMessageTemplate: _strConvertMarkdownToHTML(
      text: """
 
Hello %s,
 
Your have **%s remaining credits** in your account.
 
Would you like to [buy more](%s)?
 
      """
    )
    emailMessage: _sprintf(
      string: $__emailMessageTemplate,
      values: [
        $__displayName,
        $__remainingCredits,
        "https://mysite.com/buy-credits"
      ]
    )
 
    _sendEmail(
      input: {
        to: $__email
        subject: "Remaining credits alert"
        messageAs: {
          html: $__emailMessage
        }
      }
    ) {
      status
      errors {
        __typename
        ...on ErrorPayload {
          message
        }
      }
    }
  }
}