Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yesworld opened this issue Apr 15, 2019 · 1 comment
Open

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

yesworld opened this issue Apr 15, 2019 · 1 comment

Comments

@yesworld
Copy link

yesworld commented Apr 15, 2019

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
Copy link

try

import * as ratelimit from 'telegraf-ratelimit'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants