var request = require('request');
var uuid = require('uuid/v1');
var querystring = require('querystring')

module.exports = function (req, res, next) {
  var botPayload = {};
  console.log('send');

  sendIM('таааак', function() { });
}


function sendIM(payload, callback)
{
  return send('/im/sendIM', payload, callback);
}

function send(method, payload, callback) {
  var uid = process.env.UID;
  var sid = process.env.SID;
  var to = process.env.TO;
  var url = process.env.URL;

  console.log(url + method + '?' +
      querystring.stringify({
        'aimsid': sid,
        't': to,
        'r': uuid(),
        'message': payload
      }));
 
  request({
    uri: url + '?' +
      querystring.stringify({
        'aimsid': sid,
        't': to,
        'r': uuid(),
        'message': payload
      }),
    method: 'POST'
  }, function (error, response, body) {
    if (error) {
      console.log(error);
      console.log(response);
      console.log(body);
      return callback(error);
    }

    callback(null, response.statusCode, body);
  });
}


@@ -387,16 +387,20 @@
 ess.env.
+BOT_
 UID;%0A  v
@@ -420,16 +420,20 @@
 ess.env.
+BOT_
 SID;%0A  v
@@ -454,16 +454,20 @@
 s.env.TO
+_UID
 ;%0A  var 
@@ -484,16 +484,24 @@
 ess.env.
+BOT_API_
 URL;%0A%0A  

Update alcobot.js