const TJBot = require('tjbot');
const led = require('./lib/led.js');

console.log("Default configuration:" )
console.log(TJBot.prototype.defaultConfiguration);
console.log("Default speak config:")
console.log(TJBot.prototype.languages.speak);
console.log("Default listen config:")
console.log(TJBot.prototype.languages.listen)

console.log("init tjbot");
var hardware = [ 'microphone','speaker', 'servo'];

var configuration = require('./config.js');
var credentials = require('./credentials.js');
var workspace_id = credentials.workspace_id[config.listen.language]
console.log("workspace_id:"+workspace_id);
console.log("configuration:");
console.log(configuration);
var tj = new TJBot(hardware, configuration, credentials);

function testLed(){
  console.log("test leds");
  console.log("red");
  led.setLED(1,0,0);
  tj.sleep(500);
  console.log("green");
  led.setLED(0,1,0);
  tj.sleep(500);
  console.log("blue");
  led.setLED(0,0,1);
  tj.sleep(500);
}

function testServo(){
  console.log("test servo arm");
  tj.wave();
}

function testTTS(){
  console.log("test Text To Speech");
  tj.speak("teste 1 2 3");
}

function test(){
  testLed();
  testServo();
  testTTS();
}

test();

// listen for utterances and send the result to
// the Conversation service
tj.listen(function(msg) {
  // send to the conversation service
    tj.converse(workspace_id, turn, function(response) {
      // speak the result
      console.log(response);
      tj.speak(response.description);
    });
});

@@ -487,24 +487,138 @@
 tials.js');%0A
+console.log(%22configuration:%22);%0Aconsole.log(configuration);%0Aconsole.log(%22credentials:%22);%0Aconsole.log(credentials);%0A
 var workspac
@@ -636,16 +636,29 @@
 entials.
+conversation.
 workspac
@@ -668,16 +668,23 @@
 d%5Bconfig
+uration
 .listen.
@@ -740,66 +740,8 @@
 d);%0A
-console.log(%22configuration:%22);%0Aconsole.log(configuration);
 %0Avar
@@ -1399,16 +1399,38 @@
 service%0A
+    console.log(msg);%0A
     tj.c
@@ -1455,12 +1455,11 @@
 id, 
-turn
+msg
 , fu
@@ -1545,36 +1545,262 @@
  tj.
-speak(response.description);
+pauseListening();%0A      var speakPromise = tj.speak(response.description);%0A      if (speakPromise != undefined)%7B%0A%09speakPromise.then(function()%7Btj.resumeListening()%7D );%0A      %7D%0A%09else%7B%0A%09 console.log(%22speak promise is undefined%22);%0A%09 tj.resumeListening();%0A%09%7D
 %0A   

update tjbot