Slack

A message in your channel for every new lead.

The team hears about a lead within minutes, in the channel you choose.

  1. 1
    In Slack, create an app (api.slack.com/apps) and switch on Incoming Webhooks. Add it to a channel and copy its address.
  2. 2
    Make an API key. Open script.google.com and make a new project with the script below.
  3. 3
    Script properties: VISIONSAGE_KEY and SLACK_URL.
  4. 4
    Add a time-driven trigger for alertNewLeads, every 5 minutes.
Google Apps Script
// Slack alert for new leads. In Slack: create an app → Incoming Webhooks → copy the address.
// Google Apps Script (script.google.com) → New project → paste this → Save.
// Project Settings → Script properties → add VISIONSAGE_KEY (your API key) and SLACK_URL (the Slack address).
// Triggers → Add trigger → alertNewLeads → Time-driven → Every 5 minutes.
const API = 'https://api.crm.thevisionsage.com/v1/api';

function alertNewLeads() {
  const props = PropertiesService.getScriptProperties();
  const since = props.getProperty('LAST_ALERT') || new Date(Date.now() - 10 * 60 * 1000).toISOString();
  const started = new Date().toISOString();
  const res = UrlFetchApp.fetch(
    API + '/leads?pageSize=20&sortOrder=asc&createdFrom=' + encodeURIComponent(since),
    { headers: { Authorization: 'Bearer ' + props.getProperty('VISIONSAGE_KEY') } }
  );
  const body = JSON.parse(res.getContentText());
  body.data.forEach(function (lead) {
    UrlFetchApp.fetch(props.getProperty('SLACK_URL'), {
      method: 'post',
      contentType: 'application/json',
      payload: JSON.stringify({
        text: ':bell: New lead: *' + lead.name + '* ' + (lead.phone || lead.email || '') +
          (lead.source ? ' (' + lead.source.name + ')' : ''),
      }),
    });
  });
  props.setProperty('LAST_ALERT', started);
}

Something missing or unclear? Tell us and we will fix this page.