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

using 2 workspaces watson #100

Closed chakir-alaoui closed 7 years ago

chakir-alaoui commented 7 years ago

i want to identify the input language and then in my backend select the specific workspace to keep the conversation, but i can't switch to the other workspace.

after detecting user language , i export it with module.exports.language to my app.js but when i use console.log to display the language : language undefined

Please suggest the best approach to achieve this.

aarora91 commented 7 years ago

Hi @chakir-alaoui,

I believe you don't need to change the receive middleware based on the language. All you'd have to do is change the way you're initializing the middleware object (in app.js)

Just change the workspace_id based on the result of your regex eval and use it for initializing the middleware obj like it's done here: https://github.com/watson-developer-cloud/botkit-middleware/blob/master/examples/multi-bot/app.js#L22

Let me know if that didn't help or you need more info. Good luck!

aarora91 commented 7 years ago

Ah I see. Then you're right, it must be done before the message is sent to Conversation. Did you try re-initializing the middleware.conversation object inside middleware.before function? If you over-write it there with the appropriate workspace_id it should pick it up when postMessage is invoked. Give that a try..also if you run the code with the debug string 'watson-middleware:index' then it should print all debug statements inside https://github.com/watson-developer-cloud/botkit-middleware/blob/master/lib/middleware/index.js