# kakao-chatbot-templates

> For It is a package to use Kakao OpenBuilder's skill template more easily.

Latest version **0.3.2** (published 2021-03-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install kakao-chatbot-templates
pnpm add kakao-chatbot-templates
yarn add kakao-chatbot-templates
bun add kakao-chatbot-templates
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2021-03-31 |
| First published | 2021-01-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 53 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | jhkang |
| Maintainers | jhkang |
| Keywords | kakao-chatbot |

## Links

- npm: https://www.npmjs.com/package/kakao-chatbot-templates
- Repository: https://github.com/liam-kor/kakao-chatbot-templates
- Homepage: https://github.com/liam-kor/kakao-chatbot-templates#readme
- Issues: https://github.com/liam-kor/kakao-chatbot-templates/issues
- npm.io page: https://npm.io/package/kakao-chatbot-templates

## Dependencies (3)

- [pupa](https://npm.io/package/pupa.md) ^2.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.167

## Recent versions

- 0.3.2 (latest) — 2021-03-31
- 0.3.1 — 2021-03-29
- 0.3.0 — 2021-03-23
- 0.2.9 — 2021-03-18
- 0.2.8 — 2021-03-17
- 0.2.7 — 2021-03-15
- 0.2.6 — 2021-03-15
- 0.2.5 — 2021-03-15
- 0.2.4 — 2021-03-12
- 0.2.3 — 2021-03-11
- 0.2.2 — 2021-03-09
- 0.2.1 — 2021-03-05
- 0.2.0 — 2021-03-05
- 0.1.23 — 2021-03-04
- 0.1.22 — 2021-03-04
- … 28 more at https://npm.io/package/kakao-chatbot-templates/versions

## README

## Install

```
$ yarn add kakao-chatbot-templates
```

## Usage

###### SimpleText

```js
import { SimpleText, SkillResponse, Template } from 'kakao-chatbot-templates';
const template = new Template([
  new SimpleText('Hello world!')
]);
const skillResponse = new SkillResponse(template)).render();
console.log(template);
```
```bash
{
  "version": "2.0",
  "template": {
    "outputs": [
      {
        "simpleText": {
          "text": "Hello world!"
        }
      }
    ]
  }
}
```

###### SimpleImage

```js
import { SimpleImage, SkillResponse, Template } from 'kakao-chatbot-templates';
const template = new Template([
  new SimpleImage('https://www.example.com/image.jpg', 'altText'),
]);
const skillResponse = new SkillResponse(template)).render();
console.log(template);
```
```bash
{
  "version": "2.0",
  "template": {
    "outputs": [
      {
        "simpleImage": {
          "imageUrl": "https://www.example.com/image.jpg",
          "altText": "altText"
        }
      }
    ]
  }
}
```

##### BasicCard
**Precautions**
When creating Button and QuickReply, if you need to put data in the extra field as needed, <U>it is recommended that you use a key other than the 'data' field name.</U> When inserted within a data field, the field is overwritten if there is data entered in the parent component.
```js
import { BasicCard, SimpleThumbnail, Button, WebLinkButton, QuickReply, SkillResponse, Template } from 'kakao-chatbot-templates';
const template = new Template([
  new BasicCard(
    {
      description: '상품명 : {productName}',
      thumbnail: new SimpleThumbnail('{productImageUrl}'),
      buttons: [
        new WebLinkButton('구매하러 가기', '{productUrl}'),
        new Button({
          label: '상담원 연결',
          action: 'block',
          messageText: '상담원 연결',
          blockId: 'KakaoOpenbuilderBlockId',
        }),
      ],
    },
    {
      productName: '샘플 상품',
      productUrl: 'https://www.example.com/image.jpg',
      productImageUrl: 'https://www.example.com/image.jpg',
    },
  ),
],
[
  new QuickReply()
]);
const skillResponse = new SkillResponse(template)).render();
console.log(template);
```
```bash
{
  "version": "2.0",
  "template": {
    "outputs": [
      {
        "basicCard": {
          "description": "상품명 : 샘플 상품",
          "thumbnail": {
            "imageUrl": "https://www.example.com/image.jpg"
          },
          "buttons": [
            {
              "label": "구매하러 가기",
              "action": "webLink",
              "webLinkUrl": "https://www.example.com/image.jpg",
              "extra": {
                "data": {
                  "productName": "샘플 상품",
                  "productUrl": "https://www.example.com/image.jpg",
                  "productImageUrl": "https://www.example.com/image.jpg"
                }
              }
            },
            {
              "label": "상담원 연결",
              "action": "block",
              "messageText": "상담원 연결",
              "blockId": "KakaoOpenbuilderBlockId",
              "extra": {
                "data": {
                  "productName": "샘플 상품",
                  "productUrl": "https://www.example.com/image.jpg",
                  "productImageUrl": "https://www.example.com/image.jpg"
                }
              }
            }
          ]
        }
      }
    ],
    "quickReplies": [
      {
        "label": "처음으로",
        "action": "block",
        "blockId": "KakaoOpenbuilderBlockId",
        "extra": {}
      }
    ]
  }
}
```


###### Carousel

```js
import { CarouselWithData, BasicCard, SimpleThumbnail, Button, WebLinkButton, QuickReply, SkillResponse, Template } from 'kakao-chatbot-templates';

const cardFormat = new BasicCard({
  description: '상품명 : {productName}',
  thumbnail: new SimpleThumbnail('{productImageUrl}'),
  buttons: [
    new WebLinkButton('구매하러 가기', '{productUrl}'),
    new Button({
      label: '상담원 연결',
      action: 'block',
      messageText: '상담원 연결',
      blockId: 'KakaoOpenbuilderBlockId',
    }),
  ],
});

const products = [
  {
    productName: '샘플상품1',
    productImageUrl: '샘플이미지1',
    productUrl: '샘플링크1',
  },
  {
    productName: '샘플상품2',
    productImageUrl: '샘플이미지2',
    productUrl: '샘플링크2',
  },
];

const template = new Template([new CarouselWithData(cardFormat, products)]);
const skillResponse = new SkillResponse(template)).render();
console.log(template);
```
```bash
{
  "version": "2.0",
  "template": {
    "outputs": [
      {
        "carousel": {
          "type": "basicCard",
          "items": [
            {
              "description": "상품명 : 샘플상품1",
              "thumbnail": {
                "imageUrl": "샘플이미지1"
              },
              "buttons": [
                {
                  "label": "구매하러 가기",
                  "action": "webLink",
                  "webLinkUrl": "샘플링크1",
                  "extra": {
                    "data": {
                      "productName": "샘플상품1",
                      "productImageUrl": "샘플이미지1",
                      "productUrl": "샘플링크1"
                    }
                  }
                },
                {
                  "label": "상담원 연결",
                  "action": "block",
                  "messageText": "상담원 연결",
                  "blockId": "KakaoOpenbuilderBlockId",
                  "extra": {
                    "data": {
                      "productName": "샘플상품1",
                      "productImageUrl": "샘플이미지1",
                      "productUrl": "샘플링크1"
                    }
                  }
                }
              ]
            },
            {
              "description": "상품명 : 샘플상품2",
              "thumbnail": {
                "imageUrl": "샘플이미지2"
              },
              "buttons": [
                {
                  "label": "구매하러 가기",
                  "action": "webLink",
                  "webLinkUrl": "샘플링크2",
                  "extra": {
                    "data": {
                      "productName": "샘플상품2",
                      "productImageUrl": "샘플이미지2",
                      "productUrl": "샘플링크2"
                    }
                  }
                },
                {
                  "label": "상담원 연결",
                  "action": "block",
                  "messageText": "상담원 연결",
                  "blockId": "KakaoOpenbuilderBlockId",
                  "extra": {
                    "data": {
                      "productName": "샘플상품2",
                      "productImageUrl": "샘플이미지2",
                      "productUrl": "샘플링크2"
                    }
                  }
                }
              ]
            }
          ]
        }
      }
    ]
  }
}
```

---
_Source: https://npm.io/package/kakao-chatbot-templates · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
