Skip to main content

Overview

Lua CLI provides built-in APIs for common operations, so you don’t have to build everything from scratch.
import { User, Data, CDN, Products, Baskets, Orders, Templates } from 'lua-cli';

User

Access and manage user data

Data

Custom data with vector search

CDN

File upload and retrieval

Products

E-commerce product catalog

Baskets

Shopping cart management

Orders

Order processing

Templates

Template messaging (WhatsApp)

User API

Access current user’s information.
import { User } from 'lua-cli';

const user = await User.get();
// Returns: { id, email, name, ... }

Example Tool

export class GetUserDataTool implements LuaTool {
  name = "get_user_data";
  description = "Retrieve current user's information";
  inputSchema = z.object({});

  async execute(input: any) {
    const user = await User.get();
    return {
      name: user.name,
      email: user.email
    };
  }
}

Full API Reference

Complete User API documentation

Data API

Store and retrieve custom data with semantic search capabilities.

Key Features

  • 🗄️ Custom Collections: Store any JSON data
  • 🔍 Vector Search: Semantic similarity search
  • 📊 Filtering: Query by field values
  • 📄 Pagination: Handle large datasets

Quick Example

import { Data } from 'lua-cli';

// Create with search indexing
await Data.create('movies', {
  title: 'Inception',
  director: 'Christopher Nolan',
  year: 2010
}, 'Inception Christopher Nolan 2010 sci-fi thriller dreams');

// Semantic search
const results = await Data.search('movies', 'mind-bending thriller', 10, 0.7);
// Finds "Inception" even though query doesn't contain exact words!

Use Cases

await Data.create('kb_articles', {
  title: 'How to reset password',
  content: 'Step by step guide...',
  category: 'Account'
}, `password reset account help`);

const results = await Data.search('kb_articles', 
  'forgot my password', 10, 0.7);

Full API Reference

Complete Data API documentation

CDN API

Upload and retrieve files from the Lua CDN.

Key Features

  • 📤 Upload Files: Store any file type
  • 📥 Retrieve Files: Get files by ID
  • 🖼️ Image Optimization: Automatic WebP compression
  • 🤖 AI Integration: Use with AI for image analysis

Quick Example

import { CDN } from 'lua-cli';

// Upload a file
const file = new File([buffer], 'document.pdf', { type: 'application/pdf' });
const fileId = await CDN.upload(file);

// Retrieve by ID
const retrievedFile = await CDN.get(fileId);
console.log(retrievedFile.name); // 'document.pdf'

Use Cases

// Store a document
const doc = new File([content], 'report.pdf', { 
  type: 'application/pdf' 
});
const fileId = await CDN.upload(doc);

// Save reference
await Data.create('documents', {
  title: 'Q4 Report',
  fileId: fileId,
  uploadedAt: new Date().toISOString()
});

Full API Reference

Complete CDN API documentation

Products API

Manage e-commerce product catalog.
import { Products } from 'lua-cli';

// Search products
const products = await Products.search('laptop');

// Create product
await Products.create({
  name: 'MacBook Pro',
  price: 1999.99,
  category: 'Computers',
  sku: 'MBP-14-001',
  inStock: true
});

// Get by ID
const product = await Products.getById('product_abc123');

Full API Reference

Complete Products API documentation

Baskets API

Shopping cart management for e-commerce.
import { Baskets, BasketStatus } from 'lua-cli';

// Create basket
const basket = await Baskets.create({
  currency: 'USD',
  metadata: { source: 'web' }
});

// Add items
await Baskets.addItem(basket.id, {
  id: 'product_xyz',
  price: 29.99,
  quantity: 2,
  SKU: 'PROD-001'
});

// Checkout
const order = await Baskets.placeOrder({
  shippingAddress: {...},
  paymentMethod: 'stripe'
}, basket.id);

Basket Statuses

Currently being used for shopping

Full API Reference

Complete Baskets API documentation

Orders API

Order creation and management.
import { Orders, OrderStatus } from 'lua-cli';

// Create order
const order = await Orders.create({
  basketId: 'basket_abc123',
  data: {
    shippingAddress: {...},
    paymentMethod: 'stripe'
  }
});

// Update status
await Orders.updateStatus(OrderStatus.FULFILLED, order.id);

// Get orders
const userOrders = await Orders.get(OrderStatus.PENDING);

Order Statuses

1

PENDING

Created, not yet confirmed
2

CONFIRMED

Confirmed, being processed
3

FULFILLED

Completed and delivered
4

CANCELLED

Cancelled by user or system

Full API Reference

Complete Orders API documentation

Templates API

Send template messages across different channels. Currently supports WhatsApp templates.
import { Templates } from 'lua-cli';

// List WhatsApp templates
const result = await Templates.whatsapp.list(channelId, { search: 'order' });

// Get specific template
const template = await Templates.whatsapp.get(channelId, templateId);

// Send template message
await Templates.whatsapp.send(channelId, templateId, {
  phoneNumbers: ['+447551166594'],
  values: {
    body: { customer_name: 'John', order_number: '12345' }
  }
});

Use Cases

  • 📦 Order notifications - Shipping updates, delivery confirmations
  • 📅 Appointment reminders - Healthcare, salon, service bookings
  • 🎉 Marketing campaigns - Promotions, announcements
  • 🔐 Authentication - OTP codes, verification messages

Full API Reference

Complete Templates API documentation

Combining APIs

Most real-world applications combine multiple APIs:

E-commerce Flow Example

export class QuickCheckoutTool implements LuaTool {
  async execute(input: any) {
    // 1. Search for product
    const products = await Products.search(input.productName);
    const product = products.data[0];
    
    // 2. Create basket
    const basket = await Baskets.create({ currency: 'USD' });
    
    // 3. Add product
    await Baskets.addItem(basket.id, {
      id: product.id,
      price: product.price,
      quantity: input.quantity
    });
    
    // 4. Create order
    const order = await Baskets.placeOrder({
      shippingAddress: input.address,
      paymentMethod: 'stripe'
    }, basket.id);
    
    return {
      orderId: order.id,
      total: basket.common.totalAmount
    };
  }
}

CRM with Custom Data Example

export class CreateCustomerTool implements LuaTool {
  async execute(input: any) {
    // Get current user
    const user = await User.get();
    
    // Create customer record
    const customer = await Data.create('customers', {
      name: input.name,
      email: input.email,
      company: input.company,
      createdBy: user.email,
      createdAt: new Date().toISOString()
    }, `${input.name} ${input.company} ${input.email}`);
    
    // Log interaction
    await Data.create('interactions', {
      customerId: customer.id,
      type: 'created',
      notes: 'Initial contact',
      timestamp: new Date().toISOString()
    });
    
    return { customerId: customer.id };
  }
}

API Comparison

APIBest ForKey Feature
UserProfile dataUser authentication
DataCustom schemasVector search
CDNFile storageUpload/retrieve files
ProductsE-commercePre-built catalog
BasketsShopping cartsTTL & status
OrdersOrder trackingStatus workflow
TemplatesProactive messagingWhatsApp templates

Next Steps