watson-developer-cloud / botkit-middleware

A middleware to connect Watson Conversation Service to different chat channels using Botkit
https://www.npmjs.com/package/botkit-middleware-watson
Apache License 2.0
206 stars 254 forks source link

watsonMiddleware.updateContextAsync is not a function #71

Closed richielo closed 7 years ago

richielo commented 7 years ago

Is version 1.4 not available at the moment? If not how do use something similar? Thanks a lot in advance

richielo commented 7 years ago

I even tried 1.3.1 and it gives me watsonMiddleware.updateContext is not a function

Naktibalda commented 7 years ago

updateContext is currently only available in master branch. updateContextAsync is promisified version created by Promise.promisifyAll(watsonMiddleware);

@germanattanasio please release a new version.

richielo commented 7 years ago

@Naktibalda Thanks a lot for the reply. Any idea when will there be a new version? If it's not happening soon, are there any workarounds at the moment? I just want to update the context and get an alternate response from Watson

Naktibalda commented 7 years ago

I can't answer a question about a new version. Some workarounds: a) modify context in after, send context from controller - https://github.com/watson-developer-cloud/botkit-middleware#using-middlewareafter-and-controller b) require watson-botkit-middleware/lib/middleware/utils.js and use its updateContext method. c) copy the updateContext function from utils to your bot.

Naktibalda commented 7 years ago

I missed the easiest workaround - using master branch with npm:

"botkit-middleware-watson": "git+https://git@github.com/watson-developer-cloud/botkit-middleware.git#master",
richielo commented 7 years ago

Thanks a lot. That fixes things. I am following the example in the README and it's still giving me error. Do you mind helping me out a bit? I am very new to this. Thanks a lot. I am getting this "TypeError: Converting circular structure to JSON"


function search(context, callback){
    context.action = "found";
    if(context.entertainment == "movies"){
        result_1 = movie_dict[context.movie_genre][0];
        console.log(result_1);
        context.search_result = movie_dict[context.movie_genre];
    }
    else if(context.entertainment == "music"){
        result_1 = music_dict[context.music_genre][0];
        console.log(result_1);
        context.search_result = music_dict[context.music_genre];
    }
    callback(null, context);
}

var searchAsync = Promise.promisify(search);

 var newMessage = message;
 newMessage.text = 'searching';
 searchAsync(message.watsonData.context).then(function (context) {
                //update context in storage
                return watsonMiddleware.updateContext(message.user, context);
              }).then(function () {
                //send message to watson (it reads updated context from storage)
                console.log("before send");
                console.log(newMesssage);
                return watsonMiddleware.sendToWatson(bot, newMessage);
              }).catch(function (error) {
                console.log("error")
                newMessage.watsonError = error;
              }).then(function () {
                //send results to user
                console.log("after send");
                console.log(newMessage);
                return processWatsonResponse(bot, newMessage);
              });```
richielo commented 7 years ago

The updatecontext function is giving error, I tried calling it like this: watsonMiddleware.updateContext(message.user, watsonMiddleware.storage, {context: context})

Naktibalda commented 7 years ago

You don't need to wrap context in an object. try watsonMiddleware.updateContext(message.user, watsonMiddleware.storage, context);

I've seen this circular structure error once and it was happening in debug line at https://github.com/watson-developer-cloud/botkit-middleware/blob/master/lib/middleware/utils.js#L48

germanattanasio commented 7 years ago

@Naktibalda is master ready for a release? if yes will it be patch or minor. I think that after your changes we will have to do a minor release. Please write some lines in the CHANGELOG.md file and I will do a minor release.

Thanks!

Naktibalda commented 7 years ago

Done #72

germanattanasio commented 7 years ago

🎉 1.4.0 is out.

Thanks @Naktibalda! thank-you

richielo commented 7 years ago

Thanks a lot for the help @Naktibalda @germanattanasio Close #71

Naktibalda commented 7 years ago

You have to click the button.