Как избежать прерываний от Луиса во время диалога с водопадом (BotFramework v4) - PullRequest
0 голосов
/ 13 октября 2018

Как мне запретить Луису инициировать намерение в Bot Framework v4?Например, когда вы задаете пользователю вопрос / используете подсказку типа "как вас зовут?"или «Какой у вас почтовый индекс?»

В версии 3 это можно сделать следующим образом:

var recognizer = new builder.LuisRecognizer(url) 
    .onEnabled(function (context, callback) {
        // LUIS is only ON when there are no tasks pending(e.g. Prompt text) 
        var enabled = context.dialogStack().length === 0; 
        callback(null, enabled); 
    });

( ссылка )

в версии 4, вот мой распознаватель:

this.luisRecognizer = new LuisRecognizer({
            applicationId: luisConfig.appId,
            endpoint: luisConfig.getEndpoint(),
            endpointKey: luisConfig.authoringKey
        });

Я думаю, мне нужно создать это как промежуточное ПО, которое проверяет, существует ли состояние диалога, а затем отключить / повторно включить Луиса ...?

1 Ответ

0 голосов
/ 17 декабря 2018

В главном диалоговом окне (которое вы используете для распознавания намерений LUIS) проверьте свой контекст, чтобы увидеть, есть ли какое-либо активное диалоговое окно:

async onTurn(context) {
    // Create dialog context.
    const dc = await this.dialogs.createContext(context);
    // By checking the incoming Activity type, the bot only calls LUIS in appropriate cases.
    if (context.activity.type === ActivityTypes.Message) {
        // Normalizes all user's text inputs
        const utterance = context.activity.text.trim().toLowerCase();

        // handle conversation interrupts first
        const interrupted = await this.isTurnInterrupted(dc, utterance);
        if (!interrupted) {
            // Continue the current dialog
            const dialogResult = await dc.continueDialog();

            // If no one has responded,
            if (!dc.context.responded) {
                // Examine results from active dialog
                switch (dialogResult.status) {
                    case DialogTurnStatus.empty:
                        // Call to LUIS recognizer to get intent + entities
                        const results = await this.luisRecognizer.recognize(dc.context);
                        // Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
                        const topIntent = results.luisResult.topScoringIntent;

                        switch (topIntent.intent) {
                            case SMALLTALK_INTENT:
                                return await dc.beginDialog(SmallTalkDialog.Name);
                            ...
                        }
                    case DialogTurnStatus.waiting:
                        // The active dialog is waiting for a response from the user, so do nothing
                        break;
                    case DialogTurnStatus.complete:
                        await dc.endDialog();
                        break;
                    default:
                        await dc.cancelAllDialogs();
                        break;
                }
            }
        }
    } else if (context.activity.type === ActivityTypes.ConversationUpdate &&
        context.activity.recipient.id !== context.activity.membersAdded[0].id) {
        // If the Activity is a ConversationUpdate, send a greeting message to the user.
        await context.sendActivity('¡Hola! ¿En qué puedo ayudarte? ?');
    } else if (context.activity.type !== ActivityTypes.ConversationUpdate) {
        // Respond to all other Activity types.
        //await context.sendActivity(`[${ context.activity.type }]-type activity detected.`);
        //await this.authDialog.onTurn(context);
    }
    // Save state changes
    await this.conversationState.saveChanges(context);
  }

Надеюсь, это поможет.

...