protected async routeStep()

in templates/typescript/generator-bot-virtualassistant/generators/skill/templates/sample-skill/src/dialogs/_mainDialog.ts [199:264]


    protected async routeStep(stepContext: WaterfallStepContext): Promise<DialogTurnResult> {
        
        //PENDING: This should be const activity: IMessageActivity = innerDc.context.activity.asMessageActivity()
        // but it's not in botbuilder-js currently
        const activity: Activity = stepContext.context.activity;

        if (activity.type === ActivityTypes.Message && activity.text !== undefined && activity.text.trim().length > 0) {
            // Get current cognitive models for the current locale.
            const localizedServices: Partial<ICognitiveModelSet> = this.services.getCognitiveModels(stepContext.context.activity.locale as string);

            // Get skill LUIS model from configuration.
            const luisService: LuisRecognizer | undefined = localizedServices.luisServices? localizedServices.luisServices.get('<%=skillNameCamelCase%>') : undefined;

            if (luisService !== undefined){
                const result = stepContext.context.turnState.get(this.stateProperties.skillLuisResult);
                const intent: string = LuisRecognizer.topIntent(result);
                switch(intent) {
                    case 'Sample': { 

                        return await stepContext.beginDialog(this.sampleDialog.id);
                    } 
                    case 'None': 
                    default: {
                        // intent was identified but not yet implemented
                        await stepContext.context.sendActivity(this.templateEngine.generateActivityForLocale('UnsupportedMessage', stepContext.context.activity.locale));
                        return await stepContext.next();
                    }
                }  
            } else {
                throw new Error('The specified LUIS Model could not be found in your Bot Services configuration.');
            } 
        } else if (activity.type === ActivityTypes.Event) {
            // PENDING const ev = activity.AsEventActivity();
            const ev = activity;
            if (ev.name !== undefined && ev.name.trim().length > 0 ) {
                switch (ev.name) {      
                    case 'SampleAction': {
                        let actionData: Object = {};

                        if (ev.value !== undefined) {
                            actionData = ev.value as SampleActionInput;
                        }

                        // Invoke the SampleAction dialog passing input data if available
                        return await stepContext.beginDialog(SampleAction.name, actionData);
                    }

                    default: {
                        await stepContext.context.sendActivity({ 
                            type: ActivityTypes.Trace, 
                            text: `Unknown Event ${ ev.name ? ev.name : 'undefined' } was received but not processed.`                       
                        });
                        break;
                    }  
                }
            } else {
                await stepContext.context.sendActivity({
                    type: ActivityTypes.Trace, 
                    text: 'An event with no name was received but not processed.'
                });
            }
        }
        
        // If activity was unhandled, flow should continue to next step
        return await stepContext.next();
    }