1.0.2 • Published 4 years ago

tgairbot v1.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

#TgAirBot

This is a library for creating progressive bots for Telegram. Based on the principle of MVS (Model, View, Service).

Uses TypeScript and in particular the extensive system of decorators.

####Work has just begun!!! ##Install

npm install tgairbot

##Install dependencies

npm i node-telegram-bot-api @types/node-telegram-bot-api
npm i @types/color colors
npm i dotenv 

##Using

    you project dir
    |
    +--dist (generated folder by typescript)
    | 
    +--node_modules
    | 
    +--src (folder for your bot)
    |  |
    |  |
    |  +--...folders module
    |  |
    |  +--you module folder
    |  |  |
    |  |  +-- *.module.ts (module file)
    |  |  |
    |  |  +-- *.view.ts (view file)
    |  |  |
    |  |  +-- *.service.ts (service file)
    |  |
    |  +--main.ts (input file)
    |
    +--.env
    |
    +--package.json
    |
    +--tsconfig.json
  • ###tsconfig.ts
{
    "compilerOptions": {
        "target": "es6",  
        "module": "commonjs",
        "outDir": "./dist",   
        "rootDir": "./src",   
        "strict": true,                          
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true, 
        "skipLibCheck": true,           
        "forceConsistentCasingInFileNames": true
    }
}
  • ###package.json
{
  ..., 

  "scripts": {
    "start": "node ./dist/main.js",
    "start:dev": "tsc && npm run start"
  },

  ...,

  "dependencies": {
    "@types/color": "^3.0.1",
    "@types/node-telegram-bot-api": "^0.50.2",
    "colors": "^1.4.0",
    "dotenv": "^8.2.0",
    "node-telegram-bot-api": "^0.50.0"
  }
}

At the root of the project you need an .env file with the submitted fields

TELEGRAM_TOKEN=you telegram bot token
  • ###main.ts
import { Airbot } from 'tgairbot/airbot'
import { HelloModule } from "./hello/hello.module"

const bot = new Airbot({polling: true})

bot.Create(HelloModule)
  • ###hello.module.ts
import { Module } from "tgairbot/module/module"
import { HelloView } from "./hello.view"

@Module({
    name: "HelloModule",
    imports: [],
    views: [HelloView],
    services: []
})
export class HelloModule {
    constructor(...args: any[]) {}
}
  • ###hello.view.ts
import { View } from 'tgairbot/view/view'
import { HelloService } from './hello.service'

@View({
    name: "HelloView",
    service: [HelloService]
})
export class HelloView {
    constructor(private helloService: HelloService) {}
    
    first_message() {
        return this.helloService.first_message()
    }
}
  • ###hello.service.ts
import { Service } from "tgairbot/service/service"

@Service({
    name: "HelloService"
})
export class HelloService {

    first_message() {
        return console.log("Hello")
    }
}