Skip to content

Web Mini Program Runtime Library ​

We provide a runtime library for Web Mini Programs that can conveniently call some methods.

You can install through package management tools:

sh
npm install @agilebot/extension-runtime
sh
yarn add @agilebot/extension-runtime
sh
pnpm add @agilebot/extension-runtime

You can also reference directly in the browser:

html
<script src="https://unpkg.com/@agilebot/extension-runtime/dist/browser.js"></script>

When you use the <script> tag to directly import the runtime library in the browser, all exported methods will be mounted on the global namespace gbtExtension .

For example, if you need to get the current language, you don't need to use import, but can directly call:

html
<script>
  gbtExtension.getLanguage().then(function (lang) {
    console.log(`Current language is: ${lang}`);
  });
</script>

Multi-language ​

When a Web Mini Program is opened in AgileLink, it needs to get the current language of the App and then switch the user's Web Mini Program language to be consistent with the App. This functionality can be implemented in the following way.

Example code:

ts
import { 
getLanguage
} from '@agilebot/extension-runtime';
const
currentLang
= await
getLanguage
();
console
.
log
(`Current language: ${
currentLang
}`);

Enable Shortcuts ​

When the extension's Web page is opened, some shortcuts will be disabled, such as physical buttons on industrial teaching pendants. You can enable shortcuts in the following way:

ts
import { 
enableShortcut
} from '@agilebot/extension-runtime';
enableShortcut
();

DANGER

If this method is not called, it may lead to the following consequences:

  • After the industrial teaching pendant screen locks, the screen cannot be awakened through physical buttons
  • You can only force shutdown and restart by pressing and holding the teaching pendant power button for more than 15 seconds

Display Components like Popups ​

To maintain a consistent style with AgileLink, we provide some common functions for displaying notification messages and popups.

rtmNotification - Notification Messages ​

Notification messages are used to display brief tips to users, supporting four types:

ts
import { 
rtmNotification
} from '@agilebot/extension-runtime';
// Show info notification
rtmNotification
.
info
('This is an info message');
// Show error notification
rtmNotification
.
error
('This is an error message');
// Show success notification
rtmNotification
.
success
('Operation successful');
// Show warning notification
rtmNotification
.
warning
('This is a warning message');

All notification methods support an optional detail parameter for displaying detailed information:

ts
// Notification with detail
rtmNotification
.
error
('Operation failed', 'Please check your input and try again');
rtmNotification
.
info
('System notification', 'You have 3 new messages');

API Reference ​

MethodParametersReturn ValueDescription
info(message, detail?)message: string
detail?: string
voidShow info notification
error(message, detail?)message: string
detail?: string
voidShow error notification
success(message, detail?)message: string
detail?: string
voidShow success notification
warning(message, detail?)message: string
detail?: string
voidShow warning notification

rtmMessageBox - Dialog Boxes ​

Dialog boxes are used for scenarios requiring user confirmation or input, supporting three types:

confirm - Confirmation Dialog ​

ts
import { 
rtmMessageBox
} from '@agilebot/extension-runtime';
// Basic usage
rtmMessageBox
.
confirm
('Are you sure you want to delete?')
.
then
(() => {
console
.
log
('User confirmed the operation');
}) .
catch
(() => {
console
.
log
('User cancelled the operation');
}); // Using async/await async function
deleteItem
() {
try { await
rtmMessageBox
.
confirm
('Are you sure you want to delete this item?');
console
.
log
('Deletion confirmed');
// Perform delete operation... } catch {
console
.
log
('Deletion cancelled');
} }

alert - Alert Dialog ​

ts
// Show alert dialog
rtmMessageBox
.
alert
('Please note: this operation cannot be undone!')
.
then
(() => {
console
.
log
('User has read the alert');
});

prompt - Input Dialog ​

ts
// Get user input
rtmMessageBox
.
prompt
('Please enter your name:', {
inputPlaceholder
: 'Enter name here',
inputValue
: 'Default name',
inputValidator
: (
value
: string) => {
if (!
value
) return 'Name cannot be empty';
if (
value
.
length
< 2) return 'Name must be at least 2 characters';
return true; },
inputErrorMessage
: 'Invalid input'
}) .
then
((
result
) => {
// prompt returns { value: string, action: string } on success
console
.
log
('User entered:',
result
);
}) .
catch
(() => {
console
.
log
('User cancelled input');
});

Advanced Configuration Options ​

All MessageBox methods support an optional second options parameter to customize the appearance and behavior of the dialog:

ts
rtmMessageBox
.
confirm
('Delete this item?', {
title
: 'Confirm Deletion',
type
: 'warning',
confirmButtonText
: 'Yes, Delete',
cancelButtonText
: 'Cancel',
center
: true,
closeOnClickModal
: false,
closeOnPressEscape
: false
});

Configuration Options ​

All MessageBox methods are based on Element UI's MessageBox component and support the following configuration options:

ParameterDescriptionTypeAccepted ValuesDefault
titleTitle of the MessageBoxstring——
messageContent of the MessageBoxstring / VNode——
dangerouslyUseHTMLStringWhether message is treated as HTML stringboolean—false
typeMessage type, used for icon displaystringsuccess / info / warning / error—
iconClassCustom icon's class, overrides typestring——
customClassCustom class name for MessageBoxstring——
callbackCallback when MessageBox closes if you don't prefer Promisefunction(action, instance)——
showCloseWhether to show close buttonboolean—true
beforeCloseCallback before MessageBox closes, and it will prevent MessageBox from closingfunction(action, instance, done)——
distinguishCancelAndCloseWhether to distinguish between canceling (clicking cancel button) and closing (clicking close button, overlay, or pressing ESC)boolean—false
lockScrollWhether to lock body scroll when MessageBox promptsboolean—true
showCancelButtonWhether to show a cancel buttonboolean—false (true when called with confirm and prompt)
showConfirmButtonWhether to show a confirm buttonboolean—true
cancelButtonTextText content of cancel buttonstring—Cancel
confirmButtonTextText content of confirm buttonstring—OK
cancelButtonClassCustom class name of cancel buttonstring——
confirmButtonClassCustom class name of confirm buttonstring——
closeOnClickModalWhether MessageBox can be closed by clicking the maskboolean—true (false when called as alert)
closeOnPressEscapeWhether MessageBox can be closed by pressing the ESC keyboolean—true (false when called as alert)
closeOnHashChangeWhether to close MessageBox when hash changesboolean—true
showInputWhether to show an inputboolean—false (true when called as prompt)
inputPlaceholderPlaceholder of inputstring——
inputTypeType of inputstring—text
inputValueInitial value of inputstring——
inputPatternRegexp for the inputregexp——
inputValidatorValidation function for the input. Should return a boolean or string. If a string is returned, it will be assigned to inputErrorMessagefunction——
inputErrorMessageError message when validation failsstring—Illegal input
centerWhether to align the content in centerboolean—false
roundButtonWhether to use round buttonboolean—false

Note

  • callback parameter: function(action, instance), where action can be 'confirm', 'cancel', or 'close', and instance is the MessageBox instance
  • beforeClose parameter: function(action, instance, done), where done is used to close the MessageBox instance
  • For more details, please refer to Element UI MessageBox Documentation

API Reference ​

MethodParametersReturn ValueDescription
alert(message, options?)message: string
options?: ElMessageBoxOptions
Promise<MessageBoxData>Show alert dialog
confirm(message, options?)message: string
options?: ElMessageBoxOptions
Promise<MessageBoxData>Show confirmation dialog
prompt(message, options?)message: string
options?: ElMessageBoxOptions
Promise<MessageBoxData>Show input dialog

Get Extension Status ​

You can get the current status of an extension in the following way:

ts
import { 
getExtensionState
} from '@agilebot/extension-runtime';
const
extension
= await
getExtensionState
('myService');
console
.
log
(`Extension enabled: ${
extension
.
enabled
}, Port: ${
extension
.
port
}`);

Whether in Extension Environment ​

When debugging Web pages locally, you can determine whether currently running in the extension environment or local computer:

ts
import { 
isInExtension
} from '@agilebot/extension-runtime';
console
.
log
(`Currently in extension environment: ${
isInExtension
()}`);