function receivedMessage(event) {
	let senderID = event.sender.id;
	//var recipientID = event.recipient.id;
	//var timeOfMessage = event.timestamp;
	let message = event.message;
	//var messageId = message.mid;
	let messageText = message.text;
	//var messageAttachments = message.attachments;
	console.log("Received Facebook message from " + senderID + ": " + messageText);
	if (messageText) {
		userLogins.findOne( { FB_ID: senderID }, function(err, doc){
			//make sure the user has at least one slack account linked to their facebook account
			//if they don't, send them a sign in link
			if( doc === null ){
				console.error(senderID + " is not signed into any Slack accounts.")
				sendTextMessage(senderID, "You must sign in with at least one Slack account");
				SignIn(senderID);
			//if the message starts with "/signin", send them a sign in link
			} else if( messageText.substring(0,7) === "/signin" ){
				console.log(senderID + " requested a sign in link.")
				SignIn(senderID);
			//if the message starts with "/signout", prompt to find which team the user wants to sign out of
			} else if( messageText.substring(0,8) === "/signout" ){
				//go to the signout part of the condition below
				PromptTeams(senderID, "signout");
			//if the message starts with "/subscribe", prompt to get the team of the channel to which the user wants to subscribe
			} else if( messageText.substring(0,10) === "/subscribe"){
				//go to the subscribe part of the condition below
				PromptTeams(senderID, "subscribe");
			//if the message starts with "/unsubscribe", prompt to get the team of hte channel to which the users wants to unsubscribe
			} else if( messageText.substring(0,12) === "/unsubscribe"){
				//go to the unsubscribe part of the condition below
				PromptTeams(senderID, "unsubscribe");
			//if the message starts with "/select", prompt to find the team the user wants to select
			} else if(messageText.substring(0,7) === "/select"){
				//go to the select part of the condition below
				PromptTeams(senderID, "select");
			//if the message is a quick reply, process the payload
			} else if(message.quick_reply != undefined){
				//the payload is a string with pieces of information separated by "~_!", so split the payload by that string to get an array of information
				let payload = message.quick_reply.payload.split("~_!");
				//if the user was previously entered "/subscribe", prompt to get the channel to which the user wants to subscribe
				if(payload[0] === "subscribe"){
					let teamName = payload[1];
					PromptAllChannels(senderID, teamName);
				//if the user previously chose a channel to which to subscribe, update the database with the new subscription
				} else if(payload[0] === "subscribe2"){
					let teamID = payload[1];
					let teamName = payload[2];
					let channelID = payload[3];
					let channelName = payload[4];
					SubscribeUpdateDatabase(senderID, teamID, teamName, channelID, channelName);
				//if the user previously entered "/unsubscribe", prompt to get the channel to which the user wants to unsubscribe
				} else if(payload[0] === "unsubscribe"){
					let teamName = payload[1]
					PromptSubscribedChannels(senderID, teamName, "unsubscribe2");
				//if the user previously chose a channel to which to unsubscribe, update the database with the new changes
				} else if(payload[0] === "unsubscribe2"){
					let teamName = payload[1];
					let channelName = payload[2];
					Unsubscribe(teamName, channelName, senderID);
				//if the user previously entered "/signout", update the database with the new changes
				} else if(payload[0] === "signout"){
					let teamName = payload[1]
					SignOut(senderID, teamName);
				//if the user previously entered "/select", prompt to find the channel the user wants to select
				} else if(payload[0] === "select"){
					let teamName = payload[1];
					PromptSubscribedChannels(senderID, teamName, "select2");
				//if the user previously entered a channel to select, update the database with user's selected team and channel
				} else if(payload[0] === "select2"){
					let teamName = payload[1];
					let channelName = payload[2];
					SelectTeamChannel(senderID, teamName, channelName);
				}
			//if the message isn't one of the above formats, assume the user wants to send a message
			} else{
				//get the team name, channel name, and message from the facebook message
				let colon = messageText.indexOf(":");
				let space = messageText.indexOf(" ", colon);
				let teamName = null;
				let channelName = null;
				let message = null;
				//if the user doesn't specify the channel and team, get his/her selected team and channel
				if(colon === -1 || space === -1){
					userSettings.findOne( {FB_ID: senderID}, function(err, doc){
						teamName = doc.SELECTED_TEAM;
						channelName = doc.SELECTED_CHANNEL;
						message = messageText;
						sendSlackMessage(senderID, teamName, channelName, message);
					});
				//otherwise, parse the message for them and send the message based on them
				} else {
					teamName = messageText.substring(0, colon);
					channelName = messageText.substring(colon+1, space);
					message = messageText.substring(space+1);
					sendSlackMessage(senderID, teamName, channelName, message);
				}
			}
		} );
	}
}
//Postconditions: the message received will be processed and replied to
the message received will be processed and replied to
the message received will be processed and replied to
function receivedMessage(event) {
	let senderID = event.sender.id;
	let message = event.message;
	let messageText = message.text;
	console.log("Received Facebook message from " + senderID + ": " + messageText);
	if (messageText) {
		userLogins.findOne( { FB_ID: senderID }, function(err, doc){
			if( doc === null ){
				console.error(senderID + " is not signed into any Slack accounts.")
				sendTextMessage(senderID, "You must sign in with at least one Slack account");
				SignIn(senderID);
			} else if( messageText.substring(0,7) === "/signin" ){
				console.log(senderID + " requested a sign in link.")
				SignIn(senderID);
			} else if( messageText.substring(0,8) === "/signout" ){
				PromptTeams(senderID, "signout");
			} else if( messageText.substring(0,10) === "/subscribe"){
				PromptTeams(senderID, "subscribe");
			} else if( messageText.substring(0,12) === "/unsubscribe"){
				PromptTeams(senderID, "unsubscribe");
			} else if(messageText.substring(0,7) === "/select"){
				PromptTeams(senderID, "select");
			} else if(message.quick_reply != undefined){
				let payload = message.quick_reply.payload.split("~_!");
				if(payload[0] === "subscribe"){
					let teamName = payload[1];
					PromptAllChannels(senderID, teamName);
				} else if(payload[0] === "subscribe2"){
					let teamID = payload[1];
					let teamName = payload[2];
					let channelID = payload[3];
					let channelName = payload[4];
					SubscribeUpdateDatabase(senderID, teamID, teamName, channelID, channelName);
				} else if(payload[0] === "unsubscribe"){
					let teamName = payload[1]
					PromptSubscribedChannels(senderID, teamName, "unsubscribe2");
				} else if(payload[0] === "unsubscribe2"){
					let teamName = payload[1];
					let channelName = payload[2];
					Unsubscribe(teamName, channelName, senderID);
				} else if(payload[0] === "signout"){
					let teamName = payload[1]
					SignOut(senderID, teamName);
				} else if(payload[0] === "select"){
					let teamName = payload[1];
					PromptSubscribedChannels(senderID, teamName, "select2");
				} else if(payload[0] === "select2"){
					let teamName = payload[1];
					let channelName = payload[2];
					SelectTeamChannel(senderID, teamName, channelName);
				}
			} else{
				let colon = messageText.indexOf(":");
				let space = messageText.indexOf(" ", colon);
				let teamName = null;
				let channelName = null;
				let message = null;
				if(colon === -1 || space === -1){
					userSettings.findOne( {FB_ID: senderID}, function(err, doc){
						teamName = doc.SELECTED_TEAM;
						channelName = doc.SELECTED_CHANNEL;
						message = messageText;
						sendSlackMessage(senderID, teamName, channelName, message);
					});
				} else {
					teamName = messageText.substring(0, colon);
					channelName = messageText.substring(colon+1, space);
					message = messageText.substring(space+1);
					sendSlackMessage(senderID, teamName, channelName, message);
				}
			}
		} );
	}
}
function receivedMessage ( event ) { let senderID = event . sender . id ; let message = event . message ; let messageText = message . text ; console . log ( "Received Facebook message from " + senderID + ": " + messageText ) ; if ( messageText ) { userLogins . findOne ( { FB_ID : senderID } , function ( err , doc ) { if ( doc === null ) { console . error ( senderID + " is not signed into any Slack accounts." ) sendTextMessage ( senderID , "You must sign in with at least one Slack account" ) ; SignIn ( senderID ) ; } else if ( messageText . substring ( 0 , 7 ) === "/signin" ) { console . log ( senderID + " requested a sign in link." ) SignIn ( senderID ) ; } else if ( messageText . substring ( 0 , 8 ) === "/signout" ) { PromptTeams ( senderID , "signout" ) ; } else if ( messageText . substring ( 0 , 10 ) === "/subscribe" ) { PromptTeams ( senderID , "subscribe" ) ; } else if ( messageText . substring ( 0 , 12 ) === "/unsubscribe" ) { PromptTeams ( senderID , "unsubscribe" ) ; } else if ( messageText . substring ( 0 , 7 ) === "/select" ) { PromptTeams ( senderID , "select" ) ; } else if ( message . quick_reply != undefined ) { let payload = message . quick_reply . payload . split ( "~_!" ) ; if ( payload [ 0 ] === "subscribe" ) { let teamName = payload [ 1 ] ; PromptAllChannels ( senderID , teamName ) ; } else if ( payload [ 0 ] === "subscribe2" ) { let teamID = payload [ 1 ] ; let teamName = payload [ 2 ] ; let channelID = payload [ 3 ] ; let channelName = payload [ 4 ] ; SubscribeUpdateDatabase ( senderID , teamID , teamName , channelID , channelName ) ; } else if ( payload [ 0 ] === "unsubscribe" ) { let teamName = payload [ 1 ] PromptSubscribedChannels ( senderID , teamName , "unsubscribe2" ) ; } else if ( payload [ 0 ] === "unsubscribe2" ) { let teamName = payload [ 1 ] ; let channelName = payload [ 2 ] ; Unsubscribe ( teamName , channelName , senderID ) ; } else if ( payload [ 0 ] === "signout" ) { let teamName = payload [ 1 ] SignOut ( senderID , teamName ) ; } else if ( payload [ 0 ] === "select" ) { let teamName = payload [ 1 ] ; PromptSubscribedChannels ( senderID , teamName , "select2" ) ; } else if ( payload [ 0 ] === "select2" ) { let teamName = payload [ 1 ] ; let channelName = payload [ 2 ] ; SelectTeamChannel ( senderID , teamName , channelName ) ; } } else { let colon = messageText . indexOf ( ":" ) ; let space = messageText . indexOf ( " " , colon ) ; let teamName = null ; let channelName = null ; let message = null ; if ( colon === - 1 || space === - 1 ) { userSettings . findOne ( { FB_ID : senderID } , function ( err , doc ) { teamName = doc . SELECTED_TEAM ; channelName = doc . SELECTED_CHANNEL ; message = messageText ; sendSlackMessage ( senderID , teamName , channelName , message ) ; } ) ; } else { teamName = messageText . substring ( 0 , colon ) ; channelName = messageText . substring ( colon + 1 , space ) ; message = messageText . substring ( space + 1 ) ; sendSlackMessage ( senderID , teamName , channelName , message ) ; } } } ) ; } }
Postconditions: the message received will be processed and replied to
Postconditions : the message received will be processed and replied to
//var recipientID = event.recipient.id; //var timeOfMessage = event.timestamp; //var messageId = message.mid; //var messageAttachments = message.attachments; //make sure the user has at least one slack account linked to their facebook account //if they don't, send them a sign in link //if the message starts with "/signin", send them a sign in link //if the message starts with "/signout", prompt to find which team the user wants to sign out of //go to the signout part of the condition below //if the message starts with "/subscribe", prompt to get the team of the channel to which the user wants to subscribe //go to the subscribe part of the condition below //if the message starts with "/unsubscribe", prompt to get the team of hte channel to which the users wants to unsubscribe //go to the unsubscribe part of the condition below //if the message starts with "/select", prompt to find the team the user wants to select //go to the select part of the condition below //if the message is a quick reply, process the payload //the payload is a string with pieces of information separated by "~_!", so split the payload by that string to get an array of information //if the user was previously entered "/subscribe", prompt to get the channel to which the user wants to subscribe //if the user previously chose a channel to which to subscribe, update the database with the new subscription //if the user previously entered "/unsubscribe", prompt to get the channel to which the user wants to unsubscribe //if the user previously chose a channel to which to unsubscribe, update the database with the new changes //if the user previously entered "/signout", update the database with the new changes //if the user previously entered "/select", prompt to find the channel the user wants to select //if the user previously entered a channel to select, update the database with user's selected team and channel //if the message isn't one of the above formats, assume the user wants to send a message //get the team name, channel name, and message from the facebook message //if the user doesn't specify the channel and team, get his/her selected team and channel //otherwise, parse the message for them and send the message based on them