<commit_before>'use strict';

/**
 * @name send
 * @module send
 * @description utilities for sendind different type of messages on top of
 *              open311-messages
 *
 * @see {@link Message}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public 
 */


//dependencies
const _ = require('lodash');
const config = require('config');
const environment = require('execution-environment');
const infobip = require('open311-infobip');
const phone = require('phone');
const mongoose = require('mongoose');
const Message = mongoose.model('Message');


/**
 * @name formatPhoneNumberToE164
 * @description format provided mobile phone number to E.164 format
 * @param  {String} phoneNumber a phone number to be formatted
 * @param {String} [country] 2 or 3 letter ISO country code. default to TZ
 * @return {String} E.164 formated phone number without leading plus sign
 * @see {@link https://en.wikipedia.org/wiki/E.164|e.164}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public
 */
exports.formatPhoneNumberToE164 = function (phoneNumber, countryCode) {

  //try convert give phone number to e.164
  try {
    countryCode = countryCode || 'TZ';
    phoneNumber = phone(phoneNumber, countryCode);
    phoneNumber = _.first(phoneNumber).replace(/\+/g, '');
    return phoneNumber;
  }

  //fail to convert, return original format
  catch (error) {
    return phoneNumber;
  }

};


/**
 * @name sms
 * @description send a given message as an sms
 * @param  {Message|Object}   message valid message instance or definition
 * @param  {Function} done    a callback to invoke on success or failure
 * @see {@link Message}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public
 */
exports.sms = function (message, done) {
<commit_msg>force lazy initialization for sms sending<commit_after>'use strict';

/**
 * @name send
 * @module send
 * @description utilities for sendind different type of messages on top of
 *              open311-messages
 *
 * @see {@link Message}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public 
 */


//dependencies
const _ = require('lodash');
const config = require('config');
const environment = require('execution-environment');
const infobip = require('open311-infobip');
const phone = require('phone');
const mongoose = require('mongoose');


/**
 * @name formatPhoneNumberToE164
 * @description format provided mobile phone number to E.164 format
 * @param  {String} phoneNumber a phone number to be formatted
 * @param {String} [country] 2 or 3 letter ISO country code. default to TZ
 * @return {String} E.164 formated phone number without leading plus sign
 * @see {@link https://en.wikipedia.org/wiki/E.164|e.164}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public
 */
exports.formatPhoneNumberToE164 = function (phoneNumber, countryCode) {

  //try convert give phone number to e.164
  try {
    countryCode = countryCode || 'TZ';
    phoneNumber = phone(phoneNumber, countryCode);
    phoneNumber = _.first(phoneNumber).replace(/\+/g, '');
    return phoneNumber;
  }

  //fail to convert, return original format
  catch (error) {
    return phoneNumber;
  }

};


/**
 * @name sms
 * @description send a given message as an sms
 * @param  {Message|Object}   message valid message instance or definition
 * @param  {Function} done    a callback to invoke on success or failure
 * @see {@link Message}
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 * @version 0.1.0
 * @public
 */
exports.sms = function (message, done) {

  //obtain Message model
  const Message = mongoose.model('Message');

{'fraction_non_alphanumeric': 0.1350606394707828, 'fraction_numerical': 0.025909592061742006, 'mean_word_length': 3.676546391752577, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '5475301', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1094, 'n_words': 368}