<commit_before>'use strict';

const CIO = require('customerio-node');
const logger = require('winston');

const BlinkRetryError = require('../errors/BlinkRetryError');
const CustomerIoUpdateCustomerMessage = require('../messages/CustomerIoUpdateCustomerMessage');
const Worker = require('./Worker');

class CustomerIoUpdateCustomerWorker extends Worker {
  constructor(blink) {
    super(blink);
    this.blink = blink;

    this.cioConfig = this.blink.config.customerio;

    // Bind process method to queue context
    this.consume = this.consume.bind(this);
  }

  setup() {
    this.queue = this.blink.queues.customerIoUpdateCustomerQ;
    this.cioClient = new CIO(this.cioConfig.apiKey, this.cioConfig.siteId);
  }

  async consume(userMessage) {
    let meta;
    if (userMessage.isMobileOnly()) {
      meta = {
        env: this.blink.config.app.env,
        code: 'cio_update_skip_mobile_only',
        worker: this.constructor.name,
        request_id: userMessage ? userMessage.getRequestId() : 'not_parsed',
      };
      logger.debug(`Skipping mobile only user ${userMessage.getData().id}`, meta);
      return true;
    }

    let customerIoUpdateCustomerMessage;
    try {
      // For now all messages are new
      customerIoUpdateCustomerMessage = CustomerIoUpdateCustomerMessage.fromUser(
        userMessage,
        true,
      );
      customerIoUpdateCustomerMessage.validateStrict();
    } catch (error) {
      meta = {
        env: this.blink.config.app.env,
        code: 'error_cio_update_cant_convert_user',
        worker: this.constructor.name,
        request_id: userMessage ? userMessage.getRequestId() : 'not_parsed',
      };
      logger.warning(
        `Can't convert user to cio customer: ${userMessage.getData().id} error ${error}`,
        meta,<commit_msg>Don't skip sending SMS-only users to Customer.io<commit_after>'use strict';

const CIO = require('customerio-node');
const logger = require('winston');

const BlinkRetryError = require('../errors/BlinkRetryError');
const CustomerIoUpdateCustomerMessage = require('../messages/CustomerIoUpdateCustomerMessage');
const Worker = require('./Worker');

class CustomerIoUpdateCustomerWorker extends Worker {
  constructor(blink) {
    super(blink);
    this.blink = blink;

    this.cioConfig = this.blink.config.customerio;

    // Bind process method to queue context
    this.consume = this.consume.bind(this);
  }

  setup() {
    this.queue = this.blink.queues.customerIoUpdateCustomerQ;
    this.cioClient = new CIO(this.cioConfig.apiKey, this.cioConfig.siteId);
  }

  async consume(userMessage) {
    let meta;
    let customerIoUpdateCustomerMessage;
    try {
      // For now all messages are new
      customerIoUpdateCustomerMessage = CustomerIoUpdateCustomerMessage.fromUser(
        userMessage,
        true,
      );
      customerIoUpdateCustomerMessage.validateStrict();
    } catch (error) {
      meta = {
        env: this.blink.config.app.env,
        code: 'error_cio_update_cant_convert_user',
        worker: this.constructor.name,
        request_id: userMessage ? userMessage.getRequestId() : 'not_parsed',
      };
      logger.warning(
        `Can't convert user to cio customer: ${userMessage.getData().id} error ${error}`,
        meta,
{'fraction_non_alphanumeric': 0.11461844927980386, 'fraction_numerical': 0.0, 'mean_word_length': 3.3117569352708056, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5003180', 'n_tokens_mistral': 957, 'n_tokens_neox': 963, 'n_words': 194}