예제 #1
0
        /// <summary>
        /// Passes an update to the chain for handling
        /// </summary>
        /// <param name="args">Data structure containing relevant references for update handling</param>
        public async Task Handle(UpdateHandlerArgs args)
        {
            // Catch exceptions so they don't cause the entire service to crash
            try
            {
                if ((null == HandlesUpdateType) || (args.Update.Type == HandlesUpdateType))
                {
                    await HandlerLogicImpl(args);
                }
            }
            catch (Exception e)
            {
                await Say.Error($"Internal error while handling update {args.Update.Id}: {e.Message}");
            }

            // End of the chain has reached as soon as the update has been marked as handled
            if (args.Handled)
            {
                return;
            }

            // Invoke next handler in chain, otherwise throw Exception that update was not handled
            if (null != _nextHandler)
            {
                await _nextHandler.Handle(args);
            }
            else
            {
                throw new UpdateNotHandledException(args.Update);
            }
        }
        /// <summary>
        /// Filters for supported commands
        /// </summary>
        protected override async Task MessageUpdateHandlerLogicImpl(UpdateHandlerArgs args)
        {
            if (!HandlesCommands.Contains(args.MessageArgs.CommandTokens[0].Trim().ToLower()))
            {
                return;
            }

            await CommandTextMessageUpdateHandlerLogicImpl(args);
        }
        /// <summary>
        /// Basic filtering for messages of type MessageUpdateType
        /// </summary>
        protected override async Task HandlerLogicImpl(UpdateHandlerArgs args)
        {
            if (null != HandlesMessageType)
            {
                if (args.MessageArgs.Message.Type != HandlesMessageType)
                {
                    return;
                }
            }

            await MessageUpdateHandlerLogicImpl(args);
        }
예제 #4
0
 /// <summary>
 /// Implements the actual logic for handling upats
 /// </summary>
 /// <param name="args">Data structure containing relevant references for update handling</param>
 protected abstract Task HandlerLogicImpl(UpdateHandlerArgs args);
 /// <summary>
 /// Implements the logic for the selected commands
 /// </summary>
 protected abstract Task CommandTextMessageUpdateHandlerLogicImpl(UpdateHandlerArgs args);