Carousel
This component like "scrollable" inline component
Installation
PNPm
pnpm add @tlgr/carousel
yarn
yarn add @tlgr/carousel
npm
npm i @tlgr/carousel
Example
example.ts
import { Carousel } from "@tlgr/carousel";
import { Telegraf } from "telegraf";
const TOKEN = "<PASTE API TOKEN HERE>";
const bot = new Telegraf(TOKEN);
const cats: string[] = [
"https://snapshot.canon-asia.com/vn/article/eng/3-ideas-for-cute-cat-photos",
"https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2",
]; // or it can be a text
const carousel1 = new Carousel(bot, {
items: cats,
type: "photo",
loop: true, // starts again when carousel is end.
});
carousel1.on("next", (ctx, instance) => {
console.log(`render photo: ${instance.item}`);
});
carousel1.on("prev", (ctx, instance) => {
console.log(`render photo: ${instance.item}`);
});
bot.start((ctx) => {
carousel1.send(ctx);
});
bot.launch();
carousel.text.ts
import { Carousel } from "@tlgr/carousel";
import { Telegraf } from "telegraf";
const TOKEN = "<PASTE API TOKEN HERE>";
const bot = new Telegraf(TOKEN);
const texts = ["Long text", "text 1", "text 2"];
const carousel1 = new Carousel(bot, {
items: texts,
type: "message", // message - sends text message
loop: true, // starts again when carousel is end.
});
carousel1.on("next", (ctx, instance) => {
console.log(`render text: ${instance.item}`);
});
carousel1.on("prev", (ctx, instance) => {
console.log(`render text: ${instance.item}`);
});
bot.start((ctx) => {
carousel1.send(ctx);
});
bot.launch();
Demo
Example:
Text carousel: