timesync
11/2/2016 - 4:05 AM

Propose a meeting time using the Freebusy Beta API

Propose a meeting time using the Freebusy Beta API

/**
 * freebusy-propose-meeting.js
 *
 * @author Kurt Collins (twitter/github: @timesync)
 * @author Parthiv Patel
 *
 * @platform Built.io Flow
 *
 * @description Node.js script to create an activity for proposing a meeting in Freebusy.io using
 *      Built.io Flow.
 *
 * @input
 *      str: The string you'd like to split.
 *      sep: The separator.
 *
 * @output
 *      arr: An array of strings.
 */

/**
 * Module configuration variables
 */
const activityId = 'freebusy-propose-meeting';						// Activity ID
const activityLabel = 'Freebusy Propose Meeting';					// Activity Label
const activityHelp = 'Booking URL for FreeBusy';					// Help Text

const activityInputSchema = {
    title: 'Freebusy Propose Meeting',
    type: 'object',
    properties: {
    	organizerName: {
            title: 'Organizer Name',
            type: 'string',
            description: "The organizer's name.",
            propertyOrder: 1,
            minLength: 1
    	},
        organizerEmail: {
            title: 'Organizer Email',
            type: 'string',
            description: "The organizer's email address.",
            propertyOrder: 2,
            minLength: 1
        },
        attendeeName: {
            title: 'Attendee Name',
            type: 'string',
            description: 'Email address of the attendee.',
            propertyOrder: 3,
            minLength: 1
        },
        attendeeEmail: {
            title: 'Attendee Email Address',
            type: 'string',
            description: 'Email addresses of the attendee.',
            propertyOrder: 4,
            minLength: 1
        },
        timeStart: {
            title: 'Start Time',
            type: 'string',
            description: 'Meeting start time.',
            propertyOrder: 5,
            minLength: 1
        },
        duration: {
            title: 'Duration in Minutes',
            type: 'string',
            description: 'Total length of time for the meeting in minutes.',
            propertyOrder: 6,
        },
        subject: {
        	title: 'Meeting Subject',
        	type: 'string',
        	description: 'The subject of the meeting to go in the invitation.',
        	propertyOrder: 7,
        	minLength: 1
        },
        location: {
        	title: 'Meeting Location',
        	type: 'string',
        	description: 'The location of the meeting.',
        	propertyOrder: 8,
        	minLength: 1
        }        
    }
};

const activityOutputSchema = {
    title:'Output',
    type: 'object',
    properties: {
        Url: {
            type: 'string',
            title: 'Url'
        }
    }
};

/**
 * executeActivity()
 *
 * @description This function performs the API call and any necessary manipulation.
 */
function executeActivity(input, output) {
	var proposalObj = {
		"organizer": {
			"email": input.organizerEmail,
			"name": input.organizerName
		},
		participants: [{
			"email": input.attendeeEmail,
			"name": input.attendeeName
		}],
		"startTime": input.startTime,
		"durationInMin": input.duration,
		"subject": input.subject,
		"location": input.location
	}
    var encodedObj = new Buffer(JSON.stringify(proposalObj)).toString('base64');
    var encodedUrl = "https://freebusy.io/meetings/schedule?proposal=" + encodedObj;

    var outputObj = {
    	'Url': encodedUrl
    }

    return output(null, outputObj);
}

/**
 * Built.io activity creation happens here.
 */
module.exports = function() {
    this.id = activityId;
    this.label = activityLabel;
    this.help = activityHelp;
    this.input = activityInputSchema;
    this.output = activityOutputSchema;
    this.execute = executeActivity;
};