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
207 stars 255 forks source link

How can I connect Watson and facebook using only botkit, not botkit-middleware-watson #150

Closed developer-bz closed 5 years ago

developer-bz commented 5 years ago

Hi,

I have already used botkit-middleware-watson, it's great. Now what I would want to know is how can i send facebook messages to watson and back and forth using just botkit, not the middleware.

Thanks in advance

Naktibalda commented 5 years ago

It's an odd question to ask. Why do you want to avoid using middleware?

developer-bz commented 5 years ago

Dear Naktibalda,

It's a business requirement. Can you please let me know if it is achievable or not? If yes, please provide an example

Thanks in advance

Naktibalda commented 5 years ago

A business requirement to connect Botkit to Watson Assistant without using this middleware? Your best option is to clone and rebrand it. Or you can start from scratch.

Are you allowed to use watson-node-sdk?

developer-bz commented 5 years ago

Thing is that we can replace watson with something else anytime. Hope this helps.

Thanks in advance

Naktibalda commented 5 years ago

Ah, you want abstraction.

In that case, you can still use this middleware, but you must avoid using any Watson specific properties of the message and avoid calling any methods of middleware.

The only Watson specific thing that you can't avoid using is message.watsonData.output.text, You could write your own wrapper for this middleware and all other middlewares that you want to support to transform response to common format.

developer-bz commented 5 years ago

Can you please elaborate on how I can do it? I am not getting a clear idea.

Thanks

On Wed, Nov 7, 2018 at 3:06 PM Gintautas Miselis notifications@github.com wrote:

It's an odd question to ask. Why do you want to avoid using middleware?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/watson-developer-cloud/botkit-middleware/issues/150#issuecomment-436602186, or mute the thread https://github.com/notifications/unsubscribe-auth/ARcC-i6tBcotWmx0gy6grcllLEIY4mnTks5ussyzgaJpZM4YSSNZ .

Naktibalda commented 5 years ago

I am using example of middleware wrapper from https://github.com/watson-developer-cloud/botkit-middleware#using-middleware-wrapper

So it would look like this:

var watsonWrapper = function (bot, message, next) {
  watsonMiddleware.receive(bot, message, function() {
      if (message.watsonData.output.text) {
          message.replyText = message.watsonData.output.text.join('\n');
      }
      next();
  })
};

// here you tell botkit which wrapper to use
slackController.middleware.receive.use(watsonWrapper);

// and this part is independent of NLP middleware
slackController.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], function(bot, message) {
  if (message.replyText) {
    bot.reply(message, message.replyText);
  }
});

You would have to implement wrappers for other NLP middlewares too to assign response to message.replyText. It is up to you to do that and to test this code.

germanattanasio commented 5 years ago

Closing since this is not a problem with this library or a question related to Watson Assistant