https://github.com/xzeldon/vk-di
🤖 A TypeScript wrapper around vk-io with Dependency Injection
https://github.com/xzeldon/vk-di
Last synced: 21 days ago
JSON representation
🤖 A TypeScript wrapper around vk-io with Dependency Injection
- Host: GitHub
- URL: https://github.com/xzeldon/vk-di
- Owner: xzeldon
- License: mit
- Created: 2021-09-03T22:29:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T04:03:17.000Z (about 2 years ago)
- Last Synced: 2025-05-01T14:54:00.595Z (21 days ago)
- Language: TypeScript
- Homepage:
- Size: 739 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vk-di
🤖 A TypeScript wrapper around [vk-io](https://github.com/negezor/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.
```ts
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.
```ts
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
* [NestJS](https://github.com/nestjs/nest)
* [Angular](https://github.com/angular/angular)