Kenalko JavaScript
window.Kenalko reference — ready, init data (opener.username), fetch, upload, storage, and close.
Inside the Kenalko Apps screen, Kenalko injects window.Kenalko. Your bundle does not load an SDK. Call the methods below after the page is shown. The object is frozen — methods cannot be replaced.
In the web browser
Your bundle runs inside a sandboxed iframe. Kenalko enables file downloads from JavaScript (for example CSV or spreadsheet export via Blob, URL.createObjectURL, or <a download>) so download / leaderboard export buttons work like in a normal tab. Without that permission, the browser may block downloads with little or no message.
Methods
| Method | Result |
|---|---|
Kenalko.ready() | Signals ready, then returns init data (cached after the first call) |
Kenalko.getInitData() | The same init data, without the ready signal |
Kenalko.fetch({ url, method, headers, body }) | Calls your HTTPS API through the Kenalko proxy |
Kenalko.upload(file) | Uploads one file into the Kenalko Apps owner’s storage |
Kenalko.storage.get(key?) | Reads one slot, or every slot |
Kenalko.storage.set(key, object) | Stores a JSON object in a slot |
Kenalko.storage.remove(key) | Deletes a slot |
Kenalko.close() | Closes the screen and returns to chat |
Every method returns a Promise. On failure the Promise rejects with an Error that has err.code (see the table below) and err.status (HTTP).
Start
Call ready() once when the page opens. That tells Kenalko the Kenalko Apps is visible and loads the opener’s identity.
async function main() {
const init = await Kenalko.ready();
const username = (init.opener && init.opener.username) || '';
// Kenalko username of the person who tapped the card, without @
}
main().catch(console.error); getInitData() returns the same cached object. If nothing has been called yet, it loads init data but does not send the ready signal. Useready() at startup.Init data
{
app_id: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
revision: 3,
session_id: '01ARZ3NDEKTSV4RRFFQ69G5FB0',
conversation_id: '01…_01…',
owner_username: 'warung_nusantara',
opener: {
id: '01ARZ3NDEKTSV4RRFFQ69G5FAB',
username: 'demo_admin',
name: 'Sari',
is_guest: false
},
variables: { selected_poli: 'Dental' },
user_profile: { full_name: 'Sari Dewi' }
} | Field | Type | Meaning |
|---|---|---|
app_id | string | Kenalko Apps id |
revision | number | Bundle revision pinned on this card |
session_id | string | This opener’s session (new each time the card is opened) |
conversation_id | string | Chat thread. Personal chats are 53 characters (id_id). Groups and channels are 26 |
owner_username | string | Username of the account that owns the Kenalko Apps. Not the person who opened it |
opener | object | Person who tapped Open. See the next table |
variables | string map | Flow variables for this person. Present only when the card was sent from Flow |
user_profile | string map | Chat profile the owner stored for this opener. Absent for invite guests |
opener
| Field | Type | Meaning |
|---|---|---|
id | string | Kenalko user id |
username | string | Kenalko username, without @. Empty when a guest has no username |
name | string | Display name in Kenalko |
is_guest | boolean | true when opened from an invite link |
Match roles on your server with opener.username, not name. For example, username demo_admin can see the admin screens; any username that is not on your list stays a guest. On the backend, do not trust a username the page sends again — read the Kenalko-Apps-Id header on Kenalko.fetch (below).
variables anduser_profile may be missing. Every value is a string. The whole init object is at most 64 KB and 512 top-level keys. If Flow variables exceed that, the card cannot be opened.Kenalko.fetch
The Kenalko Apps must not call your server directly from the browser. Send the request through Kenalko.
const res = await Kenalko.fetch({
url: 'https://api.example.com/v1/orders',
method: 'POST',
headers: { Authorization: 'Bearer …' },
body: { table: '4', lines: [{ id: 'nasi-goreng', qty: 1 }] }
});
// res.status = upstream HTTP status
// res.data = upstream JSON object | Argument | Required | Rule |
|---|---|---|
url | yes | Public https:// domain. Not localhost, an IP, or a private network |
method | no | GET, POST (default), PUT, PATCH |
headers | no | Headers sent upstream. Names starting with Kenalko- are stripped, then Kenalko sets Kenalko-Apps-Id |
body | yes | JSON object, at most 64 KB and 512 keys. For GET, still pass {} — that body is not forwarded upstream |
The upstream response must also be a JSON object (not an array or plain text), at most 64 KB and 512 keys.
If the body includes file_id or file_ids, each id must be a file uploaded with Kenalko.upload in this session, or a file already in the Kenalko Apps owner’s File manager.
Kenalko-Apps-Id header
The value is base64url-encoded JSON. After decoding:
| Field | Meaning |
|---|---|
app_id | Kenalko Apps |
revision | Card revision |
session_id | Opener session |
conversation_id | Chat thread |
owner_username | Kenalko Apps owner |
opener_user_id | Opener id |
opener_username | Opener’s Kenalko username — the same source as init.opener.username |
Use opener_username on your server to decide the role (admin, kitchen, guest). Do not rely on a ?username= query the browser can change.
Kenalko.upload
const input = document.querySelector('input[type=file]');
const meta = await Kenalko.upload(input.files[0]);
// { file_id, name, mime, size } The file counts against the Kenalko Apps owner’s storage quota. Pass file_id again in a Kenalko.fetch body.
Kenalko.storage
Server storage on Kenalko, per Kenalko Apps and per user. Web and mobile share the same slots. At most 10 slots. Slot names are 1–64 characters: letters, digits, _, ., and -. Values are JSON objects, at most 64 KB and 512 keys.
await Kenalko.storage.set('draft', { note: 'Table 4' }); // { ok: true }
const draft = await Kenalko.storage.get('draft'); // { note: 'Table 4' } or null
const all = await Kenalko.storage.get(); // { draft: { note: 'Table 4' } }
await Kenalko.storage.remove('draft'); // { ok: true } Slots are not shared with other people in the same group. Opening the card again still reads the same slots until you remove them.
Kenalko.close
await Kenalko.close(); The Kenalko Apps screen closes and the user returns to the same chat. The back icon on the Kenalko bar (outside your bundle) does the same thing.
Sessions
- Lasts 24 hours, extended while the screen stays open.
- Opening the card again creates a new session and fresh init data. The bundle revision stays the one pinned when the card was sent.
- In a group or channel, each member has their own session,
opener, Flow variables, profile, and storage slots.
Error codes
err.code | When |
|---|---|
kenalko_app_session_expired | Session ended. Ask the user to open the card again |
kenalko_app_proxy_url_invalid | URL is not public HTTPS |
kenalko_app_request_not_json_object | Fetch body is not a JSON object |
kenalko_app_response_not_json | Your server did not reply with JSON |
kenalko_app_response_not_json_object | JSON reply is not an object |
kenalko_app_response_too_large | Reply is over 64 KB or 512 keys |
kenalko_app_file_forbidden | file_id is not from this session or the owner |
kenalko_app_storage_limit_reached | Already 10 slots |
storage_quota_exceeded | The Kenalko Apps owner’s file quota is full |
bad_request | Slot name or argument is invalid |