1.5.2 • Published 1 year ago

@tlgr/analytics v1.5.2

Weekly downloads
-
License
Apache 2.0
Repository
-
Last release
1 year ago

Analytics

Telegram Component which allows you to collect any events with bot.

Installation

PNPm

pnpm add @tlgr/analytics

Supported plugins

  • Console
  • File
  • Stream

Writing own plugins

  1. import plugin:
// filename: custom-plugin.ts
import type { Plugin } from '@tlgr/analytics/plugins';

class MyPlugin implements Plugin {
  name = 'custom plugin';

  constructor(){
    http.initSession();
  }

  listener(event: string, param: any) {
    console.log(event, param);
    if(event === 'my custom event') {
      http.post('http://server.com', param)
    }
  }
  end(){
    http.closeSession();
  }
}
  1. use custom plugin in your code
import { Telegraf } from 'telegraf';
import Analytics from './analytics';

import {MyPlugin} from './custom-plugin';

const TOKEN = '';
const bot = new Telegraf(TOKEN);

const analytics = new Analytics(bot, new MyPlugin());

bot.start(ctx => {
  // sends hello world when user sends "/start" command
  bot.telegram.sendMessage(ctx.chat.id, 'Hello world');
});

analytics.enable(true);

API

enable(launchImmediate) - enable analytics, if launchImmediate is true - also starts bot, similar as bot.launch()

disable(stopImmediate) - stops bot, if stopImmediate is true - also starts bot, similar as bot.close()

1.5.2

1 year ago

1.4.4

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago