Git Product home page Git Product logo

js-news-bot's Introduction

Logo

NaNdefined bot - JS News to Telegram Channel

WIP. The most critical todos:

  • Error handling
  • Tests
  • Some security for "Bypass" function
  • More parsers
  • Better documentation.

TL;DR

This bot parses websites with javascript news and delivers them to telegram channel. https://t.me/js_amb - join NaNdefined channel on the telegram to subscribe to that news. Join our development chat in telegram! https://t.me/joinchat/F3IFJxGnADPIh5MK2wvDlg

Reasons

RSS isn't a case anymore. We want to get rapid notifications from websites. Even from those - who has not provided us a possibility to do so.

Running

  1. Register your bot with @botfather. It will give you a token
  2. Create a channel. Make sure it's public.
  3. Add bot as an admin to the channel
  4. Create token file: cp config-example.js config.js
  5. Setup and configure MongoDB
  6. Put your actual data into configuration file
  7. npm install
  8. npm start
  9. Enjoy. Just type your bot a message in the telegram

TIPs

You have bot and channel. Users can write to bot, and the message will be transferred to the channel. It will allow everyone to share something. Also, there is a simple algorithm to prevent users from posting very often. It's POC; function requires improvements from the security perspective.

Architecture

Some highlights:

  • Two entities: Engine which cares about initialization and "kinda" DI. Parsers which are called by engine every XXX(configurable) seconds. Parser get's HTML parses it and prepares a text message.
  • Telegram API is injected by the Engine to every parser.
  • Parsers don't know anything about the Engine and other parsers either. It allows them to be exported as an npm module.
  • The Engine is also agnostic. The idea to export it into the separate npm module after stabilization.
  • Parsers extend BaseParser class which does most of the boring job.
  • It is not required for every parser, but most of them will need a database. DB is important to keep track what have we already sent and what should too. There is a handle record into BaseParser;
  • We don't have interfaces in js - so it's going to be a convention for a while: every parser should implement getAlias and parse method. The Engine automatically triggers them.

Every time ask yourself a question: "Can my parser be exported as an independent module?"

Such an approach will help us a lot to scale it.

Contribution

Everyone is welcome, feel free to open a PR. To simplify development, you will need to do two steps:

  • Create your own channel for testing
  • Register your own bot with @botfather for testing

It definitely makes sense to consider some option to test locally without telegram integration, but now I have no such experience. If you have - feel free to suggest.

Credentials

Icon used for application was taken here https://www.flaticon.com/authors/smashicons

Thank you for checking this page.

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.