Giter Club home page Giter Club logo

telegram-bot-4all's Introduction

Telegram Bot 4all

image

Create telegram bots never been so easy.

Goal

Serve as a starting point to develop telegram personal or public bots like :

  • List my movies
  • List my schedule
  • Get random names
  • Or whatever you want

Requirements

  • Node.js >=14
  • Telegram account
  • Telegram Token (BotFather)

Steps

Step 1 : Telegram previous configurations

  • Start new telegram chat with botFather and send the following commands:

  • /start

  • /newbot

  • Enter : Name of your Bot

  • Enter : Id of your Bot

    This step , will return to you the token. This is required to register and interact with your bot. Save it!!!

Step 2 : Create the bot with nodejs

Step 3 : Deploy your bot

You need to deploy your bot (this source code) in a public server or domain: using some free or private service like: Heroku, Openshift, https://zeit.co/now, etc

Example with heroku:

  • Create an account in heroku (for instance)
  • Create a configuration variable called : TELEGRAM_BOT_TOKEN with token gotten in previous step.
  • Push and save the public url of this heroku application.

Step 4 : Register bot in Telegram Servers

If your bot is deployed and has a url like:

You must register it, executing this:

curl -F "url=https://my_awesome_bot.herokuapp.com/new-message"  https://api.telegram.org/bot<your_api_token>/setWebhook

Step 5: Chat with your bot

If you followed all the steps without errors, you could use this command with your own bot:

If you don't have any response, check de logs or review the telegram father configurations.

Create new commands

  • We will create a command who return the data of the current day
  • Create a module inside of commands folder. The doit method is mandatory
function Today() {
  this.doit = (commandArguments, chatMessageObject) => {
    var today = new Date();
    return today.toISOString().substring(0, 10);
  }
}
module.exports = Today;

The framework will inject you two variables: (commandArguments, chatMessageObject) in the doit method

commandArguments

The parameters received with your command. If the chat was: /buy_coffee param1 param2, you will receive: param1 param2

chatMessageObject

The entire json sent by telegram bot internal engine:

{
  "message": {
    "from": {
      "id": 123456,
      "is_bot": false,
      "first_name": "JohnDoe",
      "last_name": "ENL",
      "username": "john_doe"
    },
    "chat": {
      "id": 87865786,
      "title": "My group or chat title",
      "type": "group"
    },
    "text": "/author param1 param2"
  }
}

You could use these variables for what you want to do with your bot command.

  • That's all. Redeploy your bot and you will have a new command, ready to use it in the chat with /today

Road Map

  • Emulate telegram service for local tests
  • Add self webhook endpoint
  • Add complex feature : receive images
  • Add complex feature : receive form data
  • Add complex feature : payments

Contributors


JRichardsz

telegram-bot-4all's People

Contributors

jrichardsz avatar

Stargazers

Muhammad Faizan Shah avatar Roman avatar

Watchers

James Cloos avatar  avatar

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.