module.exports = function (robot) {

	robot.respond(/trello get token/i, function (res_r) {

		var slackMsgs = require('./slackMsgs.js');

		var key = process.env.HUBOT_TRELLO_KEY;

		let scope = 'read,write,account';
		let name = 'Hubot';
		let expr = '30days';
		let cb_method = '';
		let return_url = '';
		let url = `https://trello.com/1/authorize?expiration=${expr}&name=${name}&scope=${scope}&key=${key}&response_type=token`;
		//https://trello.com/1/authorize?expiration=never&name=SinglePurposeToken&key=51def9cb08cf171cd0970d8607ad8f97&callback_method=fragment&return_url=https://andreasbot.herokuapp.com/hubot/trello-token
		var msg = slackMsgs.basicMessage();

		msg.attachments[0].pretext = "Please get a token to authorize your Trello account";
		msg.attachments[0].title = "Trello Token";
		msg.attachments[0].title_link = url;
		msg.attachments[0].text = "Copy the token from the link above and run\n *trello add token <YOUR TOKEN>*";
		msg.attachments[0].footer = "Trello";
		msg.attachments[0].footer_icon = "https://d2k1ftgv7pobq7.cloudfront.net/meta/u/res/images/b428584f224c42e98d158dad366351b0/trello-mark-blue.png";
		res_r.send(msg);
	})

	robot.router.get('/hubot/trello-token', function (req, res) {
		// TODO: do something with the token 
		robot.logger.info(res);
		res.send(`<h2>Token succesfuly received. You can now close the window.</h2>\n
		<input type="button" value="Close this window" onclick="self.close()">`);
		res.send(`<input type="button" value="Close this window" onclick="self.close()">`);
	});

	robot.respond(/trello add token (.*)/i, function (res_r) {
		var token = res_r.match[1];
		//***IMPORTANT*** 
		// the .env assignment doesnt work with HEROKU!
		// must set up a heroku client and communicate through their api 
		process.env['HUBOT_TRELLO_TOKEN'] = token;
	})
}
@@ -1281,19 +1281,59 @@
 info(res
+.body);%0A%09%09robot.logger.info(res.fragment
 );%0A
-
 %09%09res.se
@@ -1406,16 +1406,23 @@
 h2%3E%5Cn%0A%09%09
+%3Cform%3E%0A
 %3Cinput t
@@ -1445,135 +1445,116 @@
 ue=%22
-Close this window%22 onclick=%22self.close()%22%3E%60);%0A%09%09res.send(%60%3Cinput type=%22button%22 value=%22Close this window%22 onclick=%22self.close()%22
+Put Your Text Here%22 onclick=%22window.location.href='http://www.hyperlinkcode.com/button-links.php'%22 /%3E%0A%3C/form
 %3E%60);

update trello token