microsoft / ConversationLearner-SDK

An SDK for ConversationLearner. REPOSITORY MOVED
https://github.com/microsoft/conversationlearner
MIT License
26 stars 9 forks source link

Translation Middleware not working properly #260

Open Arincon opened 6 years ago

Arincon commented 6 years ago

I was working on a demo bot from one of the samples on ConversationLearner-Samples , and I noticed some strange behaviour.

I added Translation Middleware (like this: v4 JS Translation Docs) and I have had one main problem. The problem appears when you train ConversationLearner to send to the user many messages in a row (without waiting for the user to reply). In this scenario, the first message is translated back to the user language, but the rest remain in english. I digged into the code to find the cause, and as I see, the problem is with the context. The translation middleware is adding a "listener" to the context, which executes every time a message is sent to the user. However, as you can see in CLRunner.ts:650, in all messages excepting the first, what CL SDK is doing is resuming the conversation, and getting a context from the ConversationReference object. My suspicion is that this context doesn't have, for some reason, any middleware attached.

Any clue on this?

Thank you in advance.

Arincon commented 6 years ago

What Translation Middleware is doing is basically this:

context.onSendActivities(async (newContext, activities, newNext) => {
                await Promise.all(activities.map(async (activity) => {
                    if (activity.type == ActivityTypes.Message) {
                        await this.translateMessageAsync(newContext, activity, targetLanguage, sourceLanguage);
                    }
                }));

                return newNext();
            })
LarsLiden commented 6 years ago

Nice catch. I'll take a look. (Ref: 1355)

Arincon commented 5 years ago

Any update on this?

Thank you in advance!

LarsLiden commented 5 years ago

We've been waiting for the release version of BB v4 to come out (which it just did at Ignite). As soon as we move over to this, we'll tackle this issue. Thanks for your patience.

msft-shahins commented 5 years ago

With recent changes to CL-SDK, translation middleware should work for log dialogs and user sessions, i.e. messages sent to bot using emulator or bot framework channels. Here is a sample showing how translation middleware can be used in a CL-based bot. Note that middleware pipeline is currently bypassed when sending messages to the bot using CL teach UI.

Also current changes are released under @next tag of CL-SDK and have breaking changes. Next stable release of SDK should resolve this issue.

Arincon commented 5 years ago

With recent changes to CL-SDK, translation middleware should work for log dialogs and user sessions, i.e. messages sent to bot using emulator or bot framework channels. Here is a sample showing how translation middleware can be used in a CL-based bot. Note that middleware pipeline is currently bypassed when sending messages to the bot using CL teach UI.

Also current changes are released under @next tag of CL-SDK and have breaking changes. Next stable release of SDK should resolve this issue.

Many thanks! When I have some time to test it i will let you know.