Class: Sendgo::NoticeTemplateService

Inherits:
Object
  • Object
show all
Defined in:
lib/sendgo/management.rb

Overview

알림톡 템플릿 관리 — 등록 · 수정 · 검수 요청.

v2 전용이며 기업(Team) 소유 애플리케이션만 사용할 수 있다.

템플릿은 만든 즉시 쓸 수 없다. 카카오 검수를 통과해야 한다.

등록      inspectionStatus=REG   ← 발송 불가
검수 요청  inspectionStatus=REQ   ← 카카오 심사 중
승인      inspectionStatus=APR   ← 여기부터 발송 가능
반려      inspectionStatus=REJ   ← comments 에 사유

검수 결과는 비동기다. 웹훅이 없으므로 sync 로 폴링한다.

Constant Summary collapse

RESOURCE =
"notice-templates"

Instance Method Summary collapse

Constructor Details

#initialize(http:) ⇒ NoticeTemplateService

Returns a new instance of NoticeTemplateService.



117
118
119
# File 'lib/sendgo/management.rb', line 117

def initialize(http:)
  @http = http
end

Instance Method Details

#cancel_approval(template_code) ⇒ Object

승인 취소. 승인(+APR+)된 템플릿을 되돌린다. 이후에는 발송할 수 없다.



213
214
215
# File 'lib/sendgo/management.rb', line 213

def cancel_approval(template_code)
  @http.delete("#{path(template_code)}/approval")
end

#cancel_inspection(template_code) ⇒ Object

검수 요청 취소. 아직 심사 중(+REQ+)일 때만 통한다.



208
209
210
# File 'lib/sendgo/management.rb', line 208

def cancel_inspection(template_code)
  @http.delete("#{path(template_code)}/inspection")
end

#categories(category_code = nil) ⇒ Object

템플릿 카테고리 코드 조회.



223
224
225
# File 'lib/sendgo/management.rb', line 223

def categories(category_code = nil)
  @http.get("#{RESOURCE}/categories", { categoryCode: category_code })
end

#create(kakao_sender_key:, template_name:, template_content:, template_message_type:, template_emphasize_type:, category_code:, message_purpose:, legal_basis:, benefit_origin:, expiry_type:, opt_in_review_confirmed: true, cta_clear_confirmed: true, policy_confirmed: true, image: nil, **extra) ⇒ Object

템플릿 등록.

정책 인자 일곱 개는 sendgo 자체 게이트다. 카카오 심사와 별개이며 조합이 본문과 어긋나면 POLICY_VALIDATION_FAILED 로 거절된다. 확인 플래그 셋은 기본값이 true 지만, 내용을 실제로 검토한 뒤에 그대로 두어야 한다 — 이 값은 법적 확인의 기록이다.

선택 필드(+templateTitle+, buttons 등)는 extra 로 넘긴다. image 를 주면 이미지 템플릿으로 multipart 전송한다.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/sendgo/management.rb', line 145

def create(kakao_sender_key:, template_name:, template_content:,
           template_message_type:, template_emphasize_type:, category_code:,
           message_purpose:, legal_basis:, benefit_origin:, expiry_type:,
           opt_in_review_confirmed: true, cta_clear_confirmed: true,
           policy_confirmed: true, image: nil, **extra)
  body = {
    kakaoSenderKey: kakao_sender_key,
    templateName: template_name,
    templateContent: template_content,
    templateMessageType: template_message_type,
    templateEmphasizeType: template_emphasize_type,
    categoryCode: category_code,
    messagePurpose: message_purpose,
    legalBasis: legal_basis,
    benefitOrigin: benefit_origin,
    expiryType: expiry_type,
    optInReviewConfirmed: opt_in_review_confirmed,
    ctaClearConfirmed: cta_clear_confirmed,
    policyConfirmed: policy_confirmed
  }.merge(camelize_keys(extra))

  return @http.post_multipart(RESOURCE, body, { image: image }) if image

  @http.post(RESOURCE, body)
end

#delete(template_code) ⇒ Object

템플릿 삭제.

카카오는 템플릿 삭제 API 를 제공하지 않는다. sendgo 목록에서만 지워지고 비즈니스 채널 쪽 템플릿은 남는다. 동기화하면 다시 나타난다.



183
184
185
# File 'lib/sendgo/management.rb', line 183

def delete(template_code)
  @http.delete(path(template_code))
end

#list(kakao_sender_key: nil, inspection_status: nil, search: nil, count: nil) ⇒ Object

목록 조회.



122
123
124
125
126
127
128
129
# File 'lib/sendgo/management.rb', line 122

def list(kakao_sender_key: nil, inspection_status: nil, search: nil, count: nil)
  @http.get(RESOURCE, {
              kakaoSenderKey: kakao_sender_key,
              inspectionStatus: inspection_status,
              search: search,
              count: count
            })
end

#release(template_code) ⇒ Object

휴면 해제. 오래 안 쓴 템플릿이 dormant 로 잠기면 이걸로 깨운다.



218
219
220
# File 'lib/sendgo/management.rb', line 218

def release(template_code)
  @http.post("#{path(template_code)}/release", {})
end

#request_inspection(template_code, comment: nil, attachments: nil) ⇒ Object

검수 요청.

첨부가 있으면 comment 는 필수다. 정책 검토를 통과하지 못한 템플릿은 POLICY_REVIEW_REQUIRED 로 거절되고 errors.reasons 에 사유가 담긴다.



196
197
198
199
200
201
202
203
204
205
# File 'lib/sendgo/management.rb', line 196

def request_inspection(template_code, comment: nil, attachments: nil)
  endpoint = "#{path(template_code)}/inspection"

  if attachments.nil? || attachments.empty?
    body = comment ? { comment: comment } : {}
    return @http.post(endpoint, body)
  end

  @http.post_multipart(endpoint, { comment: comment }, { attachments: attachments })
end

#show(template_code) ⇒ Object

상세 조회. 응답의 data.template.policy 에 정책 검토 상태가 들어 있다.



132
133
134
# File 'lib/sendgo/management.rb', line 132

def show(template_code)
  @http.get(path(template_code))
end

#sync(template_code) ⇒ Object

카카오에서 검수 상태와 반려 사유를 다시 읽어 온다.



188
189
190
# File 'lib/sendgo/management.rb', line 188

def sync(template_code)
  @http.post("#{path(template_code)}/sync", {})
end

#update(template_code, **fields) ⇒ Object

템플릿 수정.

발신프로필과 템플릿 코드는 바꿀 수 없다. 본문·버튼처럼 카카오에 등록된 내용이 바뀌면 검수 상태가 되돌아가므로 재검수를 요청해야 한다.



175
176
177
# File 'lib/sendgo/management.rb', line 175

def update(template_code, **fields)
  @http.put(path(template_code), camelize_keys(fields))
end