2.1.7 • Published 4 months ago

nk-ntba v2.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Bot authorization:

const Bot = require('nk-ntba');

let bot = new Bot('API token of your bot');

Events for listening updates:

message
edited_message
channel_post
edited_channel_post
inline_query
chosen_inline_result
callback_query
shipping_query
pre_checkout_query
poll
poll_answer
my_chat_member
chat_member
chat_join_request
reply_to_message

For specific types of messages:

text
animation
audio
channel_chat_created
contact
delete_chat_photo
dice
document
game
group_chat_created
invoice
left_chat_member
location
migrate_from_chat_id
migrate_to_chat_id
new_chat_member
new_chat_photo
new_chat_title
passport_data
photo
pinned_message
poll
sticker
successful_payment
supergroup_chat_created
video
video_note
voice
voice_chat_started
voice_chat_ended
voice_chat_participants_invited
voice_chat_scheduled
message_auto_delete_timer_changed
chat_invite_link
chat_member_updated

To use specific types of messages in listener you should write event with prefix message. , for example message.text.

Adding a listener to some event:

bot.setCallback('your event', callback);

Removing a listener:

bot.removeCallback('your event');

Starting listener:

bot.start({
    short_polling: 500
});

or

bot.start({
    long_polling: 60
});

About polling

Webhookes are not available yet.

Stoping listener:

bot.stop();

Downloading file by file_id:

const fs = require('fs');
const Bot = require('nk-ntba');

let bot = new Bot('API token of your bot');

(async () => {

    await bot.downloadFile('your file_id', fs.createWriteStream('your file'));
    
})();

All other methods are async and need await or .then constructions (.catch is not used, promise is always resolved). You can check available methods in source code of this library.

Example of echo bot:

const Bot = require('nk-ntba');

let bot = new Bot('API token of your bot');

bot.setCallback('message.text', async (msg) => {

    let cid = msg.chat.id;
    let msgid = msg.message_id;
    let tx = msg.text;

    let r = await bot.sendMessage(cid, `You sent: ${tx}`);

    setTimeout(() => {

        bot.deleteMessage(cid, msgid);
        bot.deleteMessage(cid, r.message_id);

        bot.sendMessage(cid, `Messages were deleted after 5 sec`);

    }, 5000);

});

bot.listen({
    long_polling: 300
});
2.1.7

4 months ago

2.1.2

11 months ago

2.1.1

11 months ago

2.1.4

11 months ago

2.1.3

11 months ago

2.1.6

11 months ago

2.1.5

11 months ago

2.1.0

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.1.5

2 years ago

1.0.6

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago