A TypeScript wrapper around vk-io with Dependency Injection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Timofey Gelazoniya 569901d8ab
Merge pull request #104 from xzeldon/dependabot/npm_and_yarn/types/node-17.0.21
3 months ago
.github ci: add dependabot 8 months ago
packages build: change github repo to https in package.json 8 months ago
.gitignore Initial commit 9 months ago
.releaserc.json ci: github actions 8 months ago
CHANGELOG.md 1.0.0 8 months ago
LICENSE Initial commit 9 months ago
README.md chore: 📝 update readme 8 months ago
lerna.json build: switch to independent version in lerna.json 8 months ago
package.json build(deps-dev): bump @types/node from 16.11.12 to 17.0.21 3 months ago
rollup.config.js build: make rollup watch mode work 8 months ago
tsconfig.json build: make rollup watch mode work 8 months ago
yarn.lock build(deps-dev): bump @types/node from 16.11.12 to 17.0.21 3 months ago

README.md

vk-di

🤖 A TypeScript wrapper around vk-io

This repository is an example of a runtime dependency injection implementation, metadata reflection and the service provider pattern in TypeScript.

  • Decorators for declarative syntax 🛋
  • Runtime Dependency injection support 💉
  • Modular structure for better organizaed projects 🏗

Getting Started

Install dependencies

npm i

or

yarn install

Getting started

index.ts (entry point)

Your index.ts is the main entry point of your application. Your application consists of at least one "MainModule" and as many other sub-class modules as you want. You define them all here for runtime instantiation.

const app = new App({
    modules: [
        MainModule
    ],
    on_start() {
        console.log('Bot is up and running');
    }
});

app.launch();

main.module.ts

Your main modules's primary responsibility should be authenticating your bot. Pass a Client instance with Options object that contains the token field to the constructor and then call start() on the this.client property. The main module might also be a good place to add global on state change events.

import { MessageContext } from "vk-io";
import { Client, Module } from "@core/*";

export default class MainModule extends Module {
    constructor() {
        super(new Client({
            token: process.env.TOKEN
        }));

        this.client.start();
    }

    /**
     * The bot will be trigger to message '/ping'.
     * You can also use regular expressions instead of
     * strings.
     */

    @Command('ping', { prefix: '/' })
    on_ping(context: MessageContext) {
        context.send('pong!');
    }
}

An example of a fully working bot can be found in simple-bot package.

Inspired by