Пример #1
0
app.post('/item',  function(req, res) {
  logger.info('got an item post');
  var deviceid = req.body.deviceid;
  var itemString = req.body.item;
  uuid = req.body.uuid;

  var type = req.body.rec_type || 'visual';
  logger.info('deviceid: ' + deviceid);
  logger.info('nitem: ' + itemString);
  logger.info('uuid: ' + uuid);
  if (users.isDevice(deviceid)) { //TODO:  Check for undefined
    var userid = users.getUserid(deviceid);
    logger.info('user for device id ' + deviceid + ': ' + userid);
    users.setStateByUser(userid, 0);
    // result-1:personresult-2:man's handend-results
    var re = /result-\d:(.+)result-\d:(.+)end-results/;
    var results = re.exec(itemString);
    var result1 = results[1];
    var result2 = results[2];
    logger.info('result 1: ' + result1 + ', result 2: ' + result2);
    if (result1 === 'NoResults' && result2 === 'NoResults') {
      bot.send(Bot.Message.text('Sorry, nothing was recognized.  Try again and ' +
                                'adjust the lighting, hold the camera still, and aim it ' +
                                'directly at the object with no background objects.'), userid);
      metrics.recordEvent("inventory", "visual identify 1", "fail", 1, userid);
      metrics.recordEvent("inventory", "visual identify 2", "fail", 1, userid);
      uploadMetadata(result1, 'failure', result2, 'failure');
    } else if ((result1 === 'NoResults' && result2 !== 'NoResults') || 
               (result1 !== 'NoResults' && result2 === 'NoResults')) {
      logger.info('One recognition service recognized the item and the other did not recognize the item');
      var item;
      if (result1 === 'NoResults') {
        logger.info('first recognition service did not recognize, second said: ' + result2);
        users.setCurrentItem(userid, null, result2);
        currentItem = ITEM_2;
        item = result2;
      }
      else {
        logger.info('second recognition service did not recognize, first said: ' + result1);
        users.setCurrentItem(userid, result1, null);
        currentItem = ITEM_1;
        item = result1;
      }
      bot.send(Bot.Message.text('Hey, is this a(n):\n' + item + '?\nType (y)es, or (n)o'), userid);
    } else {
      bot.send(Bot.Message.text('Hey, is this a(n):\n' + '1. ' + result1 + '?\n2. ' + result2 + '?\n' + 'Type 1, 2, or (n)either'), userid);
      //Save the current item with the user so we can come back to it later once it's confirmed.
      users.setCurrentItem(userid, result1, result2);
    }
    res.status(200).send('OK');
  } else {
    logger.info('User not found.');
    res.status(401).send('Unauthorized');
  }
});
Пример #2
0
bot.onTextMessage((message) => {

	var text = message.body;
	var from = message.from;
	
	console.log('Received: \"' + text + '\" from ' + from);
// conversationHandler.handleIncomingMessage(message);
	
	// find the conversation trigger
	for(var i=0; i<tree.messages.length; i++ ){
		if( text.match(RegExp(tree.messages[i].keywords, 'i')) ){
			// conversation trigger found
			
			console.log("from1: " + from);
			
			var messageId = i;
			console.log (tree.messages[messageId].keywords + ' matched for: ' + text);
			
			if( tree.messages[messageId].type == 'text'){
				message.setBody(tree.messages[messageId].text);
			} else if( tree.messages[messageId].type == 'picture'){
				var from = message.from;
				message = Bot.Message.picture(tree.messages[messageId].url)
//					.setText(tree.messages[messageId].text != '' ? tree.messages[messageId].text : '')
					.setAttributionName('Click me')
			    	.setAttributionIcon('http://www1.macys.com/favicon.ico');
				if(tree.messages[messageId].text != ' '){
					bot.send(message, from);
					message = Bot.Message.text(tree.messages[messageId].text);
				}
			} else if( tree.messages[messageId].type == 'video' ||  tree.messages[messageId].type == 'link' ){
				var from = message.from;
				message = Bot.Message.link(tree.messages[messageId].url)
					.setText(tree.messages[messageId].text != '' ? tree.messages[messageId].text : '')
					.setAttributionName('Click me')
			    	.setAttributionIcon('http://www1.macys.com/favicon.ico');
			}
			
			var buttons = [];
			for(var j=0; j<tree.messages[messageId].buttons.length; j++){
				buttons.push(tree.messages[messageId].buttons[j].text);
			}
			
			message.addTextResponse(buttons);
			console.log("from2: " + from + '\n');
			bot.send(message, from);
			
		}else{
//			console.log(tree.messages[i].keywords + ' not matched');
		}
	}
});
Пример #3
0
function sendRecent(sendTo) {
  var myMessage = Bot.Message.text("Finding a recent sound!");
  //myMessage.addResponseKeyboard([], false);
  setTimeout(function() {
    bot.send(myMessage, sendTo);
  }, 300);

  var url = "https://foundsounds.me/api/recent";
  request({
    url: url,
    json: true
  }, function (error, response, body) {
    if (!error && response.statusCode === 200) {
      var foundSound = false;
      var i = 0;
      while (foundSound == false) {
        if (body[i].photo_id > 0) {
          sendSound(sendTo, body[i]);
          foundSound = true;
        }
        i++;
      }
    }
  });
}
Пример #4
0
function sendInfo(sendTo) {
  var myMessage = Bot.Message.text("FoundSounds is a collective art project in the form of a social network. Users find and record sounds they find interesting to share with one another.");
  myMessage.addResponseKeyboard(options, false);

  setTimeout(function() {
    bot.send(myMessage, sendTo);
  }, 300);

  var fsLink = Bot.Message.link('https://foundsounds.me').setTitle('FoundSounds').setText('Find Sounds. Share Sounds.').setPicUrl('https://foundsounds.me/ci-images/header-bg.jpg');
  fsLink.addResponseKeyboard(options, false);

  setTimeout(function() {
    bot.send(fsLink, sendTo);
  }, 1000);

}
Пример #5
0
bot.onPictureMessage((message) => {
  bot.send(Bot.Message.picture('http://i.imgur.com/oalyVlU.jpg')
    .setAttributionName('Imgur')
    .setAttributionIcon('http://s.imgur.com/images/favicon-96x96.png'),
    message.from,
    message.chatId);  
});
Пример #6
0
function sendSound(sendTo, sound) {
  var fsLink = Bot.Message.link(`https://foundsounds.me/listen/${sound.username}/${sound.soundID}`).setTitle('FoundSounds');

  if (sound.description != '') {
    fsLink.setText(sound.description);
  }

  if (sound.photo_id != "" && sound.photo_id > 0) {
    fsLink.setPicUrl(`https://foundsounds.me/${sound.trackCover}`);
  }

  /*
  .setPicUrl('https://foundsounds.me/ci-images/header-bg.jpg');
  */
  fsLink.addResponseKeyboard(options, false);
  bot.send(fsLink, sendTo);
}
Пример #7
0
function sendGeneric(sendTo) {
  mixpanel.track('generic_message');
  var myMessage = Bot.Message.text("Hi! I can send you sounds or tell you more about FoundSounds!");
  myMessage.addResponseKeyboard(options, false);
  bot.send(myMessage, sendTo);
}
Пример #8
0
		User.findOne({name:message.from}, function(err,user){
			console.log(user, err)
			if(user === null){
				user = new User({name: message.from, password:"******", state:0})

			}


	////////////////////////////////////shuffle/////////////////////////////////////

		var exclaims = ["I don't know what to do...","How did I get into this?","I should never have come here", "Help me!!"]
	  var mathRan = function (){return (Math.floor(Math.random() * (exclaims.length - 0)) + 0)}


	/////////////////////////////////////end/////////////////////////////////
			var currentState = user.state
			//

			if(message.body === "Reset"){//Dev Reset

				outgoingMessage = Bot.Message.text("Error 499383 Phone is disconnected")
				outgoingMessage.addResponseKeyboard(["Sammy has died"], false, message.from)
			}
			if(message.body === "Sammy has died"){//Reset Not working
				user.state = 0
				outgoingMessage = Bot.Message.text("Error 499383 Phone is disconnected")

			}

	////////////////////////////////////////Start////////////////////////

			if(user.state === 0) { //second message
			// if(message.body === "hey" || message.body === "What are you up to?") { //second message
		    outgoingMessage = Bot.Message.text("Chat Storiers!  I'm infront of the creepy house now, but I will be going on more adventures soon.  I need your help.")
				user.state = user.state+1
				console.log(currentState)
		    outgoingMessage.addResponseKeyboard(["Sure.  What's up", "Too busy.  Sorry."], false, message.from)

		    //message.reply("cool");
		    //message.reply("Hey, I need some advice");
			}else if(user.state  === 1){
		  // }else if(message.body === "Sure.  What's up"){
		    outgoingMessage = Bot.Message.text("There's this creepy house on my street. And the front door is wide open.  Should I go in?")
		    outgoingMessage.addResponseKeyboard(["Do it!", "No way!"], false, message.from)
					user.state = 2 //at 2

		  }else if(user.state === 2){//inside house
	       //on Two Options dont set user.state
		    outgoingMessage = Bot.Message.text("Cool.  I'm inside. Looking around....There's a living room, an upstairs, a kitchen, and a basement.  Where should I go?")
		    outgoingMessage.addResponseKeyboard(["go to the living room", "what's up with the basement" ], false, message.from)
					user.state = user.state+1 //at 3



		  }else if(message.body === "what's up with the basement"){//option B Checkout basment
				  	user.state = user.state+10 // at 13
		      outgoingMessage = Bot.Message.text("There's weird noises...like moaning or something. I dont waant to go down there!  It's lockded anyway....needs a key")
		      outgoingMessage.addResponseKeyboard(["go to the living room"], false, message.from)

		  }else if(user.state === 3 || user.state === 13 ){//Want if 3 or 13
					user.state = 4
					console.log(user.state)
		    outgoingMessage = Bot.Message.text("Kind of boring.  There a fireplace with a fire burning...And a wallet on the floor.  Some kid's school ID?  Who is this kid?...")
		    outgoingMessage.addResponseKeyboard(["Take his wallet!  Easy money.", "Let's go see more of the house"], false, message.from)

		  }else if(user.state === 4){//kitchen at 4
				user.state = 5
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("Cool.  I'm in the kitchen.  There's kitchen knife.  A big one!  I dont feel safe.  Like someone is watching me... ")
		    outgoingMessage.addResponseKeyboard(["Take the knife!", "What's around?"], false, message.from)

		  }else if(user.state === 5){//Upstairs at 5
				user.state = 6
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("I'm upstairs now...walking towards the one room ")
		    outgoingMessage.addResponseKeyboard(["What do you see?"], false, message.from)

		  }else if(user.state === 6){//Go Talk is a Death Route. At 6
				user.state = user.state+1 //at 7
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("A woman on a rocking chair....with a white dress.  There's a key on a dresser next to her...")
		    outgoingMessage.addResponseKeyboard(["Go talk to the woman", "Grab the key and bounce"], false, message.from)



		  }else if(message.body === "Grab the key and bounce"){//To the basement at 7
				user.state = 8
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("I think this is the key for the basement")
		    outgoingMessage.addResponseKeyboard(["See if the key works"], false, message.from)

		  }else if(user.state === 8){//In the basement at 8
				user.state = 9
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("It opened!  It's dark down there.  These moans are getting louder...I think I see a cell down there")
		    outgoingMessage.addResponseKeyboard(["Go down there. Maybe someone needs help", "Forget this! Leave now!"], false, message.from)

		  }else if(user.state === 9){//basement door. At 9
				user.state = 10
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("I've gone too far.  I need to check this out ")
		    outgoingMessage.addResponseKeyboard(["What's going on?"], false, message.from)

		  }else if(user.state === 10){//Basement Zombie kids.  Leave this sick place is death Route at 10.
				user.state = 11
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("There's a bunch of kids!  Pale disgusting things.  Blood is coming out of their eyes and they're trying to grab me!!!")
		    outgoingMessage.addResponseKeyboard(["See if you can free them?", "Leave this sick place!"], false, message.from)

		  }else if(message.body === "See if you can free them?"){//Basement Zombie kids
				user.state = user.state+1 //at 12
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("I tried but there is man with a shotgun walking down the stairs.  I'm hiding need to stay quiet...")
		    outgoingMessage.addResponseKeyboard(["What's happening??"], false, message.from)

		  }else if(message.body === "What's happening??"){//Basement Zombie kids
				user.state = user.state+2 //at 14
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("The kids busted out!  They're eating the man with the shotgun.  I can make it got the door! ")
		    outgoingMessage.addResponseKeyboard(["Go!"], false, message.from)

		  }else if(message.body === "Go!"){//Game Win at 0
				user.state = 0 //at 15
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("I'm outside....on my way back home.  You saved my life.  Couldn't have dont it without you.  Stay safe tonight.")
		    outgoingMessage.addResponseKeyboard(["Play Again"], false, message.from)


		//Death Route
		  }
			else if(message.body === "Leave this sick place!"){//Basement Zombie kids
				user.state = user.state+20
				console.log(user.state)
		    outgoingMessage = Bot.Message.text("There's a man with shotgun blocking the basement door!")
		    outgoingMessage.addResponseKeyboard(["Fight him!", "Hide!"], false, message.from)

		  }
			else if(user.state === 31 || message.body === "Go talk to the woman" ){//Talk to Woman Death
				user.state = 0;
		    outgoingMessage = Bot.Message.text("Error 499383 Phone is disconnected")
		    outgoingMessage.addResponseKeyboard(["Sammy has died"], false, message.from)
			}


		////================================================================================================

			// else if(message.body === "Keep Going"){//Leave Message
			// 	user.state = user.state+1
			//
			// }

			else{ //for first message
				outgoingMessage = Bot.Message.text(exclaims[mathRan()])
				//     outgoingMessage.addResponseKeyboard(["Keep Going"], false, message.from)
						user.state = user.state+1

		  	}
				///Ivar emoji test
				// console.log("Hello Ivar")
				// 	outgoingMessage = Bot.Message.text('\ud83d\ude0d')

	    user.save()//save the user
		  bot.send(outgoingMessage, message.from)})
Пример #9
0
//TODO: This is not part of the real flow.  It's just a way to trigger the bot flow
// from the bot itself.  We can eventually remove this.
function triggerItemConfirmationFlow(item, user) {
  users.setStateByUser(user, 0);
  bot.send(Bot.Message.text('Hey, is this a: ' + item + '?.  Type 1, 2, or (n)either'), user);
}