Instalasi
- Runtime
- Node.js 18+
- Output
- CJS + ESM
- Types
- Strict TS
Sesuai engines package
Aman untuk setup Node modern
Deklarasi tipe tersedia
Install package
npm install vibegram| Feature | Support | CJS | ESM | Node | Notes |
|---|---|---|---|---|---|
| Runtime | Node.js 18+ | yes | yes | 18, 20, 22 | Matches package engines. |
| Module output | Dual package | dist/cjs | dist/esm | 18+ | Types are emitted under dist/types. |
| Docs deployment | Static | - | - | 18+ | Safe for GitHub Pages. |
Jaga secret tetap di luar repository
Install package di project aplikasi Anda, lalu baca token bot dari environment variable. Jangan commit file `.env` atau token Telegram asli.
Prasyarat
- Node.js v18.0 atau lebih baru
- npm atau yarn
- Token bot Telegram dari BotFather
Cek versi Node.js:
bash
node --versionInstall
bash
npm install vibegramAtau dengan yarn:
bash
yarn add vibegramSetup TypeScript
VibeGram ditulis dengan TypeScript dan sudah membawa deklarasi tipe. Tidak perlu package @types tambahan untuk VibeGram.
Untuk project TypeScript baru:
bash
mkdir my-bot && cd my-bot
npm init -y
npm install vibegram
npm install -D typescript ts-node @types/node
npx tsc --inittsconfig.json yang direkomendasikan:
json
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"]
}Token Environment
Buat bot lewat @BotFather di Telegram, lalu simpan token di environment runtime:
bash
BOT_TOKEN=1234567890:ganti-tokenUntuk memuat .env lokal:
bash
npm install dotenvtypescript
import 'dotenv/config';Bot Pertama
Buat src/index.ts:
typescript
import 'dotenv/config';
import { Bot } from 'vibegram';
const token = process.env.BOT_TOKEN;
if (!token) {
throw new Error('BOT_TOKEN wajib diisi');
}
const bot = new Bot(token);
bot.start(async ctx => {
const name = ctx.from?.first_name ?? 'teman';
await ctx.reply(`Halo ${name}. Selamat datang di bot.`);
});
bot.hears(/halo|hai/i, ctx => ctx.reply('Halo. Ada yang bisa saya bantu?'));
await bot.launch();Jalankan:
bash
npx ts-node src/index.tsStruktur Project
Project VibeGram untuk produksi biasanya dimulai seperti ini:
text
my-bot/
src/
index.ts
handlers/
commands.ts
actions.ts
middlewares/
auth.ts
scenes/
checkout.ts
.env
package.json
tsconfig.jsonVerifikasi Instalasi
Kirim /start ke bot Anda di Telegram. Jika bot membalas, instalasi package, loading token, dan polling sudah berjalan.
Langkah Selanjutnya
- Instansi Bot & Polling - konfigurasi opsi launch.
- Pipeline Middleware - pahami urutan middleware.
- Session - simpan state per-user atau per-chat.