Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

need help with migration #60

Closed
pgoldweic opened this issue Oct 24, 2019 · 10 comments
Closed

need help with migration #60

pgoldweic opened this issue Oct 24, 2019 · 10 comments

Comments

@pgoldweic
Copy link

I understand this repository has been deprecated, but I'm wondering what's the best way forward in order to update a (production) bot built with this starter kit (version 0.0.1, which depended on botkit 0.6.12) in order to avoid the associated vulnerabilities, and remain open source? (with minimal code redevelopment).
Also, if wanting to upgrade to current open source versions of the above packages/starter kit (with possibly more code redevelopment work involved), which ones should I use?

@benbrown
Copy link
Contributor

You should update your code to use botkit 0.7.5. This should be compatible with your starter kit code.

If you want to update to the latest version, use the yeoman command yo botkit described here: https://botkit.ai/getstarted.html

@pgoldweic
Copy link
Author

Great. Thanks!

@pgoldweic
Copy link
Author

Sorry! I forgot to mention a couple of things:

  • what was the main difference (in terms of functionality) between botkit 0.6 and 0.7? (since I've done some storage customizations to that provided by botkit-starter-web, I wonder if there be something important I should know about this).
    Also, I'm watson-middleware for botkit (version 1.8.2). If you are aware of something in botkit 0.7.5 that may not work well with that version of the middleware, please let me know.
    Thanks again for all your help!

@benbrown
Copy link
Contributor

@pgoldweic you can check the changelog here:

https://github.com/howdyai/botkit/blob/master/changelog.md#074

There were no major changes - just feature updates, bug fixes, etc.

The middleware should still work as far as I know. No breaking changes were introduced.

@pgoldweic
Copy link
Author

Yes, I was just looking into the change log myself, but not seeing what happened with 0.7.5 though. Thanks for confirming this! Glad that I can upgrade to that version and not have to rewrite my code. Thanks again!

@benbrown
Copy link
Contributor

@pgoldweic 0.7.4 is actually the latest version.

We will do a 0.7.5 at some point soon. An effort is currently underway.

@pgoldweic
Copy link
Author

Sorry to resurrect this thread. I'm now considering a move to the latest Botkit version, and are wondering what are the components that I will need to install, given that I want to continue to have a web adapter with associated chat client (a la botkit-for-the-web, for botkit 0.7+) and not loose any functionality (while keeping it open sourc)e - although it would be great to gain in functionality, of course!- While I've seen the current documentation, it's non trivial to understand how to achieve these goals, and how the two options compare (both in features + open source nature, etc.). Any help with this will be appreciated. My current stack includes botkit 0.75, botkit-for-the-web, botkit-middleware-watson 1.8.2. Thanks!

@Naktibalda
Copy link
Contributor

I don't remember specifics of how I upgraded to Botkit 4 anymore and I haven't touched any Botkit related code for almost a year, but here is what I see in the old pull request.

I upgraded to botkit 4 and botkit-middleware-watson 2, and installed botbuilder-adapter-web.

My bots were originally written in Typescript, so upgrading to Typescript based Botkit and middleware made my code cleaner. If your code is written in Javascript, your experience may differ.

I kept the same frontend code, but I had to change message.attachments.quick_replies to message.quick_replies.

In backend I had to use different Storage Adapter.

I replaced my botkit initialization code with

const Botkit = require('botkit');
const { WebAdapter } = require('botbuilder-adapter-web');
const MemoryStorage = require('botbuilder-core').MemoryStorage;

const adapter = new WebAdapter();
const controller = new Botkit.Botkit({
    adapter: adapter,
    storage: new MemoryStorage(),
    replyWithTyping: process.env.REPLY_WITH_TYPING && process.env.REPLY_WITH_TYPING === 'true'
});

controller.publicFolder('/','public');

Middleware initialization code has changed from

import createWatsonMiddleware = require('botkit-middleware-watson');

    const watsonMiddleware = createWatsonMiddleware({
        username: process.env.CONVERSATION_USERNAME,
        password: process.env.CONVERSATION_PASSWORD,
        workspace_id: process.env.WORKSPACE_ID,
        version_date: '2017-05-26',
        url: process.env.CONVERSATION_URL || 'https://gateway.watsonplatform.net/conversation/api',
    });

    controller.middleware.receive.use(watsonMiddleware.receive);

to

import {WatsonMiddleware} from 'botkit-middleware-watson';

    const watsonMiddleware = new WatsonMiddleware({
        username: process.env.CONVERSATION_USERNAME,
        password: process.env.CONVERSATION_PASSWORD,
        workspace_id: process.env.WORKSPACE_ID,
        version: '2017-05-26',
        url: process.env.CONVERSATION_URL || 'https://gateway.watsonplatform.net/conversation/api',
    });

    controller.middleware.receive.use(watsonMiddleware.receive.bind(watsonMiddleware));

I used format middleware instead of send middleware for logging responses.

I replaced all promises with async/await, but not sure if it was because it was necessary or because I just wanted to use async/await.
@benbrown told me that async was necessary to fix some bug with delayed responses, but it turned out that changeContext was necessary for that. It was documented in https://botkit.ai/docs/v4/core.html#sending-alerts-and-scheduled-messages
I can't find any calls to changeContext in my code base and watson middleware now though :)

I used MemoryStorage adapter as replacement for Botkit's in-memory store originally (see code above)
and replaced it with Redis store later

const {RedisDbStorage} = require('botbuilder-storage-redis');

const redisClient = redis.createClient(process.env.REDIS_URL, {prefix: 'bot-storage:'});
redisClient.on("error", function (err) {
  console.log("Redis error: " + err);
});
const redisTtlInSeconds = process.env.REDIS_TTL || 3600;
storage = new RedisDbStorage(redisClient, redisTtlInSeconds);

I actually used fork published to private npm registry, because it took 4 months to merge my pull request and it isn't clear if ttl feature was actually released.

@pgoldweic
Copy link
Author

Thanks so much @Naktibalda for your input once again! This should definitely help me a lot as I start the conversion work. Thanks again!

@pgoldweic
Copy link
Author

Hi again @Naktibalda . Your code above does not show how you handled the Express instance with Botkit 4+ (I assume that your application was originally based on botkit-starter-web, correct? I am wondering about the peculiarities of using a custom Express instance given the lack of detailed documentation (e.g. are there any downsides, do I need to set 'disable_webserver' in Botkit's constructor?, etc.) . Take a look at my post at #63 . Do you have any comments on this? (BTW, I've also posted in the Botkit Slack Channel).

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

No branches or pull requests

3 participants