var express = require('express');
var math = require('mathjs');
var bodyParser = require('body-parser');
var app = express();

app.set('port', (process.env.PORT || 8080));

app.use(bodyParser.urlencoded({ extended: true }));

app.listen(app.get('port'), function () {
  console.log('app starting at port '+ app.get('port'));
});

var mathParser = new math.parser();

app.get('/eval', function(req, resp) {
	resp.send('/eval only currently accept POST requests.');
});

app.post('/eval', function(req, resp) {
  var result = {};
  var post = req.body;
  var expr = post.text;
  var trigger = post.trigger_word;

  // do not respond to bot-users
  if(post.user_name == 'slackbot'){
  	resp.end();
  	return;
  }

  if (!expr) {
  	result.ok = false;
  	result.text = 'No message sent.';
    resp.json(result);
    return;
  }

  if (trigger) {
  	expr = expr.slice(trigger.length);
  }
  
  result.text = '';
  
  try {
    result.ok = true;
    var answer = mathParser.eval(expr);
    result.attachments = [{
    	color: 'good',
    	author_name: '@' + post.user_name,
    	text: 'ans = *' + answer + '*',
    	mrkdwn_in: ['text']
    }];
    mathParser.scope.ans = answer;
  } catch (err) {
    result.ok = false;
    result.attachments = [{
    	color: 'danger',
    	author_name: '@' + post.user_name,
    	text: err.toString(),
    	mrkdwn_in: ['text']
    }];
    result.error = {
      type: err.name,
      message: err.message
    };
  }

  resp.json(result);

});

@@ -1022,35 +1022,28 @@
 good',%0A    %09
-author_name
+text
 : '@' + post
@@ -1052,30 +1052,21 @@
 ser_name
-,%0A    %09text:
+ +
  '
+ 
 ans = *'
@@ -1250,19 +1250,12 @@
    %09
-author_name
+text
 : '@
@@ -1272,28 +1272,24 @@
 ser_name
-,%0A    %09text:
+ + ' ' +
  err.toS

Revert "Revert "try to compact space""