← back to gquthier__calendly-ghl-webhook

Function bodies 7 total

All specs Real LLM only Function bodies
findContactByEmail function · javascript · L34-L40 (7 LOC)
server.js
async function findContactByEmail(email) {
  const url = `${GHL.baseUrl}/contacts/search/duplicate?locationId=${GHL.locationId}&email=${encodeURIComponent(email)}`;
  const res = await axios.get(url, { headers: ghlHeaders });
  const contact = res.data?.contact;
  if (!contact) return null;
  return contact;
}
findContactByPhone function · javascript · L43-L49 (7 LOC)
server.js
async function findContactByPhone(phone) {
  const url = `${GHL.baseUrl}/contacts/search/duplicate?locationId=${GHL.locationId}&number=${encodeURIComponent(phone)}`;
  const res = await axios.get(url, { headers: ghlHeaders });
  const contact = res.data?.contact;
  if (!contact) return null;
  return contact;
}
findOpportunityForContact function · javascript · L52-L57 (6 LOC)
server.js
async function findOpportunityForContact(contactId) {
  const url = `${GHL.baseUrl}/opportunities/search?location_id=${GHL.locationId}&contact_id=${contactId}&limit=20`;
  const res = await axios.get(url, { headers: ghlHeaders });
  const opportunities = res.data?.opportunities || [];
  return opportunities[0] || null;
}
updateOpportunityStage function · javascript · L60-L71 (12 LOC)
server.js
async function updateOpportunityStage(opportunityId) {
  const url = `${GHL.baseUrl}/opportunities/${opportunityId}`;
  const res = await axios.put(
    url,
    {
      pipelineId: GHL.pipelineSales,
      pipelineStageId: GHL.stageNewBooking,
    },
    { headers: ghlHeaders }
  );
  return res.data;
}
formatTypeformAnswers function · javascript · L74-L111 (38 LOC)
server.js
function formatTypeformAnswers(answers, fields) {
  const fieldMap = {};
  for (const f of fields) {
    fieldMap[f.id] = f.title;
  }

  return answers
    .map((answer) => {
      const title = fieldMap[answer.field.id] || answer.field.id;
      let value;

      switch (answer.type) {
        case "choice":
          value = answer.choice.label;
          break;
        case "text":
          value = answer.text;
          break;
        case "email":
          value = answer.email;
          break;
        case "phone_number":
          value = answer.phone_number;
          break;
        case "boolean":
          value = answer.boolean ? "Oui" : "Non";
          break;
        case "number":
          value = answer.number;
          break;
        default:
          value = JSON.stringify(answer[answer.type] ?? "");
      }

      return `${title}: ${value}`;
    })
    .join("\n");
}
extractEmailFromTypeform function · javascript · L114-L117 (4 LOC)
server.js
function extractEmailFromTypeform(answers) {
  const emailAnswer = answers.find((a) => a.type === "email");
  return emailAnswer ? emailAnswer.email : null;
}
updateContactCustomField function · javascript · L120-L128 (9 LOC)
server.js
async function updateContactCustomField(contactId, fieldId, value) {
  const url = `${GHL.baseUrl}/contacts/${contactId}`;
  const res = await axios.put(
    url,
    { customFields: [{ id: fieldId, field_value: value }] },
    { headers: ghlHeaders }
  );
  return res.data;
}