/// <inheritdoc/> public bool Filter(Message message) { var chatIsPrivate = message.Chat.Type == ChatType.Private; if (chatIsPrivate) { return(_nextFilter.Filter(message)); } var botUserName = _settingProvider.GetBotUserName(); if (string.IsNullOrEmpty(botUserName)) { throw new InvalidOperationException("The bot name must be provided for it to accept commands from group chats"); } var entities = message.GetEntities(); var mentions = entities.Where(entity => entity.Type == MessageEntityType.Mention); var botMentionFound = mentions.Any(m => m.Value.Equals(botUserName, StringComparison.InvariantCultureIgnoreCase)); if (botMentionFound) { return(_nextFilter.Filter(message)); } var commands = entities.Where(entity => entity.Type == MessageEntityType.BotCommand); var commandHasMention = commands.Any(c => c.Value.Contains(botUserName, StringComparison.InvariantCultureIgnoreCase)); if (commandHasMention) { return(_nextFilter.Filter(message)); } return(false); }
public static string ApplyTo(this IMessageFilter messageFilter, string message) { if (messageFilter != null) { return(messageFilter.Filter(message)); } return(message); }
/// <inheritdoc/> public bool Filter(Message message) { if (message.Type != Telegram.Bot.Types.Enums.MessageType.Text) { return(false); } return(_nextFilter.Filter(message)); }
/// <inheritdoc/> public bool Filter(Message message) { if (message.Chat.Type == ChatType.Supergroup || message.Chat.Type == ChatType.Channel) { return(false); } return(_nextFilter.Filter(message)); }
/// <inheritdoc/> public bool Filter(Message message) { var botMessage = MessageConverter.Convert(message); if (_processors.IsRelevantToAny(botMessage)) { return(true); } return(_nextFilter.Filter(message)); }
private IEnumerable <Data.Message> ToModels(IEnumerable <Xml.Message> xMessages) { IEnumerable <Xml.Message> filteredMessages = _messageFilter != null?_messageFilter.Filter(xMessages).ToList() : xMessages; return(filteredMessages.Select(m => ToModel(m))); }