Skip to main content

Callback Functions

callback introduces a new way of creating functions in aoitelegram that are more flexible and have slightly more capabilities than regular custom functions.

Usage

$callback[callbackId;...args]
ParametersDescription
callbackIdNamed callback function
...argsArguments to be passed

Available Functions

In callback functions with the aoitelegram syntax, the following functions are available:

  • $arguments - array of arguments passed
  • $argumentsCount - the number of function args
  • $return - what to output upon completion of the function (after the interpreter reaches $return, reading will stop and the result will be output)

Examples

<AoiClient>.addCallback({
name: "ids",
type: "js",
callback: ({ splits }) => splits.join(" "),
});

<AoiClient>.addCallback({
name: "ids",
type: "aoitelegram",
code: `
$return[$argumentsCount, $arguments]
`
});

Examples Module

Furthermore, to prevent cluttering the main file, the LoadCommands class has been enhanced with the loadCallbacks method for loading callback functions:

const loader = new LoadCommands(<AoiClient>);
loader.loadCallbacks("./callback");
export default {
name: "ids",
type: "js",
callback: context => {
const [...args] = context.splits;
return args.map(arg => Number(arg));
},
};

export default {
name: "ids",
type: "aoitelegram",
code: `
$return[Ids count: $argumentsCount, id: $arguments]
`
};