mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-06 12:57:48 +00:00
change hubspot endpoint to grwoth server
This commit is contained in:
2
.github/workflows/production.yml
vendored
2
.github/workflows/production.yml
vendored
@@ -39,8 +39,6 @@ jobs:
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
"HUBSPOT_INIT_TOKEN=${{ secrets.HUBSPOT_INIT_TOKEN }}"
|
||||
"HUBSPOT_LIST_ID=${{ secrets.HUBSPOT_LIST_ID }}"
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
|
||||
2
.github/workflows/staging.yml
vendored
2
.github/workflows/staging.yml
vendored
@@ -40,8 +40,6 @@ jobs:
|
||||
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
|
||||
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
|
||||
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
|
||||
"HUBSPOT_INIT_TOKEN=${{ secrets.HUBSPOT_INIT_TOKEN }}"
|
||||
"HUBSPOT_LIST_ID=${{ secrets.HUBSPOT_LIST_ID }}"
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
|
||||
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -45,6 +45,4 @@ jobs:
|
||||
PUBLIC_APPWRITE_PROJECT_INIT_ID: ${{ secrets.PUBLIC_APPWRITE_PROJECT_INIT_ID }}
|
||||
APPWRITE_DB_INIT_ID: ${{ secrets.APPWRITE_DB_INIT_ID }}
|
||||
APPWRITE_COL_INIT_ID: ${{ secrets.APPWRITE_COL_INIT_ID }}
|
||||
HUBSPOT_INIT_TOKEN: ${{ secrets.HUBSPOT_INIT_TOKEN }}
|
||||
HUBSPOT_LIST_ID: ${{ secrets.HUBSPOT_LIST_ID }}
|
||||
run: pnpm run build
|
||||
|
||||
@@ -25,11 +25,7 @@ ENV APPWRITE_DB_INIT_ID ${APPWRITE_DB_INIT_ID}
|
||||
ARG APPWRITE_COL_INIT_ID
|
||||
ENV APPWRITE_COL_INIT_ID ${APPWRITE_COL_INIT_ID}
|
||||
|
||||
ARG HUBSPOT_INIT_TOKEN
|
||||
ENV HUBSPOT_INIT_TOKEN ${HUBSPOT_INIT_TOKEN}
|
||||
|
||||
ARG HUBSPOT_LIST_ID
|
||||
ENV HUBSPOT_LIST_ID ${HUBSPOT_LIST_ID}
|
||||
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { HUBSPOT_INIT_TOKEN } from '$env/static/private';
|
||||
|
||||
export const hubspot = {
|
||||
fetch: async (path: string, options?: RequestInit) => {
|
||||
return fetch(`https://api.hubapi.com/crm/v3/${path}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${HUBSPOT_INIT_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options?.headers
|
||||
},
|
||||
...options
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,23 +1,9 @@
|
||||
import { APPWRITE_COL_INIT_ID, APPWRITE_DB_INIT_ID, HUBSPOT_LIST_ID } from '$env/static/private';
|
||||
import { APPWRITE_COL_INIT_ID, APPWRITE_DB_INIT_ID } from '$env/static/private';
|
||||
import { appwriteInit } from '$lib/appwrite/init.js';
|
||||
import { isProUser } from '$lib/utils/console.js';
|
||||
import type { User } from '$routes/init/helpers.js';
|
||||
import { ID, Query } from '@appwrite.io/console';
|
||||
import type { TicketData, TicketDoc } from '../constants.js';
|
||||
import { hubspot } from '$lib/hubspot.server.js';
|
||||
import { isProUser } from '$lib/utils/console.js';
|
||||
|
||||
type Contact = {
|
||||
id: string;
|
||||
properties: {
|
||||
email: string;
|
||||
hs_object_id: '4831113';
|
||||
lastmodifieddate: '2024-01-24T09:16:04.042Z';
|
||||
};
|
||||
};
|
||||
|
||||
type ContactResults = {
|
||||
results: Array<Contact>;
|
||||
};
|
||||
|
||||
type SendToHubspotArgs = {
|
||||
name: string;
|
||||
@@ -25,43 +11,16 @@ type SendToHubspotArgs = {
|
||||
};
|
||||
|
||||
async function sendToHubspot({ name, email }: SendToHubspotArgs) {
|
||||
// See if contact exists
|
||||
const contacts: ContactResults = await hubspot
|
||||
.fetch('objects/contacts/batch/read', {
|
||||
await fetch('https://growth.appwrite.io/v1/mailinglists/init', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
properties: ['email'],
|
||||
idProperty: 'email',
|
||||
inputs: [
|
||||
{
|
||||
id: email
|
||||
}
|
||||
]
|
||||
email,
|
||||
name
|
||||
})
|
||||
})
|
||||
.then((res) => res.json());
|
||||
let contact = contacts.results?.[0];
|
||||
|
||||
if (!contact) {
|
||||
contact = await hubspot
|
||||
.fetch('objects/contacts', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
properties: {
|
||||
email: email,
|
||||
firstname: name
|
||||
}
|
||||
})
|
||||
})
|
||||
.then((res) => res.json());
|
||||
}
|
||||
|
||||
await hubspot
|
||||
.fetch(`lists/${HUBSPOT_LIST_ID}/memberships/add`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify([contact.id])
|
||||
})
|
||||
.then((res) => res.json());
|
||||
});
|
||||
}
|
||||
|
||||
async function getTicketDocByUser(user: User) {
|
||||
|
||||
Reference in New Issue
Block a user