fletcherist / yandex-dialogs-sdk

☂️Build your skill for Yandex.Alice with ease. (nodejs/typescript)
MIT License
122 stars 16 forks source link

TypeError: Cannot read property 'session' of undefined #111

Closed vitalets closed 5 years ago

vitalets commented 5 years ago

code:

const { Alice, Reply } = require('yandex-dialogs-sdk');

const alice = new Alice();

alice.use((ctx, next) => {
  return next();
});

alice.any(ctx => {
  return Reply.text('Hello');
});

alice.listen(3000, '/');

output:

(node:80625) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'session' of undefined
    at .../node_modules/yandex-dialogs-sdk/dist/stage/stage.js:32:26
    at next (.../node_modules/yandex-dialogs-sdk/dist/alice.js:48:20)
    at alice.use (.../src/index.js:6:10)
    at next (.../node_modules/yandex-dialogs-sdk/dist/alice.js:48:20)
    at .../node_modules/yandex-dialogs-sdk/dist/session/userSessionMiddleware.js:15:23
Yavanosta commented 5 years ago

Hello!

You have to pass context to next middleware directly.

Like this:

alice.use((ctx, next) => {
  return next(ctx);
});
vitalets commented 5 years ago

@Yavanosta thanks! Should be fixed in docs. Created #112