telegraf / micro-bot

:robot: Zero-configuration Telegram bot runner
MIT License
182 stars 29 forks source link

Error: next(ctx) called with invalid context #18

Open lgg opened 5 years ago

lgg commented 5 years ago

Tried:

npm install micro-bot
npm init bot smart-bot
yarn create bot smart-bot
micro-bot -t TOKEN index.js

Bot started but got error:

Output:

Failed to fetch updates. Waiting: 1s request to https://api.telegram.org/tokenhere/getUpdates?offset=340740293&limit=100&timeout=30 failed, reason: connect ETIMEDOUT 149.154.167.220:443
μ-bot: Unhandled error Error: next(ctx) called with invalid context
    at execute (D:\dev\temp\rtumireaprofkombot\node_modules\telegraf\composer.js:301:33)
    at D:\dev\temp\rtumireaprofkombot\node_modules\telegraf\composer.js:298:14
    at execute (C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\composer.js:313:13)
    at Promise.resolve.handler (C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\composer.js:313:49)
    at C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\composer.js:114:56
    at execute (C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\composer.js:313:13)
    at C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\composer.js:298:14
    at Telegraf.handleUpdate (C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\telegraf.js:155:29)
    at Promise.all.updates.map (C:\Users\Фёдор\AppData\Roaming\npm\node_modules\micro-bot\node_modules\telegraf\telegraf.js:140:65)
    at Array.map (<anonymous>)
lgg commented 5 years ago

index.js

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

const bot = new Composer()

bot.use(log())
bot.use(session())

bot.start(({reply}) => reply('Welcome message'))
bot.help(({reply}) => reply('Help message'))
bot.settings(({reply}) => reply('Bot settings'))

bot.command('date', ({reply}) => reply(`Server time: ${Date()}`))

module.exports = bot

package.json

{
  "name": "rtumireaprofkombot",
  "version": "0.0.0",
  "description": "RTU MIREA Profkom bot",
  "repository": {
    "url": "lgg/rtumireaprofkombot",
    "type": "git"
  },
  "main": "index.js",
  "scripts": {
    "dev": "supervisor -x micro-bot index.js",
    "start": "micro-bot",
    "now-start": "micro-bot -d ${NOW_URL}",
    "lint": "eslint .",
    "test": "npm run lint"
  },
  "engines": {
    "node": ">=8.5.0"
  },
  "author": "lgg",
  "license": "MIT",
  "dependencies": {
    "micro-bot": "^2.5.1"
  },
  "devDependencies": {
    "eslint": "^5.9.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^8.0.0",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-standard": "^4.0.0",
    "supervisor": "^0.12.0"
  }
}
darshantejani007 commented 3 years ago

How did you solve this error? I'm also facing the same issue!

lgg commented 3 years ago

@darshantejani007 I didn't solve this issue. I used pure telegraf in new projects (empty repo) and for some reason it worked...

amjadcp commented 2 years ago

I used telegraf to access telegram bot api and express for server creation :)