var magic = require('stream-mmmagic');
var request = require('request');
var types = require('./types.json');

/**
 * Get the type of message based on contents
 * @param  {stream|string}   content  content to check
 * @param  {Function} callback Callback function
 */
exports.getMessageType = function (content, callback) {
  'use strict';
  var isAStream =
    typeof content.on === 'function' &&
    typeof content.read === 'function' &&
    typeof content.pipe === 'function';
  if (isAStream) {
    magic(content, function (err, mime) {
      if (err) {
        console.log(err);
      }
      if (types.image.indexOf(mime.type) !== -1) {
        callback('image');
      } else if (types.audio.indexOf(mime.type) !== -1) {
        callback('audio');
      } else if (types.video.indexOf(mime.type) !== -1) {
        callback('video');
      } else {
        callback('document');
      }
    });
  } else {
    callback('text');
  }
};

/**
 * Generic method to send HTTPS requests
 * @param  {Object}   params   form data
 * @param  {Function} callback Callback function
 */
exports.sendRequest = function (params, callback) {
  'use strict';
  if (params.formData) {
    params.formData.photo.pipe(require('fs').createWriteStream('/home/darshak/CoDS1.jpg'));
  }
  request.post(params, function (err, res, body) {
    if (err) {
      console.error(err);
    }
    if (callback) {
      callback(JSON.parse(body));
    }
  });
};

@@ -102,16 +102,43 @@
 .json');
+%0Avar _ = require('lodash');
 %0A%0A/**%0A *
@@ -617,24 +617,35 @@
  %7D%0A      if 
+(_.contains
 (types.image
@@ -644,25 +644,18 @@
 es.image
-.indexOf(
+, 
 mime.typ
@@ -648,39 +648,32 @@
 mage, mime.type)
- !== -1
 ) %7B%0A        call
@@ -699,24 +699,35 @@
   %7D else if 
+(_.contains
 (types.audio
@@ -726,25 +726,18 @@
 es.audio
-.indexOf(
+, 
 mime.typ
@@ -730,39 +730,32 @@
 udio, mime.type)
- !== -1
 ) %7B%0A        call
@@ -785,16 +785,27 @@
 else if 
+(_.contains
 (types.v
@@ -812,17 +812,10 @@
 ideo
-.indexOf(
+, 
 mime
@@ -824,15 +824,8 @@
 ype)
- !== -1
 ) %7B%0A
@@ -1164,129 +1164,8 @@
 t';%0A
-  if (params.formData) %7B%0A    params.formData.photo.pipe(require('fs').createWriteStream('/home/darshak/CoDS1.jpg'));%0A  %7D%0A
   re

Use lodash