์นด์นด์ค ์คํ๋น๋ ์คํฌ์๋ต JSON๋น๋
https://i.kakao.com/docs/skill-response-format#skillresponse
์นด์นด์ค ์คํ๋น๋์ Json ํ์ ์คํฌ์๋ต์ ๋ณด๋ค ์ฝ๊ฒ ๋ง๋ค์ ์๊ฒ ์ ๊ณต๋๋ SDK ์ ๋๋ค.
Background
์นด์นด์ค ์คํ๋น๋๋ฅผ ์ฌ์ฉํ๋ฉด์ ์ข ๋ ์ ๊ตํ ์๋ต์ ์ํด ์ฌ์ฉ์๊ฐ ์คํฌ ์๋ฒ๋ฅผ ์ง์ ๋ง๋ค์ด์ผ ํ ๋๊ฐ ์๋ค. ์ฌ์ฉ์๋ Json ์๋ต์ ๋ง๋ค๊ฒ ๋๋๋ฐ ๋งค์ฐ ๊ท์ฐฎ์ ํธ์ด๋ค. ์ด๋ฅผ ์ข ๋ ํธํ๊ฒ ๋ง๋ค ์ ์๊ฒ SDK๋ฅผ ๋ง๋ค๊ณ ์ถ์๋ค.
Usage
com.github.myabcc17.SkillResponseV2Builder builder = new com.github.myabcc17.SkillResponseV2Builder();
builder.addComponent(Component); // max Component is 3
builder.addQuickReply(QuickReply); // max QuickReply is 10
builder.addContext(ContextValue);
builder.addData(String, Object);
...
...
builder.build() // return json string (SkillResponse)
Components
์์ธํ ์คํ ์ฌํญ์ ํํ์ด์ง ๋์๋ง์๋ ๋์์์ผ๋ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค..
ํฐํธ ํจ๊ณผ: ํ์ ํ๋ผ๋ฏธํฐ, ์ ์ฝ ์ฌํญ
- SimpleText
- text (String)
- SimpleImage
- imageUrl (String)
- altText (String)
- BasicCard
- title (String)
- description (String) - max length is 230
- thumbnail (String)
- profile (Profile) - not supported
- social (Social) - not supported
- button (List<Button>) - max button is 3
- ListCard
- header (ListItem)
- items (List<ListItem>) - max item is 5
- buttons (List<Button>) - max button is 2
- CommerceCard
- description (String) - max length is 230
- currency (String)
- price (int)
- discount (int)
- discountRate (int)
- discountedPrice (int)
- buttons (List<Button>) - 1 <= button.size <= 3
- thumbnails (List<Thumbnail>) - only one element
- profile (Profile) - not supported
- Carousel
- type (String) - one of ["basicCard", "commerceCard"]
- items (List<CarouselItem>) - max item is 10
- carouselHeader (CarouselHeader)
Common Component
- Button
- label (String) - max length is 14
-
action (String) - one of ["webLink", "message", "block", "phone", "share", "operator"]
- but, "operator" is not supported yet.
- webLinkUrl (String) - needed when action is "webLink" or "block"
- messageText (String) - needed when action is "message"
- phoneNumber (String) - needed when action is "phone"
- blockId (String) - needed when action is "block"
- extra (Map<String, Object>)
- CarouselHeader
- title (String)
- description (String)
- thumbnail (Thumbnail)
- Thumbnail
- imageUrl (String)
- link (Link)
- fixedRatio (boolean)
- width (int) - needed when fixedRatio is true
- height (int) - needed when fixedRatio is true
- Link
- pc (String)
- mobile (String)
- web (String)
- ListItem
- title (String)
- description (String)
- imageUrl (String)
- link (Link)
Other Component
- QuickReply
- label (String)
- action (String) - one of ["message", "block"]
- messageText (String) - needed when action is message
- blockId (String) - needed when action is block
- extra (Map<String, Object>)
- ContextValue
- name (String)
- lifeSpan (int)
- params (Map<String, String>)
Example
- BasicCard Example
-
of
๋ก ์์ฑํ๋ ๊ฒฝ์ฐ, ํ์ ์ธ์๊ฐ ๋ฐ๋์ ํฌํจ๋์ด์ผ ํ๋ค. -
builder()
๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑํ๋ ๊ฒฝ์ฐ๋ ํ์ ์ธ์๊ฐ ๋ฐ๋์ ํฌํจ๋์ด์ผ ํ๋ค.- ํ์๊ฐ ์๋ ๊ฐ๋ค์ ์ํ๋ ๋๋ก ๋ฃ์ ํ
build()
๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ Component๋ฅผ ์์ฑํ๋ค.
- ํ์๊ฐ ์๋ ๊ฐ๋ค์ ์ํ๋ ๋๋ก ๋ฃ์ ํ
-
Thumbnail thumbnail = Thumbnail.builder("http://sampleimage.com")
.fixedRatio(true)
.width(2)
.height(1)
.build();
BasicCard basicCard1 = BasicCard.of(thumbnail); // BasicCard (only have thumbnail)
BasicCard basicCard2 = BasicCard.builder(thumbnail)
.title("title")
.description("sample okay?")
.build();
builder.addComponent(basicCard1);
builder.addComponent(basicCard2);
System.out.println(builder.build()); // return json string
- Button Example
- action ๊ฐ์ ๋ฐ๋ผ ํ์ ํ๋๊ฐ ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์
builder()
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅ -
QuickReply
,Thumbnail
๋ ๋ง์ฐฌ๊ฐ์ง
- action ๊ฐ์ ๋ฐ๋ผ ํ์ ํ๋๊ฐ ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์
Button button1 = Button.of("sample label", "phone", null, null, "010-1234-1234", null, null);
Button button2 = Button.builder("sample label", "phone")
.phoneNumber("010-4567-4567")
.build();