Module debot
Spending – UNSTABLE DEPRECATED Describes how much funds will be debited from the target contract balance as a result of the transaction.
RegisteredDebot – UNSTABLE DEPRECATED Structure for storing debot handle returned from
init
function.ParamsOfAppDebotBrowserShowActionVariant – Show action to the user. Called after
switch
for each action in context.ParamsOfAppDebotBrowserSendVariant – Used by Debot to call DInterface implemented by Debot Browser.
ParamsOfAppDebotBrowserApproveVariant – Requests permission from DeBot Browser to execute DeBot operation.
ParamsOfStart – UNSTABLE DEPRECATED Parameters to start DeBot. DeBot must be already initialized with init() function.
Downloads debot smart contract (code and data) from blockchain and creates an instance of Debot Engine for it.
It does not switch debot to context 0. Browser Callbacks are not called.
type ParamsOfInit = {
address: string
}
type RegisteredDebot = {
debot_handle: DebotHandle,
debot_abi: string,
info: DebotInfo
}
function init(
params: ParamsOfInit,
obj: AppDebotBrowser,
): Promise<RegisteredDebot>;
function init_sync(
params: ParamsOfInit,
): RegisteredDebot;
NOTE: Sync version is available only for
lib-node
binding.address
: string – Debot smart contract address
debot_abi
: string – Debot abi as json string.
Downloads debot smart contract from blockchain and switches it to context zero.
This function must be used by Debot Browser to start a dialog with debot. While the function is executing, several Browser Callbacks can be called, since the debot tries to display all actions from the context 0 to the user.
When the debot starts SDK registers
BrowserCallbacks
AppObject. Therefore when debote.remove
is called the debot is being deleted and the callback is called with finish
=true
which indicates that it will never be used again.type ParamsOfStart = {
debot_handle: DebotHandle
}
function start(
params: ParamsOfStart,
): Promise<void>;
function start_sync(
params: ParamsOfStart,
): void;
NOTE: Sync version is available only for
lib-node
binding.Downloads DeBot from blockchain and creates and fetches its metadata.
type ParamsOfFetch = {
address: string
}
type ResultOfFetch = {
info: DebotInfo
}
function fetch(
params: ParamsOfFetch,
): Promise<ResultOfFetch>;
function fetch_sync(
params: ParamsOfFetch,
): ResultOfFetch;
NOTE: Sync version is available only for
lib-node
binding.address
: string – Debot smart contract address.
Calls debot engine referenced by debot handle to execute input action. Calls Debot Browser Callbacks if needed.
Chain of actions can be executed if input action generates a list of subactions.
type ParamsOfExecute = {
debot_handle: DebotHandle,
action: DebotAction
}
function execute(
params: ParamsOfExecute,
): Promise<void>;
function execute_sync(
params: ParamsOfExecute,
): void;
NOTE: Sync version is available only for
lib-node
binding.Used by Debot Browser to send response on Dinterface call or from other Debots.
type ParamsOfSend = {
debot_handle: DebotHandle,
message: string
}
function send(
params: ParamsOfSend,
): Promise<void>;
function send_sync(
params: ParamsOfSend,
): void;
NOTE: Sync version is available only for
lib-node
binding.message
: string – BOC of internal message to debot encoded in base64 format.
Removes handle from Client Context and drops debot engine referenced by that handle.
type ParamsOfRemove = {
debot_handle: DebotHandle
}
function remove(
params: ParamsOfRemove,
): Promise<void>;
function remove_sync(
params: ParamsOfRemove,
): void;
NOTE: Sync version is available only for
lib-node
binding.enum DebotErrorCode {
DebotStartFailed = 801,
DebotFetchFailed = 802,
DebotExecutionFailed = 803,
DebotInvalidHandle = 804,
DebotInvalidJsonParams = 805,
DebotInvalidFunctionId = 806,
DebotInvalidAbi = 807,
DebotGetMethodFailed = 808,
DebotInvalidMsg = 809,
DebotExternalCallFailed = 810,
DebotBrowserCallbackFailed = 811,
DebotOperationRejected = 812,
DebotNoCode = 813
}
One of the following value:
DebotStartFailed = 801
DebotFetchFailed = 802
DebotExecutionFailed = 803
DebotInvalidHandle = 804
DebotInvalidJsonParams = 805
DebotInvalidFunctionId = 806
DebotInvalidAbi = 807
DebotGetMethodFailed = 808
DebotInvalidMsg = 809
DebotExternalCallFailed = 810
DebotBrowserCallbackFailed = 811
DebotOperationRejected = 812
DebotNoCode = 813
type DebotHandle = number
type DebotAction = {
description: string,
name: string,
action_type: number,
to: number,
attributes: string,
misc: string
}
description
: string – A short action description. Should be used by Debot Browser as name of menu item.name
: string – Depends on action type. Can be a debot function name or a print string (for Print Action).action_type
: number – Action type.to
: number – ID of debot context to switch after action execution.attributes
: string – Action attributes. In the form of "param=value,flag". attribute example: instant, args, fargs, sign.misc
: string – Some internal action data. Used by debot only.
type DebotInfo = {
name?: string,
version?: string,
publisher?: string,
caption?: string,
author?: string,
support?: string,
hello?: string,
language?: string,
dabi?: string,
icon?: string,
interfaces: string[],
dabiVersion: string
}
name
?: string – DeBot short name.version
?: string – DeBot semantic version.publisher
?: string – The name of DeBot deployer.caption
?: string – Short info about DeBot.author
?: string – The name of DeBot developer.support
?: string – TON address of author for questions and donations.hello
?: string – String with the first messsage from DeBot.language
?: string – String with DeBot interface language (ISO-639).dabi
?: string – String with DeBot ABI.icon
?: string – DeBot icon.interfaces
: string[] – Vector with IDs of DInterfaces used by DeBot.dabiVersion
: string – ABI version ("x.y") supported by DeBot
DeBot wants to create new transaction in blockchain.
type DebotActivityTransactionVariant = {
msg: string,
dst: string,
out: Spending[],
fee: bigint,
setcode: boolean,
signkey: string,
signing_box_handle: number
}
msg
: string – External inbound message BOC.dst
: string – Target smart contract address.fee
: bigint – Transaction total fee.setcode
: boolean – Indicates if target smart contract updates its code.signkey
: string – Public key from keypair that was used to sign external message.signing_box_handle
: number – Signing box handle used to sign external message.
type DebotActivity = ({
type: 'Transaction'
} & DebotActivityTransactionVariant)
Depends on value of the
type
field.When type is 'Transaction'
DeBot wants to create new transaction in blockchain.
msg
: string – External inbound message BOC.dst
: string – Target smart contract address.fee
: bigint – Transaction total fee.setcode
: boolean – Indicates if target smart contract updates its code.signkey
: string – Public key from keypair that was used to sign external message.signing_box_handle
: number – Signing box handle used to sign external message.
Variant constructors:
function debotActivityTransaction(msg: string, dst: string, out: Spending[], fee: bigint, setcode: boolean, signkey: string, signing_box_handle: number): DebotActivity;
UNSTABLE DEPRECATED Describes how much funds will be debited from the target contract balance as a result of the transaction.
type Spending = {
amount: bigint,
dst: string
}
amount
: bigint – Amount of nanotokens that will be sent todst
address.dst
: string – Destination address of recipient of funds.
type ParamsOfInit = {
address: string
}
address
: string – Debot smart contract address
type RegisteredDebot = {
debot_handle: DebotHandle,
debot_abi: string,
info: DebotInfo
}
debot_abi
: string – Debot abi as json string.
Print message to user.
type ParamsOfAppDebotBrowserLogVariant = {
msg: string
}
msg
: string – A string that must be printed to user.
Switch debot to another context (menu).
type ParamsOfAppDebotBrowserSwitchVariant = {
context_id: number
}
context_id
: number – Debot context ID to which debot is switched.
Notify browser that all context actions are shown.
type ParamsOfAppDebotBrowserSwitchCompletedVariant = {
}
Show action to the user. Called after
switch
for each action in context.type ParamsOfAppDebotBrowserShowActionVariant = {
action: DebotAction
}
action
: DebotAction – Debot action that must be shown to user as menu item. At leastdescription
property must be shown from [DebotAction] structure.
Request user input.
type ParamsOfAppDebotBrowserInputVariant = {
prompt: string
}
prompt
: string – A prompt string that must be printed to user before input request.
Get signing box to sign data.
Signing box returned is owned and disposed by debot engine
type ParamsOfAppDebotBrowserGetSigningBoxVariant = {
}
Execute action of another debot.
type ParamsOfAppDebotBrowserInvokeDebotVariant = {
debot_addr: string,
action: DebotAction
}
debot_addr
: string – Address of debot in blockchain.
Used by Debot to call DInterface implemented by Debot Browser.
type ParamsOfAppDebotBrowserSendVariant = {
message: string
}
message
: string – Internal message to DInterface address. Message body contains interface function and parameters.
Requests permission from DeBot Browser to execute DeBot operation.
type ParamsOfAppDebotBrowserApproveVariant = {
activity: DebotActivity
}
Called by debot engine to communicate with debot browser.
type ParamsOfAppDebotBrowser = ({
type: 'Log'
} & ParamsOfAppDebotBrowserLogVariant) | ({
type: 'Switch'
} & ParamsOfAppDebotBrowserSwitchVariant) | ({
type: 'SwitchCompleted'
} & ParamsOfAppDebotBrowserSwitchCompletedVariant) | ({
type: 'ShowAction'
} & ParamsOfAppDebotBrowserShowActionVariant) | ({
type: 'Input'
} & ParamsOfAppDebotBrowserInputVariant) | ({
type: 'GetSigningBox'
} & ParamsOfAppDebotBrowserGetSigningBoxVariant) | ({
type: 'InvokeDebot'
} & ParamsOfAppDebotBrowserInvokeDebotVariant) | ({
type: 'Send'
} & ParamsOfAppDebotBrowserSendVariant) | ({
type: 'Approve'
} & ParamsOfAppDebotBrowserApproveVariant)
Depends on value of the
type
field.When type is 'Log'
Print message to user.
msg
: string – A string that must be printed to user.
When type is 'Switch'
Switch debot to another context (menu).
context_id
: number – Debot context ID to which debot is switched.
When type is 'SwitchCompleted'
Notify browser that all context actions are shown.
When type is 'ShowAction'
Show action to the user. Called after
switch
for each action in context.action
: DebotAction – Debot action that must be shown to user as menu item. At leastdescription
property must be shown from [DebotAction] structure.
When type is 'Input'
Request user input.
prompt
: string – A prompt string that must be printed to user before input request.
When type is 'GetSigningBox'
Get signing box to sign data.
Signing box returned is owned and disposed by debot engine
When type is 'InvokeDebot'
Execute action of another debot.
debot_addr
: string – Address of debot in blockchain.
When type is 'Send'
Used by Debot to call DInterface implemented by Debot Browser.
message
: string – Internal message to DInterface address. Message body contains interface function and parameters.
When type is 'Approve'
Requests permission from DeBot Browser to execute DeBot operation.
Variant constructors:
function paramsOfAppDebotBrowserLog(msg: string): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserSwitch(context_id: number): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserSwitchCompleted(): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserShowAction(action: DebotAction): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserInput(prompt: string): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserGetSigningBox(): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserInvokeDebot(debot_addr: string, action: DebotAction): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserSend(message: string): ParamsOfAppDebotBrowser;
function paramsOfAppDebotBrowserApprove(activity: DebotActivity): ParamsOfAppDebotBrowser;
Result of user input.
type ResultOfAppDebotBrowserInputVariant = {
value: string
}
value
: string – String entered by user.
Result of getting signing box.
type ResultOfAppDebotBrowserGetSigningBoxVariant = {
signing_box: SigningBoxHandle
}
signing_box
: SigningBoxHandle – Signing box for signing data requested by debot engine. Signing box is owned and disposed by debot engine
Result of debot invoking.
type ResultOfAppDebotBrowserInvokeDebotVariant = {
}
Result of
approve
callback.type ResultOfAppDebotBrowserApproveVariant = {
approved: boolean
}
approved
: boolean – Indicates whether the DeBot is allowed to perform the specified operation.
type ResultOfAppDebotBrowser = ({
type: 'Input'
} & ResultOfAppDebotBrowserInputVariant) | ({
type: 'GetSigningBox'
} & ResultOfAppDebotBrowserGetSigningBoxVariant) | ({
type: 'InvokeDebot'
} & ResultOfAppDebotBrowserInvokeDebotVariant) | ({
type: 'Approve'
} & ResultOfAppDebotBrowserApproveVariant)
Depends on value of the
type
field.When type is 'Input'
Result of user input.
value
: string – String entered by user.
When type is 'GetSigningBox'
Result of getting signing box.
signing_box
: SigningBoxHandle – Signing box for signing data requested by debot engine. Signing box is owned and disposed by debot engine
When type is 'InvokeDebot'
Result of debot invoking.
When type is 'Approve'
Result of
approve
callback.approved
: boolean – Indicates whether the DeBot is allowed to perform the specified operation.
Variant constructors:
function resultOfAppDebotBrowserInput(value: string): ResultOfAppDebotBrowser;
function resultOfAppDebotBrowserGetSigningBox(signing_box: SigningBoxHandle): ResultOfAppDebotBrowser;
function resultOfAppDebotBrowserInvokeDebot(): ResultOfAppDebotBrowser;
function resultOfAppDebotBrowserApprove(approved: boolean): ResultOfAppDebotBrowser;
UNSTABLE DEPRECATED Parameters to start DeBot. DeBot must be already initialized with init() function.
type ParamsOfStart = {
debot_handle: DebotHandle
}
type ParamsOfFetch = {
address: string
}
address
: string – Debot smart contract address.
type ResultOfFetch = {
info: DebotInfo
}
type ParamsOfExecute = {
debot_handle: DebotHandle,
action: DebotAction
}
type ParamsOfSend = {
debot_handle: DebotHandle,
message: string
}
message
: string – BOC of internal message to debot encoded in base64 format.
type ParamsOfRemove = {
debot_handle: DebotHandle