Skip to content

Commit 2c0b593

Browse files
committed
add carousel maker
1 parent d90d0d9 commit 2c0b593

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ By default, webhook will listen on port `5463`. You should change it if it inter
140140

141141
- `.addSticker({packageId, stickerId})` // both params are of number type. see https://devdocs.line.me/files/sticker_list.pdf
142142

143-
- `.addButtons({thumbnailImageUrl, altText, title, text, actions})` // Buttons template message. `actions` must follow Action template. length of `actions` <=4
143+
- `.addButtons({thumbnailImageUrl, altText, title, text, actions})` // Buttons template message. `actions` is an array of [`action` objects](https://devdocs.line.me/en/#template-action). length of `actions` <=4
144144

145-
- `.addConfirm({altText, text, actions})` // confirmation type. actions max length = 2
145+
- `.addConfirm({altText, text, actions})` // confirmation type. `actions` max length = 2
146+
147+
- `.addCarousel({altText, columns})` // where `columns` is an array of [`column` object](https://devdocs.line.me/en/#column-object). Column object is in the shape of `{thumbnailImageUrl, title, text, actions}`. `actions` is an array of [`action` objects](https://devdocs.line.me/en/#template-action).
146148

147149
- `.addVideo, etc` (WIP)
148150

src/messages.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,34 @@ class Messages {
181181
return this
182182
}
183183

184+
addCarousel ({altText, columns}) {
185+
if (!altText) {
186+
console.error('altText must not be empty.')
187+
return this
188+
}
189+
if (this._payload.length >= 5) {
190+
console.error('Maximum payload length is 5.')
191+
return this
192+
}
193+
194+
this._payload.push({
195+
type: 'template',
196+
altText,
197+
template: {
198+
type: 'carousel',
199+
columns: columns.slice(0, 4).map(({thumbnailImageUrl, title, text, actions}) => {
200+
return ({
201+
thumbnailImageUrl,
202+
title,
203+
text,
204+
actions
205+
})
206+
})
207+
}
208+
})
209+
return this
210+
}
211+
184212
commit () {
185213
return this._payload
186214
}

0 commit comments

Comments
 (0)