0.1.12 • Published 1 year ago

@alximicus/simple-node-telegram-bot v0.1.12

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Simple node telegram bot

Simple, well-typed and easy to use package which allow you to create Telegram bots.

Currently, bot using pooling for receiving updates. Webhook will be added later.

Motivation

To have a simple, easy supported and kept updated package for creating telegram bots.

Usage

Create the bot instance:

import { ATelegram } from '@alximicus/simple-node-telegram-bot';

const bot = new ATelegram('your_bot_token');

// ...

Regexp subscriptions (searching match inside text message):

// ...

bot.onText(/\/hello/, (update, api) => {
  api.sendMessage({
    chat_id: update.message.from.id,
    text: 'Hello, my friend!',
  });
});

// ...

Commands subscriptions (searching text commands inside entities array):

// ...

const enum MyBotCommands {
  Subscribe = '/subscribe',
  Unsubscribe = '/unsubscribe',
  Start = '/start',
}

bot.onCommand(MyBotCommands.Subscribe, (update, api) => {
  // subscription code

  api.sendMessage({
    chat_id: update.message.from.id,
    text: 'You successfully subscribed to news!'
  });
});

// ...

or you can subscribe on any update:

// ...

bot.update$.subscribe({
  next: (update) => {
    // now you have access to every update
    console.log(update);
  }
})

// ...

To be continued...

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago