<commit_before>'use strict';

const Joi = require('joi');

const Message = require('./Message');
const config = require('../../config/messages/CustomerIoWebhookMessage');

class CustomerIoWebhookMessage extends Message {
  constructor(...args) {
    super(...args);

    // Data validation rules.
    this.schema = Joi.object().keys({
      data: Joi.object().required(),
      event_id: Joi.string().required(),
      event_type: Joi.string().required(),
      timestamp: Joi.number().integer().required(),
    });
  }

  getEventType() {
    return this.getData().event_type;
  }

  getEventRoutingKey(eventType = this.getEventType()) {
    const eventConfig = config.events[eventType] || config.events.generic;
    return eventConfig.routingKey;
  }
}

module.exports = CustomerIoWebhookMessage;
<commit_msg>added getUserId method to CustomerIoWebhookMessage.js<commit_after>'use strict';

const Joi = require('joi');

const Message = require('./Message');
const config = require('../../config/messages/CustomerIoWebhookMessage');

class CustomerIoWebhookMessage extends Message {
  constructor(...args) {
    super(...args);

    // Data validation rules.
    this.schema = Joi.object().keys({
      data: Joi.object().required(),
      event_id: Joi.string().required(),
      event_type: Joi.string().required(),
      timestamp: Joi.number().integer().required(),
    });
  }

  // @see https://customer.io/docs/developer-documentation/webhooks.html#list-of-webhook-attributes
  getUserId() {
    const data = this.getData().data;
    return data.customer_id;
  }

  getEventType() {
    return this.getData().event_type;
  }

  getEventRoutingKey(eventType = this.getEventType()) {
    const eventConfig = config.events[eventType] || config.events.generic;
    return eventConfig.routingKey;
  }
}

module.exports = CustomerIoWebhookMessage;

{'fraction_non_alphanumeric': 0.15513513513513513, 'fraction_numerical': 0.0, 'mean_word_length': 3.734015345268542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6600689', 'n_tokens_mistral': 550, 'n_tokens_neox': 550, 'n_words': 98}