public TopicsRoot(IBotContext context) : base()
        {
            if (context.GetConversationState <TConversationState>().RootTopic == null)
            {
                context.GetConversationState <TConversationState>().RootTopic = new TState();
            }

            this.State = context.GetConversationState <TConversationState>().RootTopic;
        }
        protected override Task OnReceiveActivity(IBotContext context)
        {
            var msgActivity = context.Request.AsMessageActivity();

            if (msgActivity != null)
            {
                var myState = context.GetConversationState <MyState>();
                myState.TurnNumber++;

                // calculate something for us to return
                int length = (msgActivity.Text ?? string.Empty).Length;

                // return our reply to the user
                context.Reply($"[{myState.TurnNumber}] You sent {msgActivity.Text} which was {length} characters");
                return(Task.CompletedTask);
            }

            var convUpdateActivity = context.Request.AsConversationUpdateActivity();

            if (convUpdateActivity != null)
            {
                foreach (var newMember in convUpdateActivity.MembersAdded)
                {
                    if (newMember.Id != convUpdateActivity.Recipient.Id)
                    {
                        context.Reply("Hello and welcome to the echo bot.");
                    }
                }
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public async Task OnReceiveActivity(IBotContext context)
        {
            var msgActivity = context.Request.AsMessageActivity();

            if (msgActivity != null)
            {
                var conversationState = context.GetConversationState <EchoState>() ?? new EchoState();

                conversationState.TurnNumber++;

                // calculate something for us to return
                int length = (msgActivity.Text ?? string.Empty).Length;

                // simulate calling a dependent service that was injected
                await _myService.DoSomethingAsync();

                // return our reply to the user
                context.Reply($"[{conversationState.TurnNumber}] You sent {msgActivity.Text} which was {length} characters");
            }

            var convUpdateActivity = context.Request.AsConversationUpdateActivity();

            if (convUpdateActivity != null)
            {
                foreach (var newMember in convUpdateActivity.MembersAdded)
                {
                    if (newMember.Id != convUpdateActivity.Recipient.Id)
                    {
                        context.Reply("Hello and welcome to the echo bot.");
                    }
                }
            }
        }