telegram-bot-mark-loku

1.0.7 • Public • Published

telegram-bot-mark-loku

Install

1 - Create a new JavaScript file in your project directory. You can name it something like bot.js.

2 - Open the bot.js file in a code editor of your choice.

Uses

3 - Begin by requiring the npm i telegram-bot-loku package at the top of your file:

#CODE: 

    const TelegramBot = require('telegram-bot-loku');

4 - Initialize the bot by passing your API token and enabling the polling option. This allows the bot to listen for and receive new messages:

#CODE: 

    const token = 'YOUR_TELEGRAM_BOT_TOKEN'; // Replace with your own bot token
    const channel = 'YOUR_TELEGRAM_BOT_CHANNEL'; // Replace with your own bot channel
    const message = 'Hi Everyone'; // Replace with your message

    async function sendMessage() {
        try {
            const telegramResponse = await telegramInstance.sendMessage("token", "channel", "Hi");
            console.log(telegramResponse);
            return telegramResponse;
        } catch (error) {
            console.error('Error:', error);
            throw error; // Re-throw the error if necessary
        }
    }

5 - Add an event listener to handle incoming messages. This listener will be triggered whenever a user sends a message to your bot:

#CODE: 

    sendMessage()
    .then(response => {
        console.log('Success:', response);
    })
    .catch(error => {
        console.error('Error:', error);
    });

By following the previous steps, your bot.js file will look like this:

#CODE: 

    const telegramInstance = require('telegram-bot-loku')

    const token = 'YOUR_TELEGRAM_BOT_TOKEN'; // Replace with your own bot token
    const channel = 'YOUR_TELEGRAM_BOT_CHANNEL'; // Replace with your own bot channel
    const message = 'Hi Everyone'; // Replace with your message

    async function sendMessage(token,channel,message) {
        try {
            const telegramResponse = await telegramInstance.sendMessage(token, channel, message);
            console.log(telegramResponse);
            return telegramResponse;
        } catch (error) {
            console.error('Error:', error);
            throw error; // Re-throw the error if necessary
        }
    }

    sendMessage().catch(error => {
        console.error('Error:', error);
    });

Running the Bot

1 - Open a terminal or command prompt and navigate to your project directory.

2 - Run the command node bot.js to start the bot. You should see a message indicating that the bot is running and waiting for incoming messages.

3 - Switch to the Telegram app on your device and find your bot by its username or display name.

4 - Send a message to your bot and observe its response. If you implemented the /start command, you should receive a welcome message.

Readme

Keywords

none

Package Sidebar

Install

npm i telegram-bot-mark-loku

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

5.51 kB

Total Files

3

Last publish

Collaborators

  • lokudeveloper