Giter Site home page Giter Site logo

evilsprut / nestjs-telegram Goto Github PK

View Code? Open in Web Editor NEW
92.0 2.0 23.0 1.24 MB

šŸ¤– A NestJS Telegram module for using the Telegram Bot API

License: MIT License

TypeScript 99.50% JavaScript 0.18% Shell 0.32%
nestjs telegram-bot-api telegram-api telegram bot nest

nestjs-telegram's Introduction

Nest Logoplus Telegram Logo

A NestJS service wrapper for Telegram bots!

Description

Telegram API wrapper for the Telegram Bots API made to work with the Nest framework.

Installation

$ npm install nestjs-telegram

Using the Module

// Inside of your module imports
@Module({
  imports: [TelegramModule.forRoot({
    botKey: 'YourBotApiToken'
  })]
})

// Or async
@Module({
  imports: [
    TelegramModule.forRootAsync({
      useFactory: async (configService: ConfigService) => ({
        botKey: configService.get('Telegram_API_Key')
      }),
      inject: [ConfigService]
    })
  ],
})

In your service class you can inject the service like so and then use it in any function as you would any other service

@Injectable()
export class MyService {

  constructor(private readonly telegram: TelegramService) {}

  testBot(): Observable<TelegramUser> {
    return this.telegram.getMe();
  }
}

Currently, the service only returns Observables as the HttpModule does. If you want to use Promises just call .toPromise() on the function.

Support

If any bugs are found in the API wrapper, please open an issue on GitHub, or a Pull Request if you want to fix it yourself! Please be as explicit as possible and provide a minimum reproducing repository if at all possible, as it helps track down what went wrong.

Documentation

All documentation for this wrapper comes from the Telegram Bot API documentation, if there are any typos, please let me know or open a PR to fix it.

Todo

  • Implement Telegram Passport methods
  • Implement Telegram Inline mode options

Stay in touch

License

Nestjs-telegram is MIT licensed.

nestjs-telegram's People

Contributors

andrewgrow avatar dependabot-preview[bot] avatar dependabot[bot] avatar evilsprut avatar jmcdo29 avatar rupikz avatar saeedsoltoon avatar xaosaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nestjs-telegram's Issues

Dependabot couldn't find the branch dev

Dependabot was set up to create pull requests against the branch dev, but couldn't find it.

If the branch has been permanently deleted you can update Dependabot's target branch from your dashboard.

You can mention @dependabot in the comments below to contact the Dependabot team.

How does the sendDocument method work?

Does not work:

this.telegramService.sendDocument({
  chat_id: 100500,
  document: fs.createReadStream('error.txt') // <--- need to have Buffer here, tried a lot of ways to make it
}).subscribe()

Telegram API answers with code 400 without explanation.

Works:

import * as FormData from 'form-data';
...
const form = new FormData();
form.append('chat_id', chat_id);
form.append('document', Buffer.alloc(text.length, text), {filename: 'error.txt'});
form.submit(`https://api.telegram.org/bot${settings.telegramBot.key}/sendDocument`, function(err, response) {
 console.log(err, response);
});

sendMessage work only once

there is a problem in sending messages, if you use sendMessaage for once, it work ok and fine but if you try that for second time in the same response such as:

.. SOMEā€ŒCALCULATIONS...
await this.telegram.sendMessage({
      chat_id: message.chat.id,
      text: 'MESSAGE',
      parse_mode: 'markdown',
});
.. SOMEOTHERā€ŒCALCULATIONS...
await this.telegram.sendMessage({ <-- this call will be ignored!
      chat_id: message.chat.id,
      text: 'ANOTHER_MESSAGE',
      parse_mode: 'markdown',
    });

also if you could handle long messages to split them and send them in order would be nice.

thanks.

Nest can't resolve dependencies of the TELEGRAM_MODULE_OPTIONS

Hi, when I follow steps from the readme I got following error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the TELEGRAM_MODULE_OPTIONS (?). 
Please make sure that the argument ConfigService at index [0] is available in the TelegramModule context.

this.url undefined

When I try to make a request axios dosen't get the first part of url from:

this.url = https://api.telegram.org/bot${this.options.botKey}/;

when I move that line to constructor from on moduleInit it works fine.

Where is getUpdates method?

Hello, i can't find getUpdates method? Do you forget add it or you have some reasons to not implement it. Seems it is very common and helpful method.

Correct type imports

Now, when i import some type, code for it looks like import { TelegramUser } from 'nestjs-telegram/dist/interfaces/telegramTypes.interface';, seems direct link to dist folder is not correct approach.

May be should change it to something like import { TelegramUser } from 'nestjs-telegram'?

Latest release

Please publish the latest release for the master branch

Unexpected crush

Can't understand what happened.

[Error: ENOENT: no such file or directory, chmod 'node_modules/nestjs-telegram/node_modules/rxjs/migrations/update-6_0_0/.index.js 3.map.icloud'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'chmod',
  path: 'node_modules/nestjs-telegram/node_modules/rxjs/migrations/update-6_0_0/.index.js 3.map.icloud'
}

Node v15.4.0
Latest NestJS
Mac OS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.