com.github.myabcc17:chatbot-response-v2-builder

Build kakao openbuilder skill response(v2) easily


Licenses
Apache-2.0/libpng-2.0

Documentation

์นด์นด์˜ค ์˜คํ”ˆ๋นŒ๋” ์Šคํ‚ฌ์‘๋‹ต 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 ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€
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();

Component Structure