Exemple #1
0
        public async Task RespondToExecution(IExecutorResponse response)
        {
            if (!response.IsSomethingFound)
            {
                await this.Context.SendActivity("Sorry, but nothing was found :(");

                return;
            }

            if (response.StringResponse != null)
            {
                await this.Context.SendActivity(response.StringResponse).ConfigureAwait(false);
            }

            if (response.CafesResponse != null && response.CafesResponse.Any())
            {
                await this.RespondToCaffe(response.CafesResponse).ConfigureAwait(false);
            }

            if (response.MenuViewModels != null && response.MenuViewModels.Any())
            {
                await this.RespondToMenu(response.MenuViewModels).ConfigureAwait(false);
            }

            if (response.FreedgeRecords != null && response.FreedgeRecords.Any())
            {
                await this.RespondToFreedgeRecords(response.FreedgeRecords).ConfigureAwait(false);
            }

            if (response.VoteResponses != FridgeVoteResponses.Undefined)
            {
                await this.RespondToPositionVote(response.VoteResponses).ConfigureAwait(false);
            }

            if (response.AddResponses != FridgeAddResponses.Undefined)
            {
                await this.RespondToAddPosition(response.AddResponses).ConfigureAwait(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Every Conversation turn for our EchoBot will call this method. In here
        /// the bot checks the Activty type to verify it's a message, bumps the
        /// turn conversation 'Turn' count, and then echoes the users typing
        /// back to them.
        /// </summary>
        /// <param name="context">Turn scoped context containing all the data needed
        /// for processing this conversation turn. </param>
        public async Task OnTurn(ITurnContext context)
        {
            // This bot is only handling Messages
            if (context.Activity.Type == ActivityTypes.Message)
            {
                // Get the conversation state from the turn context
                var state = context.GetConversationState <EchoState>();

                // Bump the turn count.
                state.TurnCount++;
                // var result = await _service.GetAllCaffes().ConfigureAwait(false);
                //var t = result.Select(x=> x.Name).ToList();
                // Echo back to the user whatever they typed.


                IExecutorResponse response = await _executor.GetResponse(context.Activity.Text, context.Activity.Conversation.Id);

                Visualizer responder = new Visualizer(context);

                await responder.RespondToExecution(response);
            }
        }
Exemple #3
0
        public async Task <IExecutorResponse> GetResponse(string command, params object[] param)
        {
            IExecutorResponse result = null;

            foreach (IPhraseProcessor processor in Processors)
            {
                try
                {
                    result = await processor.ExecuteCommandAsync(command, param);
                }
                catch (Exception ex)
                {
                    //do nothing
                }

                if (result != null)
                {
                    return(result);
                }
            }

            return(new ExecutorResponse(StringConstants.CAN_NOT_PARSE_REQUEST));
        }