コード例 #1
0
        private async Task RunStepAsync(BehaviorContext context, IOutgoingService outgoingService, BehaviorStep step)
        {
            _logger.LogDebug($"Step: {step.Id} is running for client: {context.Client.Id} within bot: {context.ServiceContext.BotId}.");

            try
            {
                if (step.Command != null)
                {
                    if (step.Command.Type == Enums.BehaviorInstructionType.Instruction &&                  //todo: не учитываются кейсы отсутвия инструкции и системной команды в инструкции
                        !string.IsNullOrEmpty(step.Command?.Instruction) &&
                        !step.Command.Instruction.Equals(DefaultBehaviorInstructionNone))
                    {
                        await HandleInterpretationResult(await _interpreter.Interpret(step.Command, context.Dialog, context.Database, context.ServiceContext.TransportName), context);
                    }
                }

                if (!string.IsNullOrEmpty(step.Response))
                {
                    var response = await _interpreter.InsertEntityParameters(step.Response, context.Dialog, context.Database);

                    await outgoingService.SendAsync(response, context.Client.Id);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Behavior step failed. StepId: {step.Id}. BotId: {context.ServiceContext.BotId}. ClientId: {context.Client.Id}.");
                throw;
            }
        }