Beispiel #1
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var _lineText = turnContext.Activity.Text.ToLower();

            var matchFound = DialogEnum.Words.ReservedStrings.Where(w => _lineText.Contains(w)).FirstOrDefault();

            if (matchFound != null)
            {
                switch (matchFound)
                {
                case DialogEnum.Words.Meniu:
                    var attachments         = new List <Attachment>();
                    var replyToConversation = MessageFactory.Attachment(attachments);
                    replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                    userDataService = new UserDataService(configuration);
                    var _data = userDataService.GetMenuItems();

                    foreach (var item in _data)
                    {
                        replyToConversation.Attachments.Add(GetHeroCard(item).ToAttachment());
                    }

                    await turnContext.SendActivityAsync(replyToConversation, cancellationToken);

                    //reply.Type = ActivityTypes.Typing;
                    //reply.Text = null;
                    //await turnContext.SendActivityAsync(reply, cancellationToken);

                    //userDataService = new UserDataService(configuration);
                    //var _data = userDataService.GetMenuItems();

                    //AdaptiveCard adaptiveCard = BuildMenuAdaptiveCard(_data);
                    //var heroCard = BuildMenuHeroCard(_data);

                    //var _menuCard = CreateAdaptiveCardAttachment(adaptiveCard);
                    //var response = MessageFactory.Attachment(_menuCard);
                    //await turnContext.SendActivityAsync(response, cancellationToken);
                    break;


                case DialogEnum.Words.Total:
                    userDataService = new UserDataService(configuration);
                    decimal _total = userDataService.WeeklyTotal(turnContext.Activity.From.Name);

                    if (_total > 0)
                    {
                        await turnContext.SendActivityAsync(new Activity()
                        {
                            Type = ActivityTypes.Message,
                            Text = $"{turnContext.Activity.From.Name}, suma comenzilor pentru saptamana aceasta este: {_total} Lei"
                        }, cancellationToken);
                    }
                    else
                    {
                        await turnContext.SendActivityAsync(new Activity()
                        {
                            Type = ActivityTypes.Message,
                            Text = $"{turnContext.Activity.From.Name}, nu ai comandat nimic pana acum"
                        }, cancellationToken);
                    }
                    break;

                case DialogEnum.Words.Del:
                    userDataService = new UserDataService(configuration);
                    userDataService.DeleteOrder(turnContext.Activity.From.Name);
                    await turnContext.SendActivityAsync(new Activity()
                    {
                        Type = ActivityTypes.Message,
                        Text = $"{turnContext.Activity.From.Name}, comanda ta a fost stearsa"
                    }, cancellationToken);

                    break;


                case DialogEnum.Words.Test:
                    break;
                }
            }
            else
            {
                string line    = turnContext.Activity.Text.ToLower();
                string user    = turnContext.Activity.From.Name;
                string comanda = string.Empty;
                userDataService = new UserDataService(configuration);
                if (ProcessLine(line, user, userDataService, out comanda))
                {
                    await turnContext.SendActivityAsync(new Activity()
                    {
                        Type = ActivityTypes.Message,
                        Text = $"Comanda pentru {user} este: {comanda}"
                    }, cancellationToken);
                }
            }
        }