const Botkit = require('botkit');
const request = require('request');

let controller = Botkit.slackbot({
    debug: false
    //include "log: false" to disable logging
    //or a "logLevel" integer from 0 to 7 to adjust logging verbosity
});

// connect the bot to a stream of messages
controller.spawn({
        token: process.env.BOTTOKEN,
}).startRTM();

controller.hears('salam',['direct_message','direct_mention','mention'],(bot,message) => {
    bot.reply(message,`wa Alikom Salam <@${message.user}> :smiley:`);
});

controller.hears('kech jdid', ['direct_message','direct_mention','mention'], (bot, message) => {
  let jdid = [];
  request.get('https://boiling-inlet-40180.herokuapp.com/news', (err,res,body) => {
    if (!err && res.statusCode == 200) {
      jdid = JSON.parse(body);
    }

    let thenews = "";
    for (let variable in jdid) {
      thenews += "* " + jdid[variable].text + "\n";

    }
    if (jdid.length>0) {
      bot.reply(message, "wah kayan, please check:\n" + thenews);
    }else {
      bot.reply(message, "walo :confused:");
    }
  });
});
controller.hears('tu sais, je suis', ['direct_message','direct_mention','mention'], (bot, message) => {
  request.post({
      url: 'http://text-processing.com/api/sentiment/',
      form: {
        language: 'french',
        text: message.text
      }
    },
    function(error, response, body){
      let answerLabel = JSON.parse(body)["label"];
      if (answerLabel==='neg') {
        return bot.reply(message, "Oh :confused:, Ghi lkhir ?");
      } else {
        return bot.reply(message, "Ah :smiley: Glad to hear that !");
      }
      }
  );
});

controller.hears('you know, I\'m', ['direct_message','direct_mention','mention'], (bot, message) => {
  request.post({
      url: 'http://text-processing.com/api/sentiment/',
      form: {
        text: message.text
      }
    },
    function(error, response, body){
      let answerLabel = JSON.parse(body)["label"];
      if (answerLabel==='neg') {
        return bot.reply(message, "Oh :confused:, Ghi lkhir ?");
      } else {
        return bot.reply(message, "Ah :smiley: Glad to hear that !");
      }
      }
  );
});

controller.on('direct_message', (bot, message) => {
    bot.reply(message, "3lach rak tgoli \""+ message.text +"\" ?");
});

module.exports = controller;

@@ -2150,32 +2150,380 @@
     %7D%0A  );%0A%7D);%0A%0A
+controller.hears('golah bsa7tek', %5B'direct_mention','mention'%5D, (bot, message) =%3E %7B%0A  bot.reply(message, %22bsa7tek%22);%0A%7D);%0A%0Acontroller.hears('say hi to (.)*', %5B'direct_message','direct_mention','mention'%5D, (bot, message) =%3E %7B%0A  let theName = message.text.split('@')%5B1%5D;%0A  bot.reply(message, %22Hello %3C@%22 + theName + %22, marhba biik :smiley_cat:%22);%0A%7D);%0A%0A
 controller.on('d

add bsa7tek and say hi messages