| Accommodation | Customer | Guest | Reservation | Status | Actions |
|---|---|---|---|---|---|
| Loading… | |||||
| Accommodation | Customer | Guest | QR Scanned | Pending Tasks | Reservation | Actions |
|---|---|---|---|---|---|---|
| Loading… | ||||||
| Accommodation | Customer | Guest | Stay | Reservation | Status |
|---|---|---|---|---|---|
| Loading… | |||||
| Property ID | Hotel |
|---|
| Recipient | Disposition | Share | |
|---|---|---|---|
Primary Owner |
ACH Transfer | 100% | Edit → |
| Name | Trigger | Actions |
|---|
| Description | Location | Port | Status |
|---|
| Property ID | Hotel |
|---|
| Name | Type | Amount | Condition |
|---|
| Source | External ID |
|---|
| Action | Type | Trigger | Rules | Code |
|---|
| Customer | Name | Trigger | Actions |
|---|
| From | Room | Customer | Subject | Last Message | Received |
|---|---|---|---|---|---|
| Loading messages… | |||||
| Received | Event | Vector | Customer | Summary |
|---|
AMIE action code runs in an automata worker thread. The following functions/objects are in scope (injected by automata.mjs).
initData (reference shape)
initData is injected as var initData = {...}; before your code (when the action was started with parameters). For event-driven actions (webhooks, email, postbacks) it carries the full inbound event message:
| Field | Meaning |
|---|---|
cmd | The command string, e.g. event |
vector | Where the event came from, e.g. email-ingress, cloudbeds, postback |
customerid | Customer ID (number). 0 = Global (no customer) |
data | The event payload object (e.g. the parsed email, Cloudbeds webhook body) |
data.event | The event string, e.g. email/incoming, reservation/created |
data.event split on / | Left side = object (e.g. email), right side = intent (e.g. incoming) |
Example (email): initData.data.event = "email/incoming", initData.data.from = "Test <test@test.com>", initData.data.subject = "Hello", initData.data.files = [{filename, contentType, data}]
Lifecycle & control
End(data = null) — finishes the action. Pass a result object/string to core; End() with no arg = success, End('...') = error message. Worker exits after this.
Log(...msg) — log to the master (appears in worker logs). Objects are JSON.stringify’d.
Messaging / external
SendEmail(to, subject, message, cc = ’’) — send email via the gateway.
techSendTelegram(message) — send a Telegram alert.
await checkLLM(url, apiKey = null) — probe an OpenAI-compatible endpoint (GETs url + /v1/models). Returns the first model name (e.g. "gpt-4o") or null on error/timeout. Auth is sent as Authorization: Bearer; omit apiKey to use the llmApiKey module global (from automata’s LLMAPIKEY env).
await llmChat(systemPrompt, userPrompt, options, images) — call an OpenAI-compatible chat endpoint. options (required) must include url (base URL, no /v1) and model (model name, e.g. from checkLLM()). Optional: apiKey (defaults to llmApiKey), temperature (defaults to 0.2). Any other key is forwarded to chat.completions.create(). Returns the assistant’s message content (string) or null on error.
images (4th arg, optional) — array of image entries. Each becomes an OpenAI image_url content block (data URL) appended to the user message. Accepted shapes: extractPdf() result entries ({ page, width, height, bytes, mimeType } — pass result.images directly), { data, contentType }, a bare base64 string, or a Buffer/Uint8Array. Example: llmChat('Describe this document.', result.text, {url, model}, result.images)
await extractPdf(source, options) — extract text (and optional PNG pages) from a PDF via PDFium WASM (clawpdf). source accepts a byte array (Buffer), a file path, or a URL. For email attachments: Buffer.from(attach.data, 'base64'). Options: mode ('auto' default — text, falls back to rendered PNG pages when text is under minTextChars), maxPages, minTextChars, image: { dpi, maxPixels, forms }. Returns { text: string, images: [{ pageNumber, png }] } — png is raw PNG bytes.
openPdf(source) / createEngine() — lower-level clawpdf APIs for multi-page work: await using pdf = await openPdf(bytes), then pdf.text(), pdf.page(n).png({ dpi }). Page numbers are one-based.
RulesReload(customerid) — ask the master to reload customer rules (currently a no-op).
Crypto
Decrypt(encrypted) — synchronous AES-192 decryption (scrypt key).
Encrypt(clear) — async (returns Promise) AES encryption.
DB models (classes, instantiated with the shared pool)
new Integration(pool, customerid) — Cloudbeds credentials; .Load(), .Save(). Fields: clientID, clientsecret, authcode, refreshtoken, lasttoken, propertyID (all encrypted strings).
new Room(pool, customerid) — .Load(), .Save(), .Update()
new Reservation(pool, customerid, reservationID) — .Load(), .Save(), .Update(), .charges
new Location(pool, customerid) — .Load(), .Save()
new Rule(pool, customerid, name) — .Load(), .Save(); fields eventtype, intent, actionlist
new Action(pool, name) — .Load(), .Save(), .Update(); fields code, actiontype, intervalsecs, hours, minutes
new Customer(pool, customerid) — .Load(), .Save()
new Team / TeamList(pool), new Member / MemberList(pool), new Task / TaskList(pool), new RoomList / ReservationList / ActionList / LocationList / RulesList (pool[, filter]) — list loaders: .Load() returns an array.
APIs
new Cloudbeds(clientID, clientsecret, customerid, authcode, refreshtoken) — methods: .Login(), .setToken(token), .getRooms(propertyID), .getPropertyInfo(propertyID), .getWebHooks(propertyID), .createWebHook(...), .deleteWebHook(id).
new Telegram(...) — chatbot API.
new API(...) — generic base for external API calls.
Utilities
delaySecs(secs) — await delaySecs(5) to wait N seconds.
convertDate(ymd) — convert YYYY-MM-DD to US date string.
pool — the shared MariaDB connection pool (also usable directly).
llmApiKey — the LLM Bearer key (from automata’s LLMAPIKEY env, decrypted at startup). Use it directly, or let checkLLM() pick it up when you omit the 2nd arg.
myID — the worker thread ID. customerid — present when the action was spawned with a customer context.
| Customer | Contact | Locations | Accommodations |
|---|
| Team | Type | Staff | Location | On-call | |
|---|---|---|---|---|---|
|
Vista Cleaners A
T-101
|
Cleaning | 6 members | Costa Vista | 3 online | Edit → |
|
Vista Cleaners B
T-102
|
Cleaning | 5 members | Costa Vista | 2 online | Edit → |
|
Baywatch HVAC
T-207
|
HVAC | 4 members | Baywatch | 1 online | Edit → |
|
Marlin Repair Crew
T-215
|
Repair | 3 members | Marlin Bay | Offline | Edit → |
|
Palm Tech Support
T-310
|
Tech | 2 members | Palm Coast | 2 online | Edit → |
| Name | Role | Customer | Telegram | Status |
|---|
| Location | Hosts | Accommodations | Occupancy | Bots |
|---|
| Accommodation | Location | Customer | Type | Status | QR Seen | QR Vol |
|---|