<commit_before>this.processWebhookMessage = function(messageObj, user, defaultValues) {
	var attachment, channel, channels, channelType, i, len, message, ref, rid, room, roomUser, ret;
	ret = [];

	if (!defaultValues) {
		defaultValues = {
			channel: '',
			alias: '',
			avatar: '',
			emoji: ''
		};
	}

	channel = messageObj.channel || defaultValues.channel;

	channels = [].concat(channel);

	for (channel of channels) {
		channelType = channel[0];

		channel = channel.substr(1);

		switch (channelType) {
			case '#':
				room = RocketChat.models.Rooms.findOne({
					$or: [
						{
							_id: channel
						}, {
							name: channel
						}
					]
				});
				if (!_.isObject(room)) {
					throw new Meteor.Error('invalid-channel');
				}
				rid = room._id;
				if (room.t === 'c') {
					Meteor.runAsUser(user._id, function() {
						return Meteor.call('joinRoom', room._id);
					});
				}
				break;
			case '@':
				roomUser = RocketChat.models.Users.findOne({
					$or: [
						{
							_id: channel
						}, {
							username: channel
						}
					]
				}) || {};
				rid = [user._id, roomUser._id].sort().join('');
				room = RocketChat.models.Rooms.findOne({
					_id: {
						$in: [rid, channel]
					}
				});
				if (!_.isObject(roomUser) && !_.isObject(room)) {
					throw new Meteor.Error('invalid-channel');
				}
				if (!room) {
					Meteor.runAsUser(user._id, function() {
						Meteor.call('createDirectMessage', roomUser.username);
						room = RocketChat.models.Rooms.findOne(rid);
					});
				}
				break;
			default:
				throw new Meteor.Error('invalid-channel-type');
		}

		if (messageObj.attachments && !_.isArray(messageObj.attachments)) {
			console.log('Attachments should be Array, ignoring value'.red, messageObj.attachments);
			messageObj.attachments = undefined;
		}

		message = {
			alias: messageObj.username || messageObj.alias || defaultValues.alias,
			msg: _.trim(messageObj.text || messageObj.msg || ''),
			attachments: messageObj.attachments,
			parseUrls: messageObj.parseUrls !== undefined ? messageObj.parseUrls : !messageObj.attachments,
			bot: messageObj.bot,
			groupable: false
		};

		if (!_.isEmpty(messageObj.icon_url) || !_.isEmpty(messageObj.avatar)) {
			message.avatar = messageObj.icon_url || messageObj.avatar;
		} else if (!_.isEmpty(messageObj.icon_emoji) || !_.isEmpty(messageObj.emoji)) {
			message.emoji = messageObj.icon_emoji || messageObj.emoji;
		} else if (!_.isEmpty(defaultValues.avatar)) {
			message.avatar = defaultValues.avatar;
		} else if (!_.isEmpty(defaultValues.emoji)) {
			message.emoji = defaultValues.emoji;
		}

		if (_.isArray(message.attachments)) {
			ref = message.attachments;
			for (i = 0, len = ref.length; i < len; i++) {
				attachment = ref[i];
				if (attachment.msg) {
					attachment.text = _.trim(attachment.msg);
					delete attachment.msg;
				}
			}
		}

		var messageReturn = RocketChat.sendMessage(user, message, room);
		ret.push({ channel: channel, message: messageReturn });<commit_msg>Allow webhook to decide if message is groupable<commit_after>this.processWebhookMessage = function(messageObj, user, defaultValues) {
	var attachment, channel, channels, channelType, i, len, message, ref, rid, room, roomUser, ret;
	ret = [];

	if (!defaultValues) {
		defaultValues = {
			channel: '',
			alias: '',
			avatar: '',
			emoji: ''
		};
	}

	channel = messageObj.channel || defaultValues.channel;

	channels = [].concat(channel);

	for (channel of channels) {
		channelType = channel[0];

		channel = channel.substr(1);

		switch (channelType) {
			case '#':
				room = RocketChat.models.Rooms.findOne({
					$or: [
						{
							_id: channel
						}, {
							name: channel
						}
					]
				});
				if (!_.isObject(room)) {
					throw new Meteor.Error('invalid-channel');
				}
				rid = room._id;
				if (room.t === 'c') {
					Meteor.runAsUser(user._id, function() {
						return Meteor.call('joinRoom', room._id);
					});
				}
				break;
			case '@':
				roomUser = RocketChat.models.Users.findOne({
					$or: [
						{
							_id: channel
						}, {
							username: channel
						}
					]
				}) || {};
				rid = [user._id, roomUser._id].sort().join('');
				room = RocketChat.models.Rooms.findOne({
					_id: {
						$in: [rid, channel]
					}
				});
				if (!_.isObject(roomUser) && !_.isObject(room)) {
					throw new Meteor.Error('invalid-channel');
				}
				if (!room) {
					Meteor.runAsUser(user._id, function() {
						Meteor.call('createDirectMessage', roomUser.username);
						room = RocketChat.models.Rooms.findOne(rid);
					});
				}
				break;
			default:
				throw new Meteor.Error('invalid-channel-type');
		}

		if (messageObj.attachments && !_.isArray(messageObj.attachments)) {
			console.log('Attachments should be Array, ignoring value'.red, messageObj.attachments);
			messageObj.attachments = undefined;
		}

		message = {
			alias: messageObj.username || messageObj.alias || defaultValues.alias,
			msg: _.trim(messageObj.text || messageObj.msg || ''),
			attachments: messageObj.attachments,
			parseUrls: messageObj.parseUrls !== undefined ? messageObj.parseUrls : !messageObj.attachments,
			bot: messageObj.bot,
			groupable: (message.groupable !== undefined) ? messageObj.groupable : false
		};

		if (!_.isEmpty(messageObj.icon_url) || !_.isEmpty(messageObj.avatar)) {
			message.avatar = messageObj.icon_url || messageObj.avatar;
		} else if (!_.isEmpty(messageObj.icon_emoji) || !_.isEmpty(messageObj.emoji)) {
			message.emoji = messageObj.icon_emoji || messageObj.emoji;
		} else if (!_.isEmpty(defaultValues.avatar)) {
			message.avatar = defaultValues.avatar;
		} else if (!_.isEmpty(defaultValues.emoji)) {
			message.emoji = defaultValues.emoji;
		}

		if (_.isArray(message.attachments)) {
			ref = message.attachments;
			for (i = 0, len = ref.length; i < len; i++) {
				attachment = ref[i];
				if (attachment.msg) {
					attachment.text = _.trim(attachment.msg);
					delete attachment.msg;
				}
			}
		}

		var messageReturn = RocketChat.sendMessage(user, message, room);
		ret.push({ channel: channel, message: messageReturn });
{'fraction_non_alphanumeric': 0.15539544784673326, 'fraction_numerical': 0.0009824791223186507, 'mean_word_length': 3.029023746701847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7589416', 'n_tokens_mistral': 2543, 'n_tokens_neox': 1990, 'n_words': 378}