Notifications from code: QubApp.notify
QubApp.notify lets code write to people of the panel through the service channels of Qubix, each channel its own method:
| Method | Where the message goes |
|---|---|
tgBot({ to, text, link }) | a private message of the Qubix notification bot, to the Telegram each person linked in Notifications |
qchat({ to, text, link }) | a line in each person's «Qubix» channel of TeleQube, labelled Aus Code |
email({ to, subject, text, link }) | a letter to each person's sign-in address, from the address for notifications |
The shortest example
function main() {
const me = QubApp.mcp.mcp_whoami().user_uuid;
QubApp.notify.tgBot({ to: me, text: 'Campaign 123 is paused: ROAS 0.4', link: '#/campaigns/123' });
}
Parameters
| Parameter | What it is |
|---|---|
to | one person's user_uuid or a list of them, 50 at most. Your own is QubApp.mcp.mcp_whoami().user_uuid; the people you manage are in QubApp.mcp.get_users() |
text | the message, plain text without markup, 3500 characters at most |
subject | the letter's subject, one line of 200 characters at most; email only |
link | a path of the panel that starts with #/, for example #/campaigns/123: the message gets a button that opens it, the letter ends with its full address |
Under the text Qubix writes who sent it and from which code — for example «Sent by Ivan Petrov from the script “ROAS pause”». The same tools called through QubApp.mcp.call('notify_tg_bot', …) are signed with the person alone in Scripts and page handlers.
Who may be written to
Yourself, always; the people of your team; an administrator — anyone whose account is active. A person who does not exist or may not be written to refuses the whole call.
The answer
Each method answers { sent, undelivered }: sent — the user_uuid of the people who got the message, undelivered — the others, each with its reason:
reason | Why |
|---|---|
no_telegram | the person has not linked Telegram in Notifications |
no_qchat | the person has not opened TeleQube yet |
inactive | the message was addressed to yourself while your own account is switched off; other people are named only while active |
failed | the channel did not take the message; Qubix writes the cause into its log |
A refusal of the whole server — the bot is not connected, TeleQube is off, the address for notifications is not chosen or its mailbox is removed — comes before the first message, so nobody gets it twice when the call is repeated.
Whose rights a call has
| Where the code runs | Whose rights the calls have | What the signature names |
|---|---|---|
| Scripts | the script's owner | the script |
| Page handlers | the site's owner; Ausführen refuses sending | the site |
| Britva rules | the rule's owner; a team or a global rule is refused | the rule |
The address for notifications
The letters of email leave from the address an administrator chose in Address for notifications of the company mail. A new address becomes a company mailbox, with read access for the person who chose it: replies to the letters arrive there. Until an address is chosen, email is refused.
Limit of messages
One run of code may send as many messages as the QubApp.notify messages per run field allows — the Notifications from code group on the JavaScript tab of System; 20 by default. Each person in each call is one message; a Britva rule gets the limit once per check cycle. The same number bounds each code per minute over all its runs and every way in, QubApp.mcp.call('notify_…') included: a page handler runs once per request, and past the number a call is refused until the minute turns.
When a call fails
A refused call throws an exception with the reason in words, in the language of the code owner's profile; a mistake in the parameters (no to, a parameter the method does not take) is a TypeError. An exception that is not caught stops the run with an error.