Skip to content

Pesan Draft (Bot API 9.5)

APIsendMessageDraft

Pesan draft

SinceBot API 9.5
ReturnsHasil draft message
Pesan draft mengisi input pengguna dan cocok untuk reply terbimbing, teks berbantuan AI, dan flow completion.

Pesan draft mengisi kolom input pengguna dengan teks tertentu. Berguna untuk auto-complete, saran input terbimbing, dan streaming teks AI.

Penggunaan

typescript
bot.command('draft', async ctx => {
    await ctx.replyWithDraft('Teks ini muncul di kolom input Anda...');
});

Kasus Penggunaan

Template Input Terbimbing

typescript
bot.command('pesan', async ctx => {
    // Pra-isi format perintah
    await ctx.replyWithDraft('/kirim [nama_produk] [jumlah] [alamat]');
});

bot.command('laporan', async ctx => {
    await ctx.replyWithDraft('/laporan_bug [judul] [deskripsi] [langkah_reproduksi]');
});

Streaming Teks AI

typescript
bot.command('ai', async ctx => {
    const prompt = ctx.command?.args?.join(' ') || '';

    if (!prompt) {
        return ctx.reply('Masukkan pertanyaan setelah /ai');
    }

    // Stream respons AI sebagai draft (pengguna melihatnya bertahap)
    for await (const chunk of aiStream(prompt)) {
        await ctx.replyWithDraft(chunk);
    }

    // Kirim respons final sebagai pesan
    const responFinal = await aiComplete(prompt);
    await ctx.reply(responFinal);
});

Auto-Complete Form

typescript
bot.command('checkout', async ctx => {
    // Pra-isi format pemesanan
    await ctx.replyWithDraft('nama: | jumlah: | kota: ');
});

API

MetodeAPI TelegramDeskripsi
ctx.replyWithDraft(text, extra?)sendMessageDraftPra-isi kolom input pengguna

Keamanan ID

Draft message menggunakan crypto.randomBytes(8) untuk menghasilkan ID 64-bit yang aman, mencegah tabrakan bahkan di konkurensi tinggi.

Streaming AI

Untuk streaming AI, kirim replyWithDraft setiap potongan teks, lalu tutup dengan ctx.reply untuk pesan final yang tetap di riwayat chat.

Released under the ISC License.