All Projects → telegraf → Micro Bot

telegraf / Micro Bot

Licence: mit
🤖 Zero-configuration Telegram bot runner

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Micro Bot

Mypackbot
🤖 Your own unlimited pack of Telegram-stickers
Stars: ✭ 18 (-89.6%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Turibot
TuriBot is a simple way to communicate with Telegram APIs in PHP
Stars: ✭ 68 (-60.69%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Telegram Bot Api
First Telegram Bot API node.js library
Stars: ✭ 205 (+18.5%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Tgbot Cpp
C++ library for Telegram bot API
Stars: ✭ 439 (+153.76%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Novagram
An Object-Oriented PHP library for Telegram Bots
Stars: ✭ 112 (-35.26%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Informer
A Telegram Mass Surveillance Bot in Python
Stars: ✭ 745 (+330.64%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Groupbutler
This bot can help you in managing your group with rules, anti-flood, description, custom triggers, and much more!
Stars: ✭ 399 (+130.64%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Java Telegram Bot Api
Telegram Bot API for Java
Stars: ✭ 819 (+373.41%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Node Telegram Api
A simple API to create and control Telegram bots
Stars: ✭ 117 (-32.37%)
Mutual labels:  telegram-api, bot, telegram-bot, telegram
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (-4.62%)
Mutual labels:  bot, telegram-bot, telegram
Telegram Bot
Telegram Bot using AWS API Gateway and AWS Lambda
Stars: ✭ 96 (-44.51%)
Mutual labels:  bot, telegram-bot, telegram
Expressbot
一个可以帮你订阅、查询快递物流、跟你闲聊Telegram机器人
Stars: ✭ 137 (-20.81%)
Mutual labels:  bot, telegram-bot, telegram
Sentry Telegram
Plugin for Sentry which allows sending notification via Telegram messenger.
Stars: ✭ 168 (-2.89%)
Mutual labels:  telegram-api, telegram-bot, telegram
Telebot.nim
Async client for Telegram Bot API in pure Nim [Bot API 5.1]
Stars: ✭ 93 (-46.24%)
Mutual labels:  bot, telegram-bot, telegram
Telegram.bot
.NET Client for Telegram Bot API
Stars: ✭ 1,964 (+1035.26%)
Mutual labels:  bot, telegram-bot, telegram
Tgdr
Telegram directory to discover channels, bots and groups.
Stars: ✭ 91 (-47.4%)
Mutual labels:  bot, telegram-bot, telegram
Hackernewsbot
📰 Telegram bot that posts new hot stories from Hacker News to telegram channel
Stars: ✭ 103 (-40.46%)
Mutual labels:  bot, telegram-bot, telegram
Vk To Telegram Transfer Bot
Бот, пересылающий сообщения из чатов ВК в Telegram и обратно
Stars: ✭ 143 (-17.34%)
Mutual labels:  bot, telegram-bot, telegram
Telegram Bot Github
Allows to you receive GitHub notifications right in the Telegram
Stars: ✭ 103 (-40.46%)
Mutual labels:  bot, telegram-bot, telegram
Zanzara
Asynchronous PHP Telegram Bot Framework built on top of ReactPHP
Stars: ✭ 107 (-38.15%)
Mutual labels:  bot, telegram-bot, telegram

NPM Version node Build Status js-standard-style

μ-bot

🤖 Zero-configuration Telegram bot runner

Documentation

micro-bot was built on top of Telegraf library.

Telegraf API documentation.

Installation

Install from NPM:

$ npm install micro-bot

Scaffolding

If you have installed latest yarn or npm you can use create-bot scaffolding tool:

$ npm init bot smart-bot
$ cd smart-bot

Or using yarn:

$ yarn create bot smart-bot
$ cd smart-bot

Quick start

The following example will answer with important information about everything.

$ mkdir smart-bot
$ cd smart-bot
$ npm init
$ npm install micro-bot --save

Then write your index.js.

module.exports = ({ reply }) => reply('42')

Then in your package.json:

"main": "index.js",
"scripts": {
  "start": "micro-bot"
}

To run the bot, use the micro-bot command:

$ BOT_TOKEN='TOKEN' npm start

or

$ micro-bot -t TOKEN index.js

To run the bot with webhook support, provide webhook domain name:

$ micro-bot -t TOKEN -d yourdomain.tld echo.js

Supported environment variables:

  • process.env.BOT_TOKEN - Bot token
  • process.env.BOT_DOMAIN - Webhook domain

Deployment to now

Let's deploy your micro-bot with Realtime global deployments by Zeit.

First, install now

$ npm install now -g
$ now login

Finally use now to deploy:

$ now -e BOT_TOKEN='YOUR BOT TOKEN'

Congratulations, your bot is alive! 🎉

Deployment to Heroku

Okay, now we will deploy our micro-bot to Heroku. Why not?!

First, install heroku binaries and login via console.

Then, init new git repo:

$ git init
$ heroku create

Afterwards, update Heroku config:

$ heroku config:set --app YourAppId BOT_TOKEN='YOUR BOT TOKEN'
$ heroku config:set --app YourAppId BOT_DOMAIN='https://YourAppId.herokuapp.com'

Then add Procfile into the root of your project, with one line:

web: micro-bot -p $PORT

Finally use git to deploy:

$ git add index.js package.json
$ git commit -m 'initial commit'
$ git push heroku master

Example μ-bots

Advanced Examples

const { mount, reply } = require('micro-bot')
module.exports = mount('sticker', reply('👍'))
const { readFileSync } = require('fs')
const { Composer } = require('micro-bot')
const bot = new Composer()

bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Help message'))
bot.hears('hi', ({ reply }) => reply('Hello'))
bot.on('sticker', ({ reply }) => reply('👍'))

// Export bot handler
module.exports = bot

// Or you can export hash with handlers and options
module.exports = {
  bot: bot,
  init: (bot) => {
    console.log('Bot initialization hook')
  },
  server: (req, res, next) => {
    console.log('Http request hook')
  },
  options: {
    telegram: {
      agent: new HttpsProxyAgent('proxy url')
    }
  },
  tlsOptions: {
    key:  readFileSync('server-key.pem'),
    cert: readFileSync('server-cert.pem'),
    ca: [
      // This is necessary only if the client uses the self-signed certificate.
      readFileSync('client-cert.pem')
    ]
  }
}

Stages & Scenes

const { Composer, Stage, Scene, session } = require('micro-bot')

// Greeter scene
const greeter = new Scene('greeter')
greeter.enter((ctx) => ctx.reply('Hi'))
greeter.leave((ctx) => ctx.reply('Buy'))
greeter.hears(/hi/gi, (ctx) => ctx.scene.leave())
greeter.on('message', (ctx) => ctx.reply('Send `hi`'))

const stage = new Stage()
stage.register(greeter)

const bot = new Composer()
bot.use(session())
bot.use(stage)
bot.command('greeter', (ctx) => ctx.scene.enter('greeter'))
bot.command('cancel', (ctx) => ctx.scene.leave())
module.exports = bot

Credits

micro-bot is highly inspired by Micro

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].