sendgo 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +36 -0
- data/lib/sendgo/brand_message.rb +106 -0
- data/lib/sendgo/client.rb +5 -1
- data/lib/sendgo/http_client.rb +35 -10
- data/lib/sendgo/short_url.rb +62 -0
- data/lib/sendgo/version.rb +1 -1
- data/lib/sendgo.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9c4b04d7a030a8e34230298a109a86571e7089878dd0d5bb8d8bd07a519aeba
|
|
4
|
+
data.tar.gz: 94b0e1785aac53f05b32cd211901cba951564f4139ad6df7a32684dee559a96a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a68d90dc67ee4ef919978e47dae16609431b8f18ce18240eba2427f6ac1023b2aeda677072a571f1006881df9d65fdfa98aec95a96a0f3a813792db8b473b6b
|
|
7
|
+
data.tar.gz: e6d730f1f9e01db94024083f1f9fb47bbb7954c1809f479f91ec7308bb2df3e2bab56e6291559185a400955f4a066c8bc68fa769b25422cc426b531e0b465b61
|
data/README.md
CHANGED
|
@@ -125,6 +125,42 @@ client.friendtalk.send(
|
|
|
125
125
|
|
|
126
126
|
---
|
|
127
127
|
|
|
128
|
+
## 브랜드메시지 사용법
|
|
129
|
+
|
|
130
|
+
브랜드메시지는 친구톡의 후속 채널입니다. 메시지 타입이 친구톡과 1:1 대응되며
|
|
131
|
+
(`FT`→`BT`, `FI`→`BI`, `FW`→`BW`, `FL`→`BL`, `FC`→`BC`, `FM`→`BM`, `FP`→`BP`, `FA`→`BA`),
|
|
132
|
+
요청에는 **친구톡 코드를 그대로** 넘기고 변환은 서버가 처리합니다.
|
|
133
|
+
|
|
134
|
+
친구톡과 달리 다음이 가능합니다.
|
|
135
|
+
|
|
136
|
+
- 채널 친구가 **아닌** 수신자에게 발송 (`targeting: N`)
|
|
137
|
+
- 수신 동의한 **전체 채널 친구 동보** 발송 (`targeting: F`, 수신자 목록 불필요)
|
|
138
|
+
- 리스트·캐러셀·커머스·동영상 등 **템플릿 기반 리치 메시지**
|
|
139
|
+
|
|
140
|
+
> v2 전용입니다. `FT`/`FI`/`FW`를 채널 친구에게만 보낼 때는 친구톡 API가 더 간단합니다.
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
# 단건 발송 — 채널 친구 대상
|
|
144
|
+
client.brand_message.send(
|
|
145
|
+
targeting: "M",
|
|
146
|
+
message_type: "FL",
|
|
147
|
+
friend_template_uuid: "9cd5460b-6458-4edc-9b11-c26d3013c340",
|
|
148
|
+
contacts: [{ contact: "01012345678", var1: "29,000원" }]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# 동보 발송 — 수신 동의한 전체 채널 친구 (contacts 불필요)
|
|
152
|
+
client.brand_message.broadcast(
|
|
153
|
+
message_type: "FW",
|
|
154
|
+
friend_template_uuid: "9cd5460b-6458-4edc-9b11-c26d3013c340"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# 캠페인 조회
|
|
158
|
+
campaigns = client.brand_message.campaigns(from: "2026-08-01", count: 10)
|
|
159
|
+
one = client.brand_message.campaign("1f0a6d0e-6b3b-4f0f-9b2f-2f6f6a1b7c11")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
128
164
|
## SMS / LMS / MMS 사용법
|
|
129
165
|
|
|
130
166
|
```ruby
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
module Sendgo
|
|
2
|
+
# 카카오 브랜드메시지 전송 서비스.
|
|
3
|
+
#
|
|
4
|
+
# 브랜드메시지는 친구톡의 후속 채널로, 메시지 타입이 친구톡과 1:1 대응된다
|
|
5
|
+
# (FT→BT, FI→BI, FW→BW, FL→BL, FC→BC, FM→BM, FP→BP, FA→BA).
|
|
6
|
+
# +message_type+ 에는 친구톡 코드를 그대로 넘기고, 변환은 서버가 처리한다.
|
|
7
|
+
#
|
|
8
|
+
# 친구톡과 달리 채널 친구가 아닌 수신자에게도 보낼 수 있고(+targeting: "N"+),
|
|
9
|
+
# 수신 동의한 전체 채널 친구에게 동보 발송할 수 있다(+targeting: "F"+).
|
|
10
|
+
#
|
|
11
|
+
# @example 단건 발송 — 채널 친구 대상
|
|
12
|
+
# client.brand_message.send(
|
|
13
|
+
# targeting: "M",
|
|
14
|
+
# message_type: "FL",
|
|
15
|
+
# friend_template_uuid: "9cd5460b-6458-4edc-9b11-c26d3013c340",
|
|
16
|
+
# contacts: [{ contact: "01012345678", var1: "29,000원" }]
|
|
17
|
+
# )
|
|
18
|
+
#
|
|
19
|
+
# @example 동보 발송 — 수신 동의한 전체 채널 친구 (contacts 불필요)
|
|
20
|
+
# client.brand_message.broadcast(
|
|
21
|
+
# message_type: "FW",
|
|
22
|
+
# friend_template_uuid: "9cd5460b-6458-4edc-9b11-c26d3013c340"
|
|
23
|
+
# )
|
|
24
|
+
class BrandMessageService
|
|
25
|
+
def initialize(http:, kakao_sender_key:, sms_sender_key:)
|
|
26
|
+
@http = http
|
|
27
|
+
@kakao_sender_key = kakao_sender_key
|
|
28
|
+
@sms_sender_key = sms_sender_key
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# 브랜드메시지를 전송한다.
|
|
32
|
+
#
|
|
33
|
+
# +targeting+ 이 "M"/"N"/"I" 이면 +contacts+ 가 필요하고 응답 data 에
|
|
34
|
+
# 발송 건수(sentCount)가 담긴다. "F" 는 동보 발송이라 +contacts+ 없이
|
|
35
|
+
# 접수 여부(accepted)만 반환되므로, 그 경우 #broadcast 가 더 명확하다.
|
|
36
|
+
#
|
|
37
|
+
# +list+ 는 캐러셀 리스트(BC/BA)이며 요청에는 그대로 list 로 전송된다.
|
|
38
|
+
def send(friend_template_uuid:, message_type: "FT", targeting: "M",
|
|
39
|
+
contacts: nil, content: nil, schedule_type: "DIRECTLY", at: nil,
|
|
40
|
+
buttons: [], image_url: nil, image_link: nil,
|
|
41
|
+
ad_flag: "Y", adult: "N", push_alarm: "Y", header: nil,
|
|
42
|
+
coupon: nil, item: nil, commerce: nil, list: nil,
|
|
43
|
+
head: nil, tail: nil, video: nil, additional_content: nil,
|
|
44
|
+
friend_group_key: nil, replace_sms: "N",
|
|
45
|
+
sms_subject: nil, sms_content: nil,
|
|
46
|
+
reject_service_id: nil, webhooks: [])
|
|
47
|
+
body = {
|
|
48
|
+
at: at,
|
|
49
|
+
scheduleType: schedule_type,
|
|
50
|
+
targeting: targeting,
|
|
51
|
+
messageType: message_type,
|
|
52
|
+
friendTemplateUuid: friend_template_uuid,
|
|
53
|
+
content: content,
|
|
54
|
+
buttons: buttons,
|
|
55
|
+
imageUrl: image_url,
|
|
56
|
+
imageLink: image_link,
|
|
57
|
+
adFlag: ad_flag,
|
|
58
|
+
adult: adult,
|
|
59
|
+
pushAlarm: push_alarm,
|
|
60
|
+
header: header,
|
|
61
|
+
coupon: coupon,
|
|
62
|
+
item: item,
|
|
63
|
+
commerce: commerce,
|
|
64
|
+
list: list,
|
|
65
|
+
head: head,
|
|
66
|
+
tail: tail,
|
|
67
|
+
video: video,
|
|
68
|
+
additionalContent: additional_content,
|
|
69
|
+
friendGroupKey: friend_group_key,
|
|
70
|
+
replaceSms: replace_sms,
|
|
71
|
+
smsSubject: replace_sms == "Y" ? sms_subject : nil,
|
|
72
|
+
smsContent: replace_sms == "Y" ? sms_content : nil,
|
|
73
|
+
rejectServiceId: reject_service_id,
|
|
74
|
+
webhooks: webhooks,
|
|
75
|
+
kakaoSenderKey: @kakao_sender_key,
|
|
76
|
+
senderKey: @sms_sender_key,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# 동보는 수신자 목록이 없다. 빈 배열을 보내면 잘못된 요청으로 거절되므로
|
|
80
|
+
# 키 자체를 넣지 않는다.
|
|
81
|
+
body[:contacts] = contacts || [] unless targeting == "F"
|
|
82
|
+
|
|
83
|
+
@http.post("brand-messages/send", body)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# 동보 발송 — 수신 동의한 전체 채널 친구 (+targeting: "F"+).
|
|
87
|
+
#
|
|
88
|
+
# 수신자 목록은 카카오 측에서 확장하므로 +contacts+ 를 넘기지 않는다.
|
|
89
|
+
# 결과는 #campaigns / #campaign 으로 확인한다.
|
|
90
|
+
def broadcast(**kwargs)
|
|
91
|
+
kwargs.delete(:contacts)
|
|
92
|
+
send(**kwargs, targeting: "F")
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# 브랜드메시지 캠페인 목록을 조회한다.
|
|
96
|
+
def campaigns(from: nil, to: nil, count: nil)
|
|
97
|
+
@http.get("brand-messages", { from: from, to: to, count: count })
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# 브랜드메시지 캠페인 상세를 조회한다.
|
|
101
|
+
# +campaign_id+ 는 발송 응답의 campaignId (UUID).
|
|
102
|
+
def campaign(campaign_id)
|
|
103
|
+
@http.get("brand-messages/#{campaign_id}")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
data/lib/sendgo/client.rb
CHANGED
|
@@ -10,7 +10,8 @@ module Sendgo
|
|
|
10
10
|
# api_version: "v2"
|
|
11
11
|
# )
|
|
12
12
|
class Client
|
|
13
|
-
|
|
13
|
+
# brand_message: 카카오 브랜드메시지 — 친구톡의 후속 채널. v2 전용.
|
|
14
|
+
attr_reader :alimtalk, :friendtalk, :brand_message, :short_url, :sms
|
|
14
15
|
|
|
15
16
|
def initialize(access_key:, secret_key:, kakao_sender_key: nil, sms_sender_key: nil,
|
|
16
17
|
api_version: "v1", base_url: "https://sendgo.io")
|
|
@@ -22,6 +23,9 @@ module Sendgo
|
|
|
22
23
|
|
|
23
24
|
@alimtalk = AlimtalkService.new(http: http, kakao_sender_key: kakao_sender_key, sms_sender_key: sms_sender_key)
|
|
24
25
|
@friendtalk = FriendtalkService.new(http: http, kakao_sender_key: kakao_sender_key, sms_sender_key: sms_sender_key)
|
|
26
|
+
@brand_message = BrandMessageService.new(http: http, kakao_sender_key: kakao_sender_key, sms_sender_key: sms_sender_key)
|
|
27
|
+
# 짧은 URL — 링크 단축과 클릭 반응 분석. v2 전용.
|
|
28
|
+
@short_url = ShortUrlService.new(http: http)
|
|
25
29
|
@sms = SmsService.new(http: http, sms_sender_key: sms_sender_key)
|
|
26
30
|
end
|
|
27
31
|
end
|
data/lib/sendgo/http_client.rb
CHANGED
|
@@ -12,21 +12,46 @@ module Sendgo
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def post(path, body)
|
|
15
|
-
|
|
15
|
+
request(:post, path, body: body, is_retry: false)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# GET 요청. 캠페인 조회 엔드포인트에서 사용한다.
|
|
19
|
+
# params 의 nil 값은 제외되어 서버 기본값이 적용된다.
|
|
20
|
+
def get(path, params = {})
|
|
21
|
+
request(:get, path, params: params, is_retry: false)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# DELETE 요청. 짧은 URL 리다이렉트 중지에서 사용한다.
|
|
25
|
+
def delete(path)
|
|
26
|
+
request(:delete, path, is_retry: false)
|
|
16
27
|
end
|
|
17
28
|
|
|
18
29
|
private
|
|
19
30
|
|
|
20
|
-
def
|
|
21
|
-
token
|
|
22
|
-
url
|
|
23
|
-
uri
|
|
24
|
-
payload = body.to_json
|
|
31
|
+
def request(method, path, body: nil, params: nil, is_retry: false)
|
|
32
|
+
token = @token_manager.get_token
|
|
33
|
+
url = "#{@base_url}/api/#{@api_version}/#{path}"
|
|
34
|
+
uri = URI(url)
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
if params && !params.empty?
|
|
37
|
+
query = params.reject { |_, v| v.nil? }
|
|
38
|
+
uri.query = URI.encode_www_form(query) unless query.empty?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
req =
|
|
42
|
+
case method
|
|
43
|
+
when :get
|
|
44
|
+
Net::HTTP::Get.new(uri)
|
|
45
|
+
when :delete
|
|
46
|
+
# 바디 없는 DELETE. Post 분기로 흘러가면 조용히 POST 로 나간다.
|
|
47
|
+
Net::HTTP::Delete.new(uri)
|
|
48
|
+
else
|
|
49
|
+
Net::HTTP::Post.new(uri).tap do |r|
|
|
50
|
+
r["Content-Type"] = "application/json"
|
|
51
|
+
r.body = body.to_json
|
|
52
|
+
end
|
|
53
|
+
end
|
|
28
54
|
req["Authorization"] = bearer_auth(token)
|
|
29
|
-
req.body = payload
|
|
30
55
|
|
|
31
56
|
resp = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https",
|
|
32
57
|
read_timeout: 15, open_timeout: 10) { |h| h.request(req) }
|
|
@@ -38,7 +63,7 @@ module Sendgo
|
|
|
38
63
|
endpoint = path.split("/").last
|
|
39
64
|
if !is_retry && @token_manager.should_refresh?(resp.code.to_i, error_code)
|
|
40
65
|
@token_manager.invalidate
|
|
41
|
-
return
|
|
66
|
+
return request(method, path, body: body, params: params, is_retry: true)
|
|
42
67
|
end
|
|
43
68
|
raise SendgoError.from_response(resp.code.to_i, resp_body, endpoint, @api_version)
|
|
44
69
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
5
|
+
module Sendgo
|
|
6
|
+
# 짧은 URL — 메시지에 넣는 링크를 줄이고 클릭 반응을 집계한다.
|
|
7
|
+
#
|
|
8
|
+
# v2 전용이다.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# created = client.short_url.create(
|
|
12
|
+
# target_url: "https://example.com/promotions/summer-sale",
|
|
13
|
+
# title: "여름 세일 랜딩"
|
|
14
|
+
# )
|
|
15
|
+
#
|
|
16
|
+
# # created.dig("data", "shortUrl") 를 문자/알림톡 본문에 넣는다.
|
|
17
|
+
# stats = client.short_url.stats(created.dig("data", "code"))
|
|
18
|
+
class ShortUrlService
|
|
19
|
+
def initialize(http:)
|
|
20
|
+
@http = http
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# 짧은 URL 을 만든다.
|
|
24
|
+
#
|
|
25
|
+
# 같은 원본 URL 을 다시 줄이면 기존 링크가 그대로 반환된다.
|
|
26
|
+
# 캠페인별로 반응을 분리해 집계하려면 +force_new: true+ 를 쓴다.
|
|
27
|
+
def create(target_url:, title: nil, expires_at: nil, force_new: false)
|
|
28
|
+
body = { targetUrl: target_url, forceNew: force_new }
|
|
29
|
+
body[:title] = title unless title.nil?
|
|
30
|
+
body[:expiresAt] = expires_at unless expires_at.nil?
|
|
31
|
+
|
|
32
|
+
@http.post("short-urls", body)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# 목록 조회.
|
|
36
|
+
def list(from: nil, to: nil, count: nil)
|
|
37
|
+
@http.get("short-urls", { from: from, to: to, count: count })
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# 상세 조회.
|
|
41
|
+
def show(code)
|
|
42
|
+
@http.get("short-urls/#{escape(code)}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# 반응 통계. 일별 추이와 디바이스/유입경로/국가별 분해를 반환한다.
|
|
46
|
+
def stats(code, from: nil, to: nil)
|
|
47
|
+
@http.get("short-urls/#{escape(code)}/stats", { from: from, to: to })
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# 리다이렉트를 중지한다. 링크는 삭제되지 않고 누적 통계도 남는다.
|
|
51
|
+
# 이후 그 링크로 들어오면 410 Gone 이 반환된다.
|
|
52
|
+
def deactivate(code)
|
|
53
|
+
@http.delete("short-urls/#{escape(code)}")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def escape(code)
|
|
59
|
+
CGI.escape(code.to_s)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/sendgo/version.rb
CHANGED
data/lib/sendgo.rb
CHANGED
|
@@ -4,6 +4,8 @@ require_relative "sendgo/token_manager"
|
|
|
4
4
|
require_relative "sendgo/http_client"
|
|
5
5
|
require_relative "sendgo/alimtalk"
|
|
6
6
|
require_relative "sendgo/friendtalk"
|
|
7
|
+
require_relative "sendgo/brand_message"
|
|
8
|
+
require_relative "sendgo/short_url"
|
|
7
9
|
require_relative "sendgo/sms"
|
|
8
10
|
require_relative "sendgo/client"
|
|
9
11
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sendgo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sendgo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Sendgo API를 Ruby에서 간편하게 사용하기 위한 공식 SDK
|
|
14
14
|
email:
|
|
@@ -20,10 +20,12 @@ files:
|
|
|
20
20
|
- README.md
|
|
21
21
|
- lib/sendgo.rb
|
|
22
22
|
- lib/sendgo/alimtalk.rb
|
|
23
|
+
- lib/sendgo/brand_message.rb
|
|
23
24
|
- lib/sendgo/client.rb
|
|
24
25
|
- lib/sendgo/error.rb
|
|
25
26
|
- lib/sendgo/friendtalk.rb
|
|
26
27
|
- lib/sendgo/http_client.rb
|
|
28
|
+
- lib/sendgo/short_url.rb
|
|
27
29
|
- lib/sendgo/sms.rb
|
|
28
30
|
- lib/sendgo/token_manager.rb
|
|
29
31
|
- lib/sendgo/version.rb
|