View the Github project. View all of the files, fork the project and deploy to Heroku in a few clicks.
const { duration } = require("zenaton");
module.exports.handle = function*({ name, email, org_name }) {
// Search for the organization in pipedrive
let organization = yield this.run.task("FindOrganizationByName", org_name);
if (!organization) {
// Create the organization if it doesn't exist
organization = yield this.run.task("CreateOrganization", org_name);
}
// Search for the person in pipedrive
let person = yield this.run.task("FindPersonByEmail", email);
if (!person) {
// Create the person if it doesn't exist and link it to the organization
person = yield this.run.task("CreatePerson", { name, email }, organization);
// Create a deal and add the organization and assign a person to follow up
yield this.run.task("CreateDeal", organization, person);
// Send a slack message notifiying the team of a new lead
yield this.run.task(
"PostMessage",
`A new user has signed-up: ${person.email[0].value} ${person.name} working at ${person.org_name}`
);
} else {
// Send a slack message notifying team that an existing lead has signed up
yield this.run.task(
"PostMessage",
`An existing lead has signed-up: ${person.email} ${person.name}: congrats! :) `
);
}
// Add a note
yield this.run.task(
"AddNote",
person,
"This user has registered to the platform."
);
// Wait 2 days
yield this.wait.for(duration.days(2));
// Send a follow-up slack message to the SDR
yield this.run.task(
"PostMessage",
`The lead ${person.name} signed up 2 days ago. Did you contact them?`
);
};
A workflow instance is launched when a new user signs up with their parameters.
[
{
"name": "John",
"email": "john@gmail.com",
"companyName": "John's company"
}
]
Here are a few of the workflow tasks. You can see all task code in the github project.
The FindPersonbyEmail checks to see if the user is already in Pipedrive.
const pipedrive = require("../clients/pipedrive");
module.exports.handle = async email => {
const users = (
await pipedrive.get("/persons/find", {
params: { term: email, search_by_email: true }
})
).data.data;
return users && users.length > 0 ? users[0] : null;
};
The CreatePerson task adds the user to an existing organization.
const pipedrive = require("../clients/pipedrive");
module.exports.handle = async ({ name, email }, org) => {
return (
await pipedrive.post("/persons", {
name: name,
email: email,
org_id: org.id
})
).data.data;
};
The CreateDeal task creates a new deal in Pipedrive if the user is not found.
const pipedrive = require("../clients/pipedrive");
module.exports.handle = async (org, person) => {
return (
await pipedrive.post("/deals", {
title: `${org.name}'s Deal`,
person_id: person.id,
org_id: org.id
})
).data.data;
};
};
The PostMessage task sends a message to Slack.
const axios = require("axios");
module.exports.handle = async text => {
return (
await axios.post(process.env.SLACK_INCOMING_WEBHOOK, {
text
})
).data;
};
View the Github project where you can fork the project and deploy to Heroku in a few clicks.
Sample Projects
Start building workflows
Sign-up and run a sample project Learn more