[
  {
    "path": ".editorconfig",
    "content": "# editorconfig.org\nroot = true\n\n[*]\nindent_style = space\nindent_size = 2\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.md]\ntrim_trailing_whitespace = false\n\n[*.txt]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".eslintignore",
    "content": "node_modules/\n"
  },
  {
    "path": ".eslintrc",
    "content": "{\n  \"extends\": [\"standard\"]\n}\n"
  },
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directory\nnode_modules\n\n# Optional npm cache directory\n.npm\n\n# Optional REPL history\n.node_repl_history\n.nyc_output\ncoverage\n_docpress\npackage-lock.json\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - 8\n  - 9\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2016 Vitaly Domnikov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "bin/micro-bot",
    "content": "#!/usr/bin/env node\n\nconst { existsSync } = require('fs')\nconst path = require('path')\nconst parse = require('minimist')\nconst dotenv = require('dotenv')\nconst { start } = require('../')\n\nconst help = () => {\n  console.log(`Usage: micro-bot [opts] <file>\n\n  -t  Bot token\n  -d  Webhook domain [$BOT_DOMAIN or $NOW_URL]\n  -H  Webhook host [0.0.0.0]\n  -p  Webhook port [$PORT or 3000]\n  -e  Load env vars from file. [.env]'\n  -s  Silent mode\n  -h  Show this help message\n  -v  Show version information`)\n}\n\nconst args = parse(process.argv, {\n  alias: {\n    d: 'domain',\n    e: 'dotenv',\n    h: 'help',\n    H: 'host',\n    p: 'port',\n    s: 'silent',\n    t: 'token',\n    v: 'version'\n  },\n  boolean: ['h', 'v', 's'],\n  default: {\n    H: '0.0.0.0',\n    p: process.env.PORT || 3000\n  }\n})\n\nif (args.help) {\n  help()\n  process.exit(0)\n}\n\nif (args.version) {\n  const packageData = require('../package.json')\n  console.log(`v${packageData.version}`)\n  process.exit(0)\n}\n\nif (args.dotenv) {\n  const dotenvFileName = typeof args.dotenv === 'string' ? args.dotenv : '.env'\n  if (!existsSync(dotenvFileName)) {\n    console.error(`μ-bot: -e flag is set but ${dotenvFileName} file is missing`)\n    help()\n    process.exit(1)\n  }\n  dotenv.config({ path: dotenvFileName })\n}\n\nconst token = args.token || process.env.BOT_TOKEN\nif (!token) {\n  console.error(`μ-bot: Please supply Bot token`)\n  help()\n  process.exit(1)\n}\n\nlet [,, file] = args._\n\nif (!file) {\n  try {\n    const packageJson = require(path.resolve(process.cwd(), 'package.json'))\n    file = packageJson.main || 'index.js'\n  } catch (err) {\n    if (err.code === 'MODULE_NOT_FOUND') {\n      console.error(`μ-bot: Could not read \\`package.json\\`: ${err.message}`)\n      process.exit(1)\n    }\n  }\n}\n\nif (!file) {\n  console.error('μ-bot: Please supply a file with bot handler.')\n  help()\n  process.exit(1)\n}\n\nif (file[0] !== '/') {\n  file = path.resolve(process.cwd(), file)\n}\n\nlet botModule\ntry {\n  botModule = require(file)\n} catch (err) {\n  console.error(`μ-bot: Error when importing ${file}: ${err.stack}`)\n  process.exit(1)\n}\n\nconst domain = args.domain || process.env.BOT_DOMAIN || process.env.NOW_URL\n\nconst botOptions = {\n  token,\n  domain,\n  botModule,\n  port: args.port,\n  host: args.host\n}\n\nstart(botOptions).catch((err) => {\n  console.warn(`μ-bot: Failed to start: ${err}`)\n})\n"
  },
  {
    "path": "examples/bot.js",
    "content": "const { Composer } = require('micro-bot')\nconst bot = new Composer()\n\nbot.start((ctx) => ctx.reply('Welcome'))\nbot.help((ctx) => ctx.reply('Help message'))\nbot.hears('hi', ({ reply }) => reply('Hello'))\nbot.on('sticker', ({ reply }) => reply('👍'))\nbot.on('message', ({ reply }) => reply('👋'))\n\nmodule.exports = bot\n"
  },
  {
    "path": "index.js",
    "content": "const Telegraf = require('telegraf')\nconst Stage = require('telegraf/stage')\nconst Scene = require('telegraf/scenes/base')\nconst WizardScene = require('telegraf/scenes/wizard')\n\nconst defaultInit = () => Promise.resolve()\nconst defaultCb = (req, res) => {\n  res.statusCode = 404\n  res.end()\n}\n\nfunction start ({ token, domain, hookPath, botModule, port, host, silent }) {\n  const webhook = typeof domain === 'string' || typeof hookPath === 'string'\n    ? {\n      domain,\n      hookPath,\n      port,\n      host,\n      tlsOptions: botModule.tlsOptions,\n      cb: botModule.server || botModule.requestHandler || defaultCb\n    }\n    : null\n  const bot = new Telegraf(token, botModule.options)\n  const init = botModule.init || botModule.initialize || defaultInit\n  bot.catch((err) => console.error('μ-bot: Unhandled error', err))\n  bot.use(botModule.bot || botModule.botHandler || botModule)\n  return init(bot)\n    .then(() => bot.launch({ webhook }))\n    .then(() => !silent && console.log(`μ-bot: Bot started`))\n}\n\nmodule.exports = Object.assign(Telegraf, { Stage, Scene, WizardScene, start: start })\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"micro-bot\",\n  \"version\": \"2.5.3\",\n  \"description\": \"Zero-configuration Telegram bot runner\",\n  \"author\": \"Vitaly Domnikov <oss@vitaly.codes>\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/telegraf/micro-bot#readme\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+ssh://git@github.com/telegraf/micro-bot.git\"\n  },\n  \"bugs\": {\n    \"url\": \"https://github.com/telegraf/micro-bot/issues\"\n  },\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"eslint .\"\n  },\n  \"engines\": {\n    \"node\": \">=8.1\"\n  },\n  \"bin\": {\n    \"micro-bot\": \"./bin/micro-bot\"\n  },\n  \"dependencies\": {\n    \"dotenv\": \"^6.0.0\",\n    \"minimist\": \"^1.2.0\",\n    \"telegraf\": \"^3.25.4\"\n  },\n  \"devDependencies\": {\n    \"eslint\": \"^5.4.0\",\n    \"eslint-config-standard\": \"^12.0.0\",\n    \"eslint-plugin-import\": \"^2.2.0\",\n    \"eslint-plugin-node\": \"^8.0.0\",\n    \"eslint-plugin-promise\": \"^4.0.0\",\n    \"eslint-plugin-standard\": \"^4.0.0\"\n  },\n  \"keywords\": [\n    \"telegraf\",\n    \"telegram\",\n    \"bot\"\n  ]\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# ⚠️ This package is deprecated. Use [telegraf](https://github.com/telegraf/telegraf)'s builtin CLI instead.\n\n[![NPM Version](https://img.shields.io/npm/v/micro-bot.svg?style=flat-square)](https://www.npmjs.com/package/micro-bot)\n[![node](https://img.shields.io/node/v/micro-bot.svg?style=flat-square)](https://www.npmjs.com/package/micro-bot)\n[![Build Status](https://img.shields.io/travis/telegraf/micro-bot.svg?branch=master&style=flat-square)](https://travis-ci.org/telegraf/micro-bot)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)\n\n# μ-bot\n> 🤖 Zero-configuration Telegram bot runner\n\n## Documentation\n\n`micro-bot` was built on top of [`Telegraf`](https://github.com/telegraf/telegraf) library.\n\n[Telegraf API documentation](http://telegraf.js.org).\n\n## Installation\n\nInstall from NPM:\n\n```bash\n$ npm install micro-bot\n```\n\n## Scaffolding\n\nIf you have installed latest `yarn` or `npm` you can use [`create-bot`](https://github.com/telegraf/create-bot) scaffolding tool:\n\n```bash\n$ npm init bot smart-bot\n$ cd smart-bot\n```\n\nOr using `yarn`:\n\n```bash\n$ yarn create bot smart-bot\n$ cd smart-bot\n```\n\n## Quick start\n\nThe following example will answer with important information about everything.\n\n```bash\n$ mkdir smart-bot\n$ cd smart-bot\n$ npm init\n$ npm install micro-bot --save\n```\n\nThen write your `index.js`.\n\n```js\nmodule.exports = ({ reply }) => reply('42')\n```\n\nThen in your `package.json`:\n\n```js\n\"main\": \"index.js\",\n\"scripts\": {\n  \"start\": \"micro-bot\"\n}\n```\n\nTo run the bot, use the `micro-bot` command:\n\n```bash\n$ BOT_TOKEN='TOKEN' npm start\n```\n\nor\n\n```bash\n$ micro-bot -t TOKEN index.js\n```\n\nTo run the bot with webhook support, provide webhook domain name:\n\n```bash\n$ micro-bot -t TOKEN -d yourdomain.tld echo.js\n```\n\nSupported environment variables:\n\n* `process.env.BOT_TOKEN` - Bot token\n* `process.env.BOT_DOMAIN` - Webhook domain\n\n## Deployment to `now`\n\nLet's deploy your `micro-bot` with Realtime global deployments by Zeit.\n\nFirst, install [`now`](https://zeit.co/now)\n```bash\n$ npm install now -g\n$ now login\n```\n\nFinally use `now` to deploy:\n\n```bash\n$ now -e BOT_TOKEN='YOUR BOT TOKEN'\n```\n\nCongratulations, your bot is alive! 🎉\n\n## Deployment to Heroku\n\nOkay, now we will deploy our `micro-bot` to Heroku. Why not?!\n\nFirst, install [`heroku binaries`](https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up) and login via console.\n\nThen, init new git repo:\n```bash\n$ git init\n$ heroku create\n```\n\nAfterwards, update Heroku config:\n\n```bash\n$ heroku config:set --app YourAppId BOT_TOKEN='YOUR BOT TOKEN'\n$ heroku config:set --app YourAppId BOT_DOMAIN='https://YourAppId.herokuapp.com'\n```\n\nThen add `Procfile` into the root of your project, with one line:\n\n```Procfile\nweb: micro-bot -p $PORT\n```\n\nFinally use git to deploy:\n\n```bash\n$ git add index.js package.json\n$ git commit -m 'initial commit'\n$ git push heroku master\n```\n\n#### Example μ-bots\n\n* [ 🔥 Glitch example](https://glitch.com/edit/#!/dashing-light)\n* [`@uncover_bot`](https://telegram.me/uncover_bot) - [Source code](https://uncover.now.sh/_src)\n* [`@epub2mobi_bot`](https://telegram.me/epub2mobi_bot) - [Source code](https://epub2mobi.now.sh/_src)\n* [`@gorchichkabot`](https://bot.gorchichka.com) - [Source code](https://github.com/agudulin/gorchichkabot)\n* [`@aloudbot`](https://telegram.me/aloudbot) - [Source code](https://github.com/shrynx/aloudbot)\n\n## Advanced Examples\n\n```js\nconst { mount, reply } = require('micro-bot')\nmodule.exports = mount('sticker', reply('👍'))\n```\n\n```js\nconst { readFileSync } = require('fs')\nconst { Composer } = require('micro-bot')\nconst bot = new Composer()\n\nbot.start((ctx) => ctx.reply('Welcome'))\nbot.help((ctx) => ctx.reply('Help message'))\nbot.hears('hi', ({ reply }) => reply('Hello'))\nbot.on('sticker', ({ reply }) => reply('👍'))\n\n// Export bot handler\nmodule.exports = bot\n\n// Or you can export hash with handlers and options\nmodule.exports = {\n  bot: bot,\n  init: (bot) => {\n    console.log('Bot initialization hook')\n  },\n  server: (req, res, next) => {\n    console.log('Http request hook')\n  },\n  options: {\n    telegram: {\n      agent: new HttpsProxyAgent('proxy url')\n    }\n  },\n  tlsOptions: {\n    key:  readFileSync('server-key.pem'),\n    cert: readFileSync('server-cert.pem'),\n    ca: [\n      // This is necessary only if the client uses the self-signed certificate.\n      readFileSync('client-cert.pem')\n    ]\n  }\n}\n```\n\n### Stages & Scenes\n\n```js\nconst { Composer, Stage, Scene, session } = require('micro-bot')\n\n// Greeter scene\nconst greeter = new Scene('greeter')\ngreeter.enter((ctx) => ctx.reply('Hi'))\ngreeter.leave((ctx) => ctx.reply('Buy'))\ngreeter.hears(/hi/gi, (ctx) => ctx.scene.leave())\ngreeter.on('message', (ctx) => ctx.reply('Send `hi`'))\n\nconst stage = new Stage()\nstage.register(greeter)\n\nconst bot = new Composer()\nbot.use(session())\nbot.use(stage)\nbot.command('greeter', (ctx) => ctx.scene.enter('greeter'))\nbot.command('cancel', (ctx) => ctx.scene.leave())\nmodule.exports = bot\n\n```\n\n## Credits\n\n`micro-bot` is highly inspired by [`Micro`](https://github.com/zeit/micro/)\n"
  }
]