Example server
Small server built with nodejs 22. This is a proof-of-concept to showcase how a minimal client integration could work.
Code
import { createServer } from "http"
// Create the HTTP server
const server = createServer((req, res) => {
// Get query parameters from the URL object
const parsedUrl = new URL(req.url || "", `http://${req.headers.host}`)
// Authenticate request with Authorization header and base64 encoded API key
const authToken = req.headers["authorization"]
if (!authToken || authToken !== "Basic MTMzNzEzMzcxMzM3MTMzNw==") {
res.writeHead(401)
res.end("Authorization header missing")
return
}
if (
req.method === "GET" &&
parsedUrl.pathname === "/imbox-integration" &&
query.view
) {
const qs = Object.fromEntries(parsedUrl.searchParams.entries())
const query = {
view: qs.view as "chat" | "ticket" | "call" | "contact",
email: qs.email,
phoneNumber: qs.phoneNumber,
externalId: qs.externalId
}
// In a real app you would get data from a database or other data source
const customer = {
customerId: "CUST12345",
name: "John Doe",
title: "Senior Account Manager",
preferredContactMethod: "email",
customerSince: "2024-01-01",
link: "https://crm-system.com/contact/12345"
}
const customerOrders = [
{ orderId: 1, product: "Shoes", value: 699, date: "2024-01-01" },
{
orderId: 2,
product: "Sunglasses",
value: 199,
date: "2024-02-02"
},
{ orderId: 3, product: "Scarf", value: 299, date: "2024-03-03" }
]
const result = {
contactLink: customer.link,
blocks: [
{
name: "Customer Information",
icon: "receipt_long",
data: [
{
type: "list",
rows: [
{
label: "Customer Id",
text: customer.customerId
},
{
label: "Name",
text: customer.name
},
{
label: "Title",
text: customer.title
},
{
label: "Customer since",
text: customer.customerSince
},
{
label: "Track orders",
text: "Open",
href:
"https://example.org/track-orders/" + customer.customerId
},
{
label: "Issue refund",
text: "Open",
href:
"https://example.org/issue-refunds/" + customer.customerId
}
]
},
{
type: "accordion",
headers: [
{
text: "Orders",
subtext: customerOrders.length.toString() + "st"
},
{
text: "Total",
subtext:
customerOrders.reduce((a, c) => a + c.value, 0).toString() +
":-"
}
],
data: [
{
type: "table",
headers: [
{ text: "Id" },
{ text: "Product" },
{ text: "Value" },
{ text: "Date" }
],
rows: customerOrders.map((order) => {
return [
{ text: order.orderId.toString() }, // col 1
{ text: order.product.toString() }, // col 2
{ text: order.value.toString() + ":-" }, // col 3
{ text: order.date } // col 4
]
})
}
]
}
]
}
]
}
res.setHeader("Content-Type", "application/json")
res.writeHead(200)
res.end(JSON.stringify(result))
} else {
res.writeHead(404)
res.end("404")
return
}
})
// Start the server
const PORT = 3000
server.listen(3000, () => console.log(`Running on port ${PORT}`))