Assistant scripts
JavaScript or Python code the assistant or a staff member runs in a sandbox: find the customer in your API, check their server, reset a HWID.
A request to the project's API is described with fields and has no logic. A script has: it finds the customer's server in your panel by their confirmed id, checks it and returns the outcome, resets the device binding of this customer's subscription only. The assistant calls a script like any other tool and answers by what it returns. A staff member runs it from a ticket with a button.
The section is “Settings → Operator tools → Scripts”, right after AI Integration: the list of the project's scripts, where “Add a script” opens the editor, and Script secrets as the tab next to it, under the section's header. Star it to pin it, as any other section. The project's owner and admins write and change scripts. A script is one of the project's tools, as an API request of AI settings is, and a project has up to 20 tools in all.
Check or action
A script's page has General, Running, Parameters and Code, with the test run, the versions and the journal of runs below.
- Name is what staff see: in the list of scripts, in the ticket's Tools, in the assistant's suggestion and in the history.
- Name for the model — lower-case Latin letters, digits and
_, a letter first, 2 to 40 characters, sayreset_hwid. It can't be changed once saved. - When to call it — for the model: when to call the script and what it does. Whether the assistant calls it depends on this description.
- Enabled — a switched-off script is run neither by the assistant nor by staff. A test run in the editor works for a switched-off one too.
- Language — JavaScript (QuickJS) or Python 3.14. Changing the language doesn't translate the code.
- Parameters — up to 10 parameters: a name, a type (a string or a whole number), a description and whether it's required. In the code it's
ctx.params. The model takes the values only from the conversation and the customer's data, a staff member types them in.
The script's mode is Check or Action:
- Check only looks things up: a service's status, whether an address opens, the customer's data in the project's system. The assistant runs it by itself when it can't answer right without it, and any staff member can run it from a ticket.
- Action changes something in the project's systems: resets a HWID, changes an IP, makes a refund. An action has two more fields, below.
- Who runs it: An operator (the default) — the assistant doesn't run the action, it hands the ticket to staff and suggests the action with its values, and a staff member runs it with a button. The assistant itself — the assistant runs the action by itself, but only by the rules of How the assistant decides, and otherwise suggests it to staff too.
- Which staff may run it: Any operator (the default) or The owner and admins. The rule holds wherever a staff member runs the action: the Tools button, the assistant's suggestion and a macro step.
Writing a script
A run starts at the function main(ctx). What it returns goes to the model or the staff member: an object, a list, a string, a number, anything that converts to JSON. The API is the same in both languages and synchronous: a platform call returns its answer right away, there's no async or await, and an async main won't run. Nothing is kept between runs: each one starts afresh. Above the editor are the Reference and Secrets buttons. They open a panel right of the code, or under it on a narrow screen: an API reference with what's below and ready examples, and the project's secrets. Pressed again, a button closes the panel, and the browser remembers the tab it was left on.
ctx — what the script knows
ctx.params.order_id
ctx.ticket.subject
ctx.customer.verified
ctx.customer.data["billmgr:item.ip"]
ctx.project.slug
ctx.trigger| Field | What it is |
|---|---|
params | the script's parameters, as the model or a staff member passed them |
ticket | the ticket: id, number, subject, channel, status, created_at (UTC) and language (ru or en). null in a test run without a ticket |
customer | the ticket's customer, fields below. null without a ticket |
project | the project's slug |
trigger | who started the run: assistant, operator or test |
The fields of ctx.customer
| Field | What it is |
|---|---|
name, username | as on the contact's card |
email | an e-mail not from the widget: from a letter, the API, BILLmanager or an operator. One a widget visitor typed in doesn't reach the script. It doesn't confirm who the customer is: a letter's sender writes the address themselves |
phone | the WhatsApp number with +. null off WhatsApp |
telegram_id | the ID from Telegram or from the site's signature. One a visitor typed in is in fields as claimed_telegram_id, unchecked |
fields | the contact's details, without keys such as a password or a token and without VPN links |
data | what the assistant sees about the customer, as set in Customer data for the assistant: services, addresses, the balance. Keys such as billmgr:item.ip, and log in a test run with a ticket shows them all |
fields_truncated, data_truncated | true when something didn't fit: the whole ctx gets up to 256 KB |
verified | the identity is confirmed by the ticket's channel: the customer writes from Telegram, VK or WhatsApp (but not from a group), from BILLmanager or from the widget with a signed identify |
verified_via | how it is confirmed: telegram, whatsapp, vk, billmgr or widget_identify |
verified_user_id | the customer's id in your system: the one the site signed in identify, or bm:<id> for BILLmanager. null in a messenger |
The field to look the customer up by, depending on how the identity is confirmed:
telegram→telegram_idwhatsapp→phonebillmgr,widget_identify→verified_user_idvk→ no id in ctx
http — requests to external APIs
The request goes from the platform, only to addresses on the internet over http or https, with up to 3 redirects, each checked again. Methods: GET, POST, PUT, PATCH, DELETE and HEAD, with http.request(method, url, options) and the shortcuts http.get and http.post. In Python the options are keyword arguments and the answer is a dict: r["status"], r["json"].
const url = "https://api.example/orders";
const auth = "Bearer " + secret("API_KEY");
const r = http.get(url, {
params: { id: 42 },
headers: { Authorization: auth },
timeout: 5,
});
const { status, json } = r;
http.post(url, { json: { id: 42 } });
http.request("DELETE", url + "/42");| Request option | What it is |
|---|---|
headers | headers, up to 30 |
params | query parameters: strings, numbers, true, false, null or lists of them |
json, body | the body: json is a value, body a string, one of the two, up to 1 MiB |
timeout | seconds, up to 30, and no longer than the run has left |
auth | the HTTP Basic user and password, as a pair |
| Answer field | What it is |
|---|---|
status | the status code. A 4xx or 5xx doesn't raise: check it yourself |
headers | the answer's headers, names in lower case |
text | the body as text |
json | the body parsed as JSON when the answer is JSON, otherwise null |
An answer is read up to 256 KB, a larger one is the error too_large. An address that isn't on the internet (an internal network, localhost) and a name that doesn't resolve are the error blocked.
secret and crypto.hmac — the project's secrets
secret("PANEL_TOKEN") returns the secret's placeholder, not its value: the value never reaches the script. Put the placeholder into the address, the parameters, the headers, the body or auth of an http request, and the platform puts the value in, only over https and only when the request's host is one of the secret's hosts. Otherwise the request doesn't go: the error secret_host. A redirect that would carry a secret to a host off the list doesn't go either. The secrets themselves are set in Script secrets, or right in the editor, on the Secrets tab of the panel by the code.
const key = secret("API_KEY");
http.get(url, { params: { key } });
http.post(url, { auth: ["api", key] });
const sig = crypto.hmac("SIGN_KEY", body);
http.post(url, {
body,
headers: { "X-Signature": sig },
});A placeholder can't go into the host, the port or the fragment of the address, nor into a header's name. Should the external API echo the secret's value, the string or header holding it reaches the script as ***. No secret by that name is the error secret_missing.
crypto.hmac(name, data, alg) is an HMAC signature in hex. The platform signs with the secret's value, the script gets only the signature. The first argument is the secret's name, not its placeholder. The secret to sign with is at least 20 characters: a shorter one could be guessed offline from a signature, so the call raises the error secret_too_short. The algorithm is sha256, the default, or sha1, the data a string up to 1 MiB.
log — the run's log
log("status", r.status) writes a line to the run's log, the arguments joined by spaces. console.log in JavaScript and print in Python go there too. Staff see the log in the run's result and in the journal, the model doesn't get it. Up to 16 KB a run, the rest is dropped, and the result says the log was cut.
Errors
An exception the script doesn't catch ends the run with an error: staff see its type, message and line of code, the model only that the check didn't run. A platform call that fails raises ScriptCallError, the reason's code in code: catch it and return an outcome of your own. Every code is in Statuses and failures.
function main(ctx) {
try {
return http.get(url).json;
} catch (e) {
if (e instanceof ScriptCallError) {
return { error: e.code };
}
throw e;
}
}Script secrets
Tokens and keys to the project's APIs live in Script secrets, the second tab of the Scripts section. The same secrets are on the Secrets tab of the panel in a script's editor: add, replace and delete them there without leaving the code, and “Insert” puts the call secret("NAME") into the code at the cursor. Secrets are shared by the project: any script takes a secret by its name. The owner and admins change them.
- Name — capital Latin letters, digits and
_, a letter first, up to 64 characters, sayPANEL_TOKEN. It stays as saved. - Value — 8 to 4000 characters, and at least 20 to sign with
crypto.hmac. It's stored encrypted and never shown to anyone once saved, it can only be replaced. - Hosts — 1 to 10, one per line:
api.example.com, an IP address, or*.example.comfor its subdomains, with no scheme, port or path. A wildcard can't go right before a public suffix such as*.vercel.appor*.co.uk: anyone can get a subdomain there. The value goes only to these hosts and only over https. - Replace changes the value and the hosts together: the hosts don't change without a new value. So a stored value can't go to a new host without someone who knows it.
- Delete asks first. Scripts that call this secret get the error
secret_missing, and it comes back only with the value typed again. - A project has up to 20 secrets. Without a plan with scripts, secrets can't be added or replaced, but they can be deleted.
Personal tokens reach neither the secrets nor the test run nor a ticket's tools: those run code and actions in the project's systems. Try the assistant is open to a token, but the project's tools don't run there through it: each check comes back as not run.
Limits
The platform keeps limits so that no script holds up the assistant's answers or gets in the way of other projects.
| What | How much |
|---|---|
| Code | up to 64 KB (65,536 bytes) of UTF-8, 2 bytes to a Cyrillic letter, and up to 100,000 bytes once escaped: a backslash, a quote, a line break or a tab takes 2 bytes there, other control characters up to 6 |
| Parameters | up to 10 parameters, a string up to 500 characters, a whole number up to 9007199254740991 either way: make a long number a string |
| Tools | up to 20 tools a project, API requests included |
| Secrets | up to 20 secrets a project, up to 10 hosts a secret, a value of 8 to 4000 characters |
| Time | 40 s for the assistant, 45 s for staff and in a test run. About 2 s of CPU in that for the script's code, waiting for answers not counted. The whole run, the sandbox's calls included, gets no more than 6 s of CPU: a loop of empty calls such as time.sleep(0) spends hardly any of the code's budget and is stopped at this ceiling. Either way the error code is fuel |
| Memory | 128 MiB |
| Requests | up to 10 http requests a run, a timeout of up to 30 s, an answer of up to 256 KB, up to 3 redirects, up to 30 headers, a body up to 1 MiB |
| Calls | up to 500 platform calls a run, log not counted. Past them a call gets too_many_calls, and a script that catches the refusal and calls on is stopped on the 1001st call: output_cap |
| Log | up to 16 KB a run, the rest is dropped. Over 10,000 records (log calls and console output together), the run is stopped |
| Result | up to 64 KB of JSON and no more than 20,000 brackets [ and {, nesting up to 64 levels. The model reads the first 4096 bytes |
| Output | an output line up to 1 MiB, all output up to 8 MiB, stderr up to 64 KiB |
| At once | 2 runs of a project at once, the next one waits up to 5 s for a place. The platform as a whole also runs only a few at once: the next one waits up to 2 s for a free place, or ends as Limit reached |
| Rate | the assistant 2 per answer, 3 an hour per ticket and 60 an hour per project. A staff member 30 runs an hour in the project, any tools. In the editor, 60 test runs an hour per project |
| Repeats | the assistant runs the same action with the same values at most once a day per ticket |
| Storage | the journal of runs keeps 30 days, the code its latest 50 versions |
What the sandbox lacks
The code runs in a WebAssembly sandbox, in a container of its own with no network: the script sees neither the platform's database, internal network, files or environment, nor other projects' data. It reaches out only through the platform's calls.
- Everywhere. No network, files, processes or threads: the only way out is
http. No npm or pip packages. - JavaScript (QuickJS). No
fetch,setTimeout,Intl,TextDecoder,structuredCloneor WebCrypto. A pause isos.sleep(ms). Anos.setTimeouttimer never fires: the run ends withmain. Signing iscrypto.hmac.URL,URLSearchParams,TextEncoder,atobandbtoaare there. - Python 3.14. No
zlib, and so nogzip, nossl,sqlite3,ctypes,bz2orlzma.zoneinfohas no time zone data: give the offset yourself,timezone(timedelta(hours=3)).socket,urllib.request,subprocessandthreadingimport but don't work.
Examples
The same two examples are in the editor: API reference → Examples → Insert. An example replaces the code and sets its own mode. The address panel.example.com and the secret PANEL_TOKEN are for the example: put your panel's address and add a secret with its host. The examples have no parameters: they learn who the customer is from ctx.customer.
Customer lookup in the project's API
A check. Looks the customer up in the panel by their confirmed id, with the PANEL_TOKEN secret: by telegram_id in Telegram, by phone in WhatsApp, by verified_user_id in the widget with identify and in BILLmanager. With the identity unconfirmed, it doesn't look.
function main(ctx) {
const customer = ctx.customer;
if (!customer || !customer.verified) {
return { found: false, reason: "not_verified" };
}
let key = "user_id";
let id = customer.verified_user_id;
if (customer.verified_via === "telegram") {
key = "telegram_id";
id = customer.telegram_id;
} else if (customer.verified_via === "whatsapp") {
key = "phone";
id = customer.phone;
}
if (!id) {
return { found: false, reason: "no_id" };
}
const token = secret("PANEL_TOKEN");
const r = http.get("https://panel.example.com/api/users", {
params: { [key]: id },
headers: { Authorization: "Bearer " + token },
});
if (r.status === 404) {
return { found: false, reason: "not_found" };
}
if (r.status !== 200) {
return {
found: false,
reason: "panel_error",
status: r.status,
};
}
const user = r.json;
const isObject = typeof user === "object" && user !== null;
if (!isObject || Array.isArray(user)) {
return { found: false, reason: "not_found" };
}
return {
found: true,
id: user.id,
plan: user.plan,
expires_at: user.expires_at,
};
}
HWID reset
An action. Resets the devices of the customer's subscription by verified_user_id, only when their identity is confirmed. If the panel answers anything but 200 or 204, it writes the answer to the log and returns done: false with the reason, and the assistant answers the customer by that outcome.
function main(ctx) {
const customer = ctx.customer;
if (!customer || !customer.verified) {
return { done: false, reason: "not_verified" };
}
if (!customer.verified_user_id) {
return { done: false, reason: "no_user_id" };
}
const id = encodeURIComponent(customer.verified_user_id);
const url = "https://panel.example.com/api/users/" + id;
const token = secret("PANEL_TOKEN");
const r = http.post(url + "/hwid/reset", {
headers: { Authorization: "Bearer " + token },
});
if (r.status !== 200 && r.status !== 204) {
log("panel", r.status, r.text);
return {
done: false,
reason: "panel_error",
status: r.status,
};
}
return { done: true };
}
Test run
Under the code is the Test run: values for the parameters, an optional ticket and “Run”.
- The run is real: it spends the checks' quotas and carries out the script's actions, for the customer of the picked ticket too. The screen warns about it.
- With a ticket the script gets its
ctx.ticketandctx.customer, without one they arenull. To see whatctx.customer.dataholds, run a script that writesctx.customerto the log, with a ticket. - If the code is changed and not saved, the code in the editor runs. The run takes the saved language and parameters.
- A switched-off script runs too: you can try it before you switch it on.
- Below you see the status, the time, the number of requests, the result, the log and what the model would get. On an error, its code, message and line of code.
- Up to 60 test runs an hour per project.
- A run with a ticket leaves a line in its history, and an action with a ticket is a real action in it. While the assistant or a staff member runs the same action with the same values, the test run doesn't start. A run of the saved code that started closes the assistant's waiting suggestions of the same action: nobody runs it a second time with the button.
Versions and the journal of runs
- Code versions: every save of the code is a new version, and the latest 50 versions are kept. A version has a number, an author and a date, the current one is marked current. “View” shows the code, “Restore this version” makes its code the new current version, and the assistant and staff run it from then on. The code you have now stays in the list. With unsaved changes on the page, it first asks whether to drop them.
- Runs: the latest 50 runs of the past 30 days, who ran the script (the assistant, an operator or a test run), when, how it went, how long it took and how many requests it made, with a link to the ticket. A run opens to its parameters, result, log, error and the code's version, or a mark that unsaved code ran.
- The journal keeps runs for 30 days, and the assistant's suggestions as long. A deleted script goes with its versions, journal and suggestions.
How the assistant decides
Switched-on checks, and actions run by The assistant itself, are on the assistant's list of tools, next to API requests. If a result would change the answer, the assistant asks for a run instead of answering, the platform runs the script and asks the assistant again, now with the result. The model gets what main returned, the first 4096 bytes of JSON. It doesn't see the log.
A check
The assistant runs a check by itself and answers by its result as by an article: the result is a fact it may tell the customer. If the check didn't run (an error, time, a limit, the runner unavailable), the model reads that the check didn't run and answers without it or hands the question to staff.
An action
An action run by The assistant itself is run by the assistant only when all of this holds:
- the customer asks for it outright in their latest message, and only about their own data, not by text from quotes, links, pictures or forwarded messages. The message came by the ticket's own channel: a letter in a Telegram ticket doesn't start an action.
- the customer's identity is confirmed by the ticket's channel (
ctx.customer.verified): Telegram, VK, WhatsApp, BILLmanager or the widget with a signedidentify. E-mail and the widget's pre-chat form don't confirm it. - the conversation isn't about money and isn't a complaint: the model marks those in the same answer, and staff decide.
- the assistant hasn't handed the ticket to staff, and no operator has replied in it yet.
- the same action with the same values hasn't run in the ticket in the last 24 hours and isn't running right now, whoever runs it: the assistant, a staff member, a macro or a test run with this ticket. A run with an unknown outcome counts too.
Otherwise the action becomes a suggestion to staff: the assistant hands the ticket over, and the ticket shows a banner with a “Run” button. An action run by An operator the assistant only ever suggests.
- Done — the assistant tells the customer what exactly was done, by the script's result.
- Not done — the assistant doesn't say it's done, and may suggest the action to staff to run again.
- Outcome unknown (time ran out, or a request went out and no answer came) — the assistant doesn't tell the customer it's done and doesn't promise to repeat it. It won't run that action itself for a day, and may suggest it to staff to check and run.
- The next answers in the ticket see which actions already ran there and how they went, whoever ran them, and don't repeat them without a new request from the customer.
- No more than 2 suggestions per answer, and no more than 10 wait in a ticket. A waiting suggestion isn't made twice.
Time, limits and failures
- Scripts count in the assistant's check limits: 2 per answer, 3 an hour per ticket and 60 an hour per project.
- While a script runs, the New message notification waits for the assistant's decision, and the Telegram bot shows the customer “typing…”.
- If the script runner is unavailable (say, for the minute a platform update takes), the run gets the status Runner unavailable, and the assistant answers without the result.
Try the assistant and the Decision log
- In Try the assistant checks run for real and spend the quotas, while actions never run: the breakdown shows “would run” or “would suggest”. To try an action for real, run it with the test run in the editor. Through a personal token checks don't run either: each one is shown as not run.
- The decision's breakdown, the Decision log and the note under an answer have Checks and Actions lines. An action says how it went, “done”, “not done”, “outcome unknown” or “suggested to an operator”, and why the assistant didn't run it itself.
- Handing a ticket over, the assistant leaves staff a note with the results of checks and actions.
In a ticket
The Tools button
The ticket's row of actions has “Tools”, on a plan with scripts. Any staff member who can open the ticket sees it.
- The list has the project's switched-on scripts and API requests that this staff member may run. An operator doesn't see an action for the owner and admins only. Each tool shows its kind (Script or HTTP), and an action has an Action mark.
- The form takes the parameters' values. An action warns that it will change the customer's data in the project's system, and when the ticket's channel doesn't confirm the customer, that the values come from the conversation and may not be theirs.
- “Run” shows what the test run shows: the status, the result, the log, the time and the requests. A run takes up to a minute. Nothing goes to the customer, the run goes into the ticket's history and the script's journal.
- A staff member has 30 runs an hour in the project for any tools, suggestions and macro steps included.
- While the assistant or another staff member runs the same action with the same values, a second run doesn't start, and the window asks you to check the ticket's history.
- In streamer mode the values and everything the run returned are blurred.
The assistant's suggestion
Above the conversation, a banner such as “The assistant suggests: HWID reset (sub_id=123)” with “Run” and “Hide”. Under the line, why the assistant didn't run it itself: only staff run this action, the channel doesn't confirm the customer or the message came by another channel, it's about money or a complaint, the conversation was handed over, staff have already replied, the same action ran or is running (with the last run: who, how it went, when), the assistant hit its limits, its earlier run failed or its outcome is unknown.
- “Run” opens the form with the suggestion's values, which can be edited. If the staff member may not run this action, or the tool is switched off, they have only “Hide”.
- If two press it, one runs it and the other sees that the suggestion has already been run or dismissed. A run that didn't start (the runner unavailable, a limit) puts the suggestion back.
- A closed or resolved ticket doesn't show waiting suggestions, and they come back if it's reopened.
A macro step
A script also runs as the Run a script step of a macro: up to three scripts in order, on behalf of whoever applies the macro, by the same rules as “Run”. More in Macros.
The ticket's history
A run leaves a line such as these in the ticket's history:
- Operator ran “HWID reset” (sub_id=123): done
- The assistant ran “HWID reset” (sub_id=123): outcome unknown
- Test run “Customer lookup in the project's API”: error
The outcome is “done”, “error”, “timed out”, “limit reached”, “refused”, “runner unavailable” or “outcome unknown”. A line comes from a staff member's run from Tools or from a suggestion, a macro step, a test run with this ticket and an action the assistant ran by itself. The assistant's check leaves no line: its outcome is in the decision's breakdown.
- The customer doesn't see these lines, neither in the widget nor in a messenger. A line has no result or log: those are in the script's journal of runs.
- The values in a line are the customer's data: streamer mode blurs them.
- In the Audit log such lines are called Tool run, and an action of the assistant has Assistant in the Who column.
Statuses and failures
A run has one of six statuses:
| Status | When |
|---|---|
ok Succeeded | main returned a result |
error Error | the script failed or the platform couldn't run it: the failure code is below |
timeout Timed out | the run's time ran out, the code wall |
limit Limit reached | the places for runs of the project or of the runner are taken, the code busy |
denied Refused | the project's plan doesn't include scripts, the code plan |
unavailable Runner unavailable | the sandbox doesn't answer, say while the platform updates, the code runner. On Dedicated, check that the scripts container is running |
Run failure codes
| Code | What it means |
|---|---|
exception | the script raised an exception: staff see its type, message and line. A syntax error shows the same way, with its line |
no_main | the script has no main(ctx) function |
async_main | main(ctx) is async, and the script API is synchronous |
not_json | main(ctx) didn't return JSON, or it nests deeper than 64 levels |
fuel | the script used up its CPU time |
memory | the script ran out of memory: it has 128 MiB |
stack | stack overflow: the recursion is too deep |
trap | the sandbox stopped the script on a fault |
exit | the script exited before returning a result |
no_result | the script returned no result |
line_cap | an output line is longer than 1 MiB |
output_cap | the script wrote more than 8 MiB or more than 10,000 log records, or made more than 1000 platform calls |
stderr_cap | the script wrote more than 64 KiB to stderr |
result_cap | the result is larger than 64 KB or has more than 20,000 brackets [ and { |
code_too_large | the code is over 64 KB, or over 100,000 bytes once escaped |
wall | the script ran out of time, the status Timed out |
busy | too many scripts are running at once, the status Limit reached |
protocol | the exchange with the sandbox broke down |
plan | the project's plan doesn't include scripts, the status Refused |
runner | the script runner is unavailable, the status Runner unavailable |
no_code | there was no code to run |
internal | an internal platform error |
Call errors
A platform call that fails raises ScriptCallError with the code in code:
| Code | What it means |
|---|---|
bad_call | a call not as the API takes it: wrong arguments, nesting deeper than 64 levels or more than 20,000 brackets [ and { |
too_many_calls | more than 500 platform calls in a run |
http_limit | more than 10 http requests in a run |
bad_request | the arguments don't fit, the error's text says which |
blocked | the address isn't on the internet or the name doesn't resolve |
timeout | no answer in time, or the run has no time left |
unreachable | the server can't be reached or its answer can't be read |
too_large | the answer is over 256 KB |
redirects | more than 3 redirects |
secret_missing | the project has no secret by that name |
secret_host | a secret goes only over https and only to its own hosts |
secret_in_host | a secret's placeholder in the scheme, host, port, user info or fragment of the address |
secret_header | a secret's placeholder in a header's name or breaking a header, or a request with a secret sets Range, Accept-Encoding or the like |
secret_too_short | the secret to sign with is under 20 characters |
hmac_alg | the algorithm is neither sha256 nor sha1 |

