예제 #1
0
        public async Task Test_Sample_Action_w_Input()
        {
            var actionInput = new SampleActionInput()
            {
                Name = "test"
            };

            await GetSkillTestFlow()
            .Send(new Activity(type: ActivityTypes.Event, name: "SampleAction", value: JObject.FromObject(actionInput)))
            .AssertReplyOneOf(GetTemplates("HaveNameMessageText", new { actionInput.Name }))
            .AssertReply((activity) =>
            {
                var a = (Activity)activity;
                Assert.AreEqual(ActivityTypes.EndOfConversation, a.Type);
                Assert.AreEqual(typeof(SampleActionOutput), a.Value.GetType());
            })
            .StartTestAsync();
        }
        // Handles routing to additional dialogs logic.
        private async Task <DialogTurnResult> RouteStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var activity = stepContext.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get current cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Get skill LUIS model from configuration.
                localizedServices.LuisServices.TryGetValue("$safeprojectname$", out var luisService);

                if (luisService != null)
                {
                    var result = stepContext.Context.TurnState.Get <$safeprojectname$Luis>(StateProperties.SkillLuisResult);
                    var intent = result?.TopIntent().intent;

                    switch (intent)
                    {
                    case $safeprojectname$Luis.Intent.Sample:
                    {
                        return(await stepContext.BeginDialogAsync(_sampleDialog.Id, cancellationToken : cancellationToken));
                    }

                    case $safeprojectname$Luis.Intent.None:
                    default:
                    {
                        // intent was identified but not yet implemented
                        await stepContext.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("UnsupportedMessage"), cancellationToken);

                        return(await stepContext.NextAsync(cancellationToken : cancellationToken));
                    }
                    }
                }
                else
                {
                    throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
                }
            }
            else if (activity.Type == ActivityTypes.Event)
            {
                var ev = activity.AsEventActivity();

                if (!string.IsNullOrEmpty(ev.Name))
                {
                    switch (ev.Name)
                    {
                    case "SampleAction":
                    {
                        SampleActionInput actionData = null;

                        if (ev.Value is JObject eventValue)
                        {
                            actionData = eventValue.ToObject <SampleActionInput>();
                        }

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

                    default:
                    {
                        await stepContext.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{ev.Name ?? "undefined"}' was received but not processed."), cancellationToken);

                        break;
                    }
                    }
                }
                else
                {
                    await stepContext.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : "An event with no name was received but not processed."), cancellationToken);
                }
            }

            // If activity was unhandled, flow should continue to next step
            return(await stepContext.NextAsync(cancellationToken : cancellationToken));
        }