Example #1
0
        private async Task UpdateActivityInternal(Activity activity,
                                                  IEnumerable <UpdateActivityHandler> updateHandlers,
                                                  Func <Task> callAtBottom)
        {
            BotAssertSlack.ActivityNotNull(activity);
            if (updateHandlers == null)
            {
                throw new ArgumentException(nameof(updateHandlers));
            }

            if (updateHandlers.Count() == 0) // No middleware to run.
            {
                if (callAtBottom != null)
                {
                    await callAtBottom();
                }

                return;
            }

            // Default to "No more Middleware after this".
            async Task next()
            {
                // Remove the first item from the list of middleware to call,
                // so that the next call just has the remaining items to worry about.
                IEnumerable <UpdateActivityHandler> remaining = updateHandlers.Skip(1);

                await UpdateActivityInternal(activity, remaining, callAtBottom).ConfigureAwait(false);
            }

            // Grab the current middleware, which is the 1st element in the array, and execute it
            UpdateActivityHandler toCall = updateHandlers.First();

            await toCall(this, activity, next);
        }
Example #2
0
        /// <summary>
        /// Creates a conversation reference from an activity.
        /// </summary>
        /// <param name="activity">The activity.</param>
        /// <returns>A conversation reference for the conversation that contains the activity.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="activity"/> is <c>null</c>.</exception>
        public static ConversationReference GetConversationReference(Activity activity)
        {
            BotAssertSlack.ActivityNotNull(activity);

            ConversationReference r = new ConversationReference
            {
                ActivityId   = activity.Id,
                User         = activity.From,
                Bot          = activity.Recipient,
                Conversation = activity.Conversation,
                ChannelId    = activity.ChannelId,
                ServiceUrl   = activity.ServiceUrl
            };

            return(r);
        }