line

New Signup to CRM with slack notification

When a new user signs up in your application, add new or update their information in Pipedrive. Create an opportunity in Pipedrive and send an internal slack message with custom rules based on whether the new user is already a pipedrive contact.

Workflow Code

View the Github project. View all of the files, fork the project and deploy to Heroku in a few clicks. Or run it in the online sandbox without needing to install Zenaton.

Play on Zenaton

const pipedriveConnectorId = "<ENTER_YOUR_ZENATON_PIPEDRIVE_CONNECTOR_ID>";
const slackConnectorId = "<ENTER_YOUR_ZENATON_SLACK_CONNECTOR_ID>";
const slackChannel = "<ENTER_SLACK_CHANNEL_ID>";

let pipedrive = null;
let slack = null;

module.exports.handle = function*(user) {
  pipedrive = this.connector("pipedrive", pipedriveConnectorId);
  slack = this.connector("slack", slackConnectorId);

  let person = yield* findOneByEmail(user.email);

  if (person === null) {
    // Create a person on pipedrive
    person = yield* createPerson(user);

    // Create an organization and link it to the person created before
    const organization = yield* createOrganization(user.companyName, person);

    // Create a deal and add the organization and person in charge in it
    yield* createDeal(person, organization);

    // Send a slack message notifying the internal team of a new lead
    yield* sendSlack(
      slackChannel,
      `A new user has signed-up: ${user.email} ${user.name} working at ${user.companyName}`
    );
  } else {
    // Create a deal and add the organization and responsible team member
    const deal = yield* createDeal(person, person.org_name);

    // Add a note
    yield* addNote(person, deal);

    // Send a slack message notifying the internal team that an existing contact has signed up
    yield* sendSlack(
      slackChannel,
      `An existing user you already know has signed-up: ${user.email} ${user.name}: congrats! :) `
    );
  }

  // Wait 5 seconds
  yield this.wait.for(5);

  // Send a follow-up slack message to the SDR
  yield* sendSlack(
    slackChannel,
    `Following his registration, the user ${user.email} needs to be contacted again`
  );
};

function* createPerson(user) {
  return (yield pipedrive.post("/persons", {
    body: {
      name: user.name,
      email: user.email
    }
  })).data.data;
}

function* createOrganization(name, person) {
  return (yield pipedrive.post("/organizations", {
    body: {
      name: name,
      owner_id: person.id
    }
  })).data.data;
}

function* createDeal(person, organization) {
  return (yield pipedrive.post("/deals", {
    body: {
      title: `${organization.name}'s Deal`,
      person_id: person.id,
      org_id: organization.id
    }
  })).data.data;
}

function* sendSlack(channel, text) {
  return yield slack.post("chat.postMessage", {
    body: {
      text,
      as_user: false,
      channel
    }
  });
}

function* findOneByEmail(email) {
  return (yield pipedrive.get("/persons/find", {
    query: {
      term: email,
      search_by_email: true
    }
  })).data.data[0];
}

function* addNote(user, deal) {
  return yield pipedrive.post("/notes", {
    body: {
      content: "This user has registered to the platform",
      user_id: user.id,
      deal_id: deal.id
    }
  });
}

Workflow Input

A workflow instance is launched with the following input. A workflow can be launched using the quick launch button on the sandbox or via http.

[
  {
    "name": "John",
    "email": "john@gmail.com",
    "companyName": "John's company"
  }
]

Enter Credentials

To run this workflow in the sandbox or in your own project, you will need to add your credentials for authentication with the API connectors.

Get the slack channel_id from the channel url.

slack channel id

You will need to get the Pipedrive API to add it as a connector. You can find this info here:

find pipedrive API

Click on "Workflow Input" in the sandbox to edit the input. The curl will also update.

workflow input sandbox

View the Github project. View all of the files, fork the project and deploy to Heroku in a few clicks. Or run it in the online sandbox without needing to install Zenaton.

Play on Zenaton