Execute a Telegram Ads script
tg_executeRun JavaScript in an isolated sandbox to automate multi-step Telegram Ads tasks such as bulk edits, pagination, joins, and cross-ad analysis without many separate tool calls.
Instructions
Run JavaScript in an isolated QuickJS sandbox with a typed tg object, for multi-step work that would otherwise need many tool calls: bulk edits, cross-ad analysis, pagination, joins and reports. Only console.log output and the returned value come back. No network, filesystem, process or env access. Calls run sequentially; the limit is 25 API calls, 15 seconds and 64 KB of output. Example: const ads = await tg.getAdsList({limit: 100}); return ads.ads.length. Write methods require TG_ADS_MODE=write, TG_ADS_CODE_MODE=write and confirm: true.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "tg_execute"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | An async arrow function, a function expression, or a plain statement body. | |
| confirm | No | Required before any write method can run. | |
| idempotency_key | No | Prefix for write idempotency keys, useful when retrying a script. |