text: import { Meteor } from 'meteor/meteor';
  import { HTTP } from 'meteor/http';
  import { Users } from 'meteor/rocketchat:models';
  import { getMainBackendIngestURL } from 'meteor/rocketchat:utils';
  import { isLeader } from 'meteor/rocketchat:lib';
  
  import { Logger } from 'meteor/rocketchat:logger';
  const logger = new Logger('notifyAboutSpammers');
  
  Meteor.methods({
  	notifyAboutSpammers(from, till) {
  		const ingestURL = getMainBackendIngestURL();
  		logger.debug(ingestURL);
  		if (!ingestURL) {
  			logger.warn('ingestURL is undefined');
  			return;
  		}
  		if (Promise.await(isLeader())) {
  			const users = Users.findSpammersBetweenDates(from, till).fetch();
  			const userAnonymIds = [];
  			for (const user of users) {
  				logger.debug(user);
  				if (user.customFields) {
  					const { anonym_id: anonymId } = user.customFields;
  					if (anonymId) {
  						userAnonymIds.push(anonymId);
  					} else {
  						logger.error(`notifyAboutSpammers error: user with empty anonym_id, id=${ user._id }`);
  					}
  				}
  			}
  
  			const data = { method:'chatSpamDetected', params:userAnonymIds };
  			logger.debug(ingestURL, data);
  			if (userAnonymIds.length) {
  				try {
  					const result = HTTP.call('POST', ingestURL, { data, timeout: 1000 });
  					logger.log('http call result:', result);
  				} catch (err) {
  					logger.error('http call Error:', err);
  				}
  			}
  			return true;
  		}
  	},
  });
  