import
{
CronJob
,
Pipeline
,
Webhook
}
from
'@core/engine'
import
{
HubSpot
,
Stripe
,
Slack
,
SendGrid
}
from
'@integrations'
import
{
db
,
redis
,
queue
,
logger
}
from
'@infra'
// ═══ CRM Sync — every 5 minutes ═══
const
syncCRM
=
new
CronJob
(
'*/5 * * * *'
,
async
() => {
const
leads =
await
db
.
query
(
'SELECT * FROM leads WHERE synced = false'
)
const
results =
await
HubSpot
.
bulk_create
(leads)
await
Slack
.
notify
(
'#sales'
,
`Synced ${results.length}`
)
await
db
.
update
(
'leads'
, { synced:
true
})
return
{ processed: results.
length
} })
// ═══ Stripe Webhook ═══
const
handler
=
new
Webhook
(
'/api/stripe'
,
async
(req) => {
if
(req.type ===
'payment_intent.succeeded'
) {
const
order =
await
Stripe
.
retrieve
(req.data.id)
await
db
.
insert
(
'transactions'
, order)
await
SendGrid
.
send
(order.email,
'receipt'
)
await
queue
.
add
(
'fulfillment'
, order) }
return
{ status:
200
} })
import
{
Router
,
auth
}
from
'@core/server'
import
{
OpenAI
,
Twilio
}
from
'@integrations'
import
{
logger
,
metrics
}
from
'@observability'
// ═══ Client Portal API ═══
const
router
=
new
Router
(
'/api/v2'
)
router
.
get
(
'/dashboard'
,
async
(req) => {
const
stats =
await
metrics
.
aggregate
(req.id)
const
tasks =
await
Airtable
.
list
(req.boardId)
return
{ stats, tasks } })
// ═══ AI Lead Scoring ═══
const
scoreLead
=
async
(lead) => {
const
history =
await
db
.
query
(
'SELECT * FROM interactions WHERE lead_id = ?'
, lead.id )
const
score =
await
OpenAI
.
chat
({ model:
'gpt-4'
, prompt:
`Score 1-100: ${history}`
})
if
(score.value >
80
) {
await
Twilio
.
sms
(lead.phone,
'Hot lead!'
)
await
Slack
.
notify
(
'#hot-leads'
, lead) }
return
score }
★
★
★
★
★
5.0
Trusted by
253+ SMBs
like you
We've worked with...