Closed febdev closed 5 years ago
You must bind receive method like this now:
controller.middleware.receive.use(
watsonMiddleware.receive.bind(watsonMiddleware),
);
Thanks heaps!
Hi @Naktibalda , What if i want to use message filtering with this new method? Can you give one sample with the new method? Thanks
It is exactly the same.
Do you mean it is the same as below,
const receiveMiddleware = (bot, message, next) => { if (message.type === 'direct_message') { watsonMiddleware.receive(bot, message, next); } else { next(); } };
slackController.middleware.receive.use(receiveMiddleware);
We don't need to bind receive method? Also, if i use the same method as above, it doesn't work.
Bind is only necessary if method is passed as parameter in order to allow it to access other fields of middleware.
It doesn't work as it is. Can you please provide with a sample?
Thanks
No, I can't give you another sample.
It doesn't work as it is. Please be more specific. Do you get an error or does it do nothing?
The first guess is that a value of message.type is not what you think it is, so do some debugging with console.log
.
I have moved from build 1.8.4 to 2.1.4 to allow new ICP4D token authentication. Now I am getting this error message below.
An error occurred in the receive middleware: TypeError: this.sendToWatson is not a function at Ware.<anonymous> (/Users/jinkim/Documents/deckard/deckard/node_modules/botkit-middleware-watson/src/index.ts:177:17) at Generator.next (<anonymous>) at /Users/jinkim/Documents/deckard/deckard/node_modules/botkit-middleware-watson/lib/index.js:23:71 at new Promise (<anonymous>) at __awaiter (/Users/jinkim/Documents/deckard/deckard/node_modules/botkit-middleware-watson/lib/index.js:19:12) at Ware.receive (/Users/jinkim/Documents/deckard/deckard/node_modules/botkit-middleware-watson/lib/index.js:126:16) at Ware.<anonymous> (/Users/jinkim/Documents/deckard/deckard/node_modules/wrap-fn/index.js:75:16) at Ware.<anonymous> (/Users/jinkim/Documents/deckard/deckard/node_modules/wrap-fn/index.js:57:27) at next (/Users/jinkim/Documents/deckard/deckard/node_modules/ware/lib/index.js:85:20) at /Users/jinkim/Documents/deckard/deckard/node_modules/wrap-fn/index.js:121:18
Nothing has changed on my end except using
import { WatsonMiddleware } from 'botkit-middleware-watson';
and changing fromconst watsonMiddleware = require('botkit-middleware-watson')...
toconst watsonMiddleware = new WatsonMiddleware(...
and adding babel preset to allow importing class.Any idea how to resolve this?