s
Size: a a a
s
s
D
D
D
s
s
И
И
s
И
D
class VkCarouselTemplate {
constructor() {
this._elements = [];
}
addSlide(photoId, buttons) {
if (photoId === undefined) throw new Error("Photo id should be specified");
if (buttons && buttons.currentRow?.length > 2)
throw new Error("Invalid buttons format");
if (this._elements.length > 9)
throw new Error("Maximum elements count reached");
this._elements.push({
photo_id: photoId,
action: {
type: "open_photo"
},
buttons: buttons?.currentRow
});
return this;
}
toJSON() {
return {
type: "carousel",
elements: this._elements
};
}
toString() {
return JSON.stringify(this.toJSON());
}
}
const template = new VkCarouselTemplate()
.addSlide(1, { currentRow: [1, 2] })
.addSlide(1, { currentRow: [1, 2] });
console.log(JSON.stringify(template), template.toJSON());
SP
ei
s
s