Skip to content

Commit

Permalink
made new command, get_new_deals
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Riess committed Jul 16, 2017
1 parent 4bfe671 commit 76e1fab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion create_engagement_for.js
Expand Up @@ -307,7 +307,7 @@ exports.handler = (event, context, callback) => {
// Task step 3
} else if (parseInt(sessionAttributes.engagement_step) === 2) {
// Parse and validate user's due date into epoch.
var due_date = time_helper.timeframe_check(event.inputTranscript);
var due_date = time_helper.timeframe_check(event.inputTranscript.toLowerCase());
if(due_date.range === true) {
due_date = due_date.comparable_high.unix() * 1000;
} else {
Expand Down
55 changes: 29 additions & 26 deletions get_new_deals.js
@@ -1,12 +1,12 @@
/**
* Intent:
* DealsInStage
* get_new_deals
*
* Description:
* Getting the number of deals that are in a specific stage of HubSpot.
*
* Slot Types:
* stage : {discovery, quote, negotiate, lost, won}
* stage : {discovery, quote, negotiate, lost, won}
* sales : {andrew, andy, john}
* confirmation : {yes, no}
*
Expand All @@ -26,42 +26,45 @@ exports.handler = (event, context, callback) => {
var slots = lambda_helper.parseSlots(event);

/*
* Stage
* Check for new deals
*/

// // First check if there is a value in the slot.
// if(slots.stage.value === null) {
// return lambda_helper.processValidation(callback, event, "stage", "What type of stage would you like to query? I have discovery, quote, negotiate, lost, or won available.");
// }

// https://developers.hubspot.com/docs/methods/deals/get_deals_created
hubspot_helper.createRequest("/deals/v1/deal/recent/created/?", "GET", null).then((body) => {
var message = "";
console.log("body", body)
console.log("body", body.results)
var messages = "";
var header = "";

// Loop through each of the deals and if one matches the id of the stage
// then increase the counter.
if(body.results == null) {
message = "You have \n" +
"Zero \n" +
"new <br />" +
'deals...<br />' +
'Hubsy leave now./';
if(body[0].results == null) {
message = `There are no new deals. Should I start cracking the robot whip on sales?`

} else {
var deals_total = 0;
var deals = [];

body.forEach((data) => {
data.deals.forEach((deal) => {
console.log(deal)
deals_total = data.total;
data.results.forEach((deal) => {
var name = deal.properties.dealname.value;
var amount = deal.properties.amount.value;
var owner = deal.properties.hubspot_owner_id.sourceId;
var stage_guid = deal.properties.dealstage.value;
var stage = null;

// Map stage guid to stage name.
config.stages.forEach((stage) => {
if(stage_guid == stage.guid) {
stage = stage.name;
};
});

deals.push(`Deal titled: ${name} owned by ${owner} worth $${amount} in ${stage} stage.`);
});
});

message = "I need to successfully break a line <br />" +
"Continued Message '/n'" +
"Still going /n" +
"Hubsy leave now. '/n'"
header = `There are a total of ${deals_total} new deal(s). Here are some of the most recent:\n`;
message = header + deals.join("\n");
};


return lambda_helper.processCallback(callback, event, "Fulfilled", message);
}).catch((err) => {
return lambda_helper.processCallback(callback, event, "Failed", err.message);
Expand Down

0 comments on commit 76e1fab

Please sign in to comment.