Thư viện QueriesGửi email tạm biệt đến người dùng hủy đăng ký khỏi ConvertKit (qua webhook)
Gửi email tạm biệt đến người dùng hủy đăng ký khỏi ConvertKit (qua webhook)
Khi người dùng kích hoạt một sự kiện trên ConvertKit (chẳng hạn như đăng ký hoặc hủy đăng ký), dịch vụ sẽ gọi một webhook kèm theo dữ liệu sự kiện. Chúng ta có thể thiết lập một Persisted Query làm webhook để xử lý dữ liệu đến này và thực thi một hành động với nó.
Query này gửi một email tạm biệt (bao gồm liên kết đến biểu mẫu yêu cầu phản hồi) đến người đã hủy đăng ký trên ConvertKit.
query ExtractPayloadData {
body: _httpRequestBody
bodyJSONObject: _strDecodeJSONObject(string: $__body)
subscriberFirstName: _objectProperty(
object: $__bodyJSONObject,
by: { path: "subscriber.first_name" }
)
@export(as: "subscriberFirstName")
subscriberEmail: _objectProperty(
object: $__bodyJSONObject,
by: { path: "subscriber.email_address" }
)
@export(as: "subscriberEmail")
}
query CreateEmailMessage(
$formURL: URL!
)
@depends(on: "ExtractPayloadData")
{
emailMessageTemplate: _strConvertMarkdownToHTML(
text: """
Hey {$subscriberFirstName}, it's sad to let you go!
Please be welcome to complete [this form]({$formURL}) and let us know if there is anything we can do better.
Thanks. Hope to see you back!
"""
)
emailMessage: _strReplaceMultiple(
search: ["{$subscriberFirstName}", "{$formURL}"],
replaceWith: [$subscriberFirstName, $formURL],
in: $__emailMessageTemplate
)
@export(as: "emailMessage")
}
mutation SendFarewellEmailToUnsubscribingUsersFromConvertKit
@depends(on: "CreateEmailMessage")
{
_sendEmail(
input: {
to: $subscriberEmail
subject: "Would you like to give us feedback on how we can improve?"
messageAs: {
html: $emailMessage
}
}
) {
status
}
}