<commit_before>var express = require('express');
var router = express.Router();
var Client = require('telapi').client;
var sendgrid  = require('sendgrid')(process.env.SENDGRID_USER, process.env.SENDGRID_PASS);
var bodyParser = require('body-parser')
var numbers = [];
var emails = [];
var telapi = new Client(process.env.TELAPI_SID, process.env.TELAPI_TOKEN);

router.post('/', function(req, res) {
  if(req.body.user.name == null | req.body.user.phone == null || req.body.user.email == null) {
    return res.send(400, "You need to put in your user information in the settings page.");
  }
  for(var i = 0; i < req.body.selected.length; i++) {
    telapi.create("sms_messages", {
        "From": process.env.TELAPI_NUMBER,
        "To": req.body.selected[i].phone,
        "Body": req.body.user.name + ' is suicidal and needs help. Contact them and take them to a hospital to get a suicide assessment. If you can\'t reach them, call 911.'
      }, function (response) {
        res.send("Messages sent successfully");
      },
      function (error) {
        res.send(400, "An error occurred while sending messages");
      }
    );
  }
  for(var i = 0; i < req.body.selected.length; i++) {
    emails.push(req.body.selected[i].email);
  }
  sendgrid.send({
    to      : emails,
    from    : process.env.SENDGRID_USER,
    subject : 'Emergency! ' + req.body.user.name + ' needs your help immediately',
    text    : 'I am having suicidal thoughts right now and I need your help. Please call or text me immediately at ' + req.body.user.phone + ' and take me to a local hospital to get a suicide assessment. If you are unable to reach me, call 911. I am not safe and cannot guarantee you that right now I will not hurt myself. This is urgent and you must take immediate action.\n\n' + req.body.user.name + '\n(via the Defcon One app)'
  }, function(err, json) {
    if (err) { res.send("An error occurred while sending messages"); }
    res.send("Messages sent successfully");
  });
});

module.exports = router;<commit_msg>add catch if contact has no phone number<commit_after>var express = require('express');
var router = express.Router();
var Client = require('telapi').client;
var sendgrid  = require('sendgrid')(process.env.SENDGRID_USER, process.env.SENDGRID_PASS);
var bodyParser = require('body-parser')
var numbers = [];
var emails = [];
var telapi = new Client(process.env.TELAPI_SID, process.env.TELAPI_TOKEN);

router.post('/', function(req, res) {
  if(req.body.user.name == null | req.body.user.phone == null || req.body.user.email == null) {
    return res.send(400, "You need to put in your user information in the settings page.");
  }
  for(var i = 0; i < req.body.selected.length; i++) {
    numbers.push(req.body.selected[i].numbers);
  }
  for(var i = 0; i < numbers; i++) {
    telapi.create("sms_messages", {
        "From": process.env.TELAPI_NUMBER,
        "To": numbers[i],
        "Body": req.body.user.name + ' is suicidal and needs help. Contact them and take them to a hospital to get a suicide assessment. If you can\'t reach them, call 911.'
      }, function (response) {
        res.send("Messages sent successfully");
      },
      function (error) {
        res.send(400, "An error occurred while sending messages");
      }
    );
  }
  for(var i = 0; i < req.body.selected.length; i++) {
    emails.push(req.body.selected[i].email);
  }
  sendgrid.send({
    to      : emails,
    from    : process.env.SENDGRID_USER,
    subject : 'Emergency! ' + req.body.user.name + ' needs your help immediately',
    text    : 'I am having suicidal thoughts right now and I need your help. Please call or text me immediately at ' + req.body.user.phone + ' and take me to a local hospital to get a suicide assessment. If you are unable to reach me, call 911. I am not safe and cannot guarantee you that right now I will not hurt myself. This is urgent and you must take immediate action.\n\n' + req.body.user.name + '\n(via the Defcon One app)'
  }, function(err, json) {
    if (err) { res.send("An error occurred while sending messages"); }
    res.send("Messages sent successfully");
  });
});

module.exports = router;
{'fraction_non_alphanumeric': 0.13583815028901733, 'fraction_numerical': 0.006984585741811176, 'mean_word_length': 3.290289256198347, 'pattern_counts': {'":': 6, '<': 8, '<?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': '1727551', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1265, 'n_words': 429}