<commit_before>'use strict';

// load .env variables if set
require('dotenv').config();

const config = require('config');
const rp = require('request-promise-native');

module.exports.notify = function(restaurants) {

  let content = createContentFrom(restaurants),
      completeWebhook = process.env.SLACK.concat(process.env.WEBHOOK),
      options = {
        method: 'POST',
        uri: completeWebhook,
        form: { 
          payload: JSON.stringify(content)
        }
      };

  return rp(options)
    .then(function(body) {
      return { message: 'Slack message sent' };
    })
    .catch(function(error) {
      console.log(error.message);
      throw error;
    });
};

function createContentFrom(restaurants) {
  return {
    'text'       : { toString: () => '' }, // only way to have no text without attachment fallback
    'channel'    : config.has('slack.channel') ? config.get('slack.channel') : undefined,
    'username'   : config.get('slack.username'),
    'icon_emoji' : config.get('slack.icon_emoji'),
    'attachments': restaurants.map(restaurant => (
      {
        'title'     : restaurant.name,
        'title_link': restaurant.url,
        'fallback'  : config.get('slack.fallback'),
        'color'     : restaurant.color,
        'mrkdwn_in' : ['text', 'pretext', 'fields'],
        'fields'    : restaurant.offers.map(offer => (
          {
            'title' : offer.title,
            'value' : offer.description,
            'short' : true,
          }
        )),
        'footer': restaurant.parser.name,
        'ts': Math.round((new Date).getTime() / 1000)
      }
    ))
  };
}
<commit_msg>Remove text field from payload<commit_after>'use strict';

// load .env variables if set
require('dotenv').config();

const config = require('config');
const rp = require('request-promise-native');

module.exports.notify = function(restaurants) {

  let content = createContentFrom(restaurants),
      completeWebhook = process.env.SLACK.concat(process.env.WEBHOOK),
      options = {
        method: 'POST',
        uri: completeWebhook,
        form: { 
          payload: JSON.stringify(content)
        }
      };

  return rp(options)
    .then(function(body) {
      return { message: 'Slack message sent' };
    })
    .catch(function(error) {
      console.log(error.message);
      throw error;
    });
};

function createContentFrom(restaurants) {
  return {
    'channel'    : config.has('slack.channel') ? config.get('slack.channel') : undefined,
    'username'   : config.get('slack.username'),
    'icon_emoji' : config.get('slack.icon_emoji'),
    'attachments': restaurants.map(restaurant => (
      {
        'title'     : restaurant.name,
        'title_link': restaurant.url,
        'fallback'  : config.get('slack.fallback'),
        'color'     : restaurant.color,
        'mrkdwn_in' : ['text', 'pretext', 'fields'],
        'fields'    : restaurant.offers.map(offer => (
          {
            'title' : offer.title,
            'value' : offer.description,
            'short' : true,
          }
        )),
        'footer': restaurant.parser.name,
        'ts': Math.round((new Date).getTime() / 1000)
      }
    ))
  };
}

{'fraction_non_alphanumeric': 0.15526976160602257, 'fraction_numerical': 0.002509410288582183, 'mean_word_length': 2.3817603393425237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5651869', 'n_tokens_mistral': 998, 'n_tokens_neox': 976, 'n_words': 175}