0.1.6 • Published 1 year ago

telegramthread v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Install

npm install telegramthread

Usage

Create a new bot

const { Bot } = require('telegramthread');

// You can use process.env.TELEGRAM_BOT_TOKEN or pass { token } to the constructor
const bot = new Bot();

bot.start();

console.log('Bot started!');

Create a new thread

async function thread (chat, photoMessage, getNextMessage) {
    // Send a message to the user to send a caption for the photo
    await chat.sendText('Send caption for the photo');
    // Get the next message from the user
    const captionMessage = await getNextMessage();
    // Send the photo with the caption
    await chat.sendPhoto(photoMessage.getFileId(), {
        caption: captionMessage.text
    });
}

Handle the thread and messages

bot.onMessage(async (message, chat) => {

    // default start message. We will inform the user to send a photo
    if (message.is('/start')) {
        await chat.sendText('Hello! Send a photo!');
    }
    
    // If the user sent a photo then start the "thread" from message
    else if (message.isPhoto()) {
        await chat.startThread(thread);
    }

    // If there is no thread, then the user sent a photo without a command
    else if (!chat.thread) {
        await chat.sendText('Send a photo!');
    }
    
});
0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago