telegraf / telegraf-ratelimit

Rate-limiting middleware for Telegraf
MIT License
37 stars 5 forks source link

[TypeScript] telegraf_ratelimit_1.default is not a function #2

Open yesworld opened 5 years ago

yesworld commented 5 years ago

I'm using node-ts and i get error in the simple example. Error:

$ yarn run start yarn run v1.15.2 $ ts-node -r tsconfig-paths/register src/index.ts TypeError: telegraf_ratelimit_1.default is not a function at Object. (/home/yesworld/telegram-bot-ts/src/index.ts:14:28) at Generator.next () at /home/yesworld/telegram-bot-ts/src/index.ts:7:71 at new Promise () at __awaiter (/home/yesworld/telegram-bot-ts/src/index.ts:3:12) at /home/yesworld/telegram-bot-ts/src/index.ts:4:13 at Object. (/home/yesworld/telegram-bot-ts/src/index.ts:35:3) at Module._compile (internal/modules/cjs/loader.js:701:30) at Module.m._compile (/home/yesworld/telegram-bot-ts/node_modules/ts-node/src/index.ts:439:23) at Module._extensions..js (internal/modules/cjs/loader.js:712:10)

package.json

{
  "scripts": {
    "start": "ts-node -r tsconfig-paths/register src/index.ts",
  },
  "dependencies": {
    "dotenv": "^7.0.0",
    "telegraf": "^3.29.0",
    "telegraf-ratelimit": "^2.0.0"
  },
  "devDependencies": {
    "@types/node": "^11.13.4",
    "nodemon": "^1.18.11",
    "ts-node": "^8.1.0",
    "typescript": "^3.4.3"
  },
}
import Telegraf, { ContextMessageUpdate } from 'telegraf'
import rateLimit from 'telegraf-ratelimit'

(async () => {

  const config = {
    window: 3000,
    limit: 1,
    onLimitExceeded: (ctx: ContextMessageUpdate, next) => ctx.reply('Rate limit exceeded')
  }

  const bot = new Telegraf(TOKEN)
  try {
    await bot.use(rateLimit(config))
  } catch (err) {
    console.log(err)
  }
  bot.on('text', (ctx) => ctx.reply('Hey'))

  try {
    await bot.launch()
  } catch (err) {
    console.log(err)
  }
})()

What am I doing wrong? Thank you for your attention.

micalevisk commented 4 years ago

try

import * as ratelimit from 'telegraf-ratelimit'