Amazebot / bbot

An adaptable conversation engine for building bespoke bots.
MIT License
55 stars 2 forks source link

Error when trying to use MongoDB for assigning nicknames #115

Closed tsai0009 closed 4 years ago

tsai0009 commented 4 years ago

My ultimate goal is to have the user actually set an api token for themselves but I am testing the DB first with nickname.

I get the error:

'error: [branch] branch_7 middleware error, Cannot read property 'nickname' of undefined'

When using the code provided in the Amazebot video:

bot.global.text({
    after: "call me"
}, (b) => {

    b.users.nickname = b.conditions.captured
    return b.respond(`OK ${b.user.nickname}`)
})

bot.global.text({
    contains: "hello"
}, (b) => {
    const nick = b.users.nickname || 'you'
    return b.respond(`Hey ${nick}`)
})

I have an idea of what middleware is, but due to my limited javascript knowledge I don't understand where it is. I am using the default node_modules.

One thing I am getting when I start the bot is:

(node:8660) DeprecationWarning: Mongoose: findOneAndUpdate() and findOneAndDelete() without the useFindAndModify option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#-findandmodify-

But it could be unrelated

tsai0009 commented 4 years ago

The problem was actually the syntax being different to that of the video.

It must have changed at some point.

Instead of b.users.nickname change it to b.message.user.nickname