KnorpelSenf / telegraf-session-firestore

Google Firestore based session middleware for telegraf.js
MIT License
4 stars 0 forks source link

firestoreSession is not a function #1

Closed opinsky closed 4 years ago

opinsky commented 4 years ago

when I try to run the example file, i get this error:

bot.use( firestoreSession(db.collection('sessions'), { lazy: true }) ) ^

TypeError: firestoreSession is not a function at Object. (/mnt/c/Users/opins/Documents/Development/changebot2/index.js:12:10) at Module._compile (internal/modules/cjs/loader.js:1156:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47

it is probably something stupid on my side, but not 100% sure.

KnorpelSenf commented 4 years ago

I just tried a fresh install and copy-pasted the example code and it just worked. Can you say how to reproduce the issue? Are you sure you imported everything correctly?

rodrigosalinas commented 4 years ago

I'm having exactly the same issue.

rodrigosalinas commented 4 years ago

This is my code:

const Telegraf = require('telegraf')
const firestoreSession = require('telegraf-session-firestore')
const { Firestore } = require('@google-cloud/firestore')
const moment = require('moment')

const { BOT_TOKEN, NODE_ENV } = process.env

const db = new Firestore({
    projectId:   '****',
    keyFilename: '******'
})

const bot = new Telegraf(BOT_TOKEN)

bot.use(firestoreSession(db.collection('sessions'), { lazy: true }))

bot.start(ctx => ctx.reply('Bienvenido'))
bot.hears('hi', ctx => ctx.reply('Hola'))
bot.on('message', ctx => ctx.reply('Comando no soportado'))
bot.launch()
rodrigosalinas commented 4 years ago

Does it have something to do with some Typescript configuration?

Michael-1 commented 4 years ago

I had the same and fixed it by calling firestoreSession.default:

bot.use(firestoreSession.default(db.collection('sessions'), { lazy: true }))
KnorpelSenf commented 4 years ago

I'm very sorry for being so silent on this, I really didn't have time to fix this in the past weeks. I could by now reproduce your issue and I have a fix ready that I will publish soon (needs to be tested first). I will keep you updated here, thank you for your patience

KnorpelSenf commented 4 years ago

I bumped major because this is a breaking change. Please update your dependency and let me know if it works for you now. The workaround relying on .default should now be obsolete.