Create a plugin
The application allows you to create a plugin automatically via Plugin Studio
. Although this is not essential for advanced users, we strongly advise you to always use it to have file templates directly in the right format and including the methods and properties useful for your development.
In addition to the server, plugins can be added to each A.V.A.T.A.R client.
A client plugin is generally used to perform client-specific actions that cannot be performed with APIs from a server plugin, or to add button wigdets to the client interface.
Note
it is not possible to create a plugin in a client's Plugin Studio
.
To create a plugin for a client :
- Create the plugin via the server's
Plugin Studio
. - Then copy the plugin to the client plugins folder.
- In the server interface, left-click on the server node.
- Menu
Edit
->Plugin Studio
. - Left-click to open the Plugin tab.
- Click on
Create a Plugin
to open the plugin creation window.
Step 1 - General information
Enter a name
(required): For the exercise, enter myFirstPluginEnter a display label
(optional): For the exercise, enter my first plugin
- Click on Next
Step 2 - The intention
The intention allows to check whether the sentence you are speaking validates a voice rule defined for the plugin.
The plugin has voice rules?
- Voice rules are not mandatory for a plugin.
For example, a plugin can manage automations or actions on peripherals directly without voice rules. - For the exercise, choose Yes.
- Voice rules are not mandatory for a plugin.
How are plugin rules checked?
- There are two ways to check a speech rule:
- By the syntax of the sentence.
- By a term in the sentence.
- For the exercise, choose By sentence syntax.
- There are two ways to check a speech rule:
Note
These choices are explained in detail in the intention section.
- Click on Next
Step 3 - The script
The script is the entry point for developing a plugin.
This step allows you to automatically add methods that interact with the application when necessary.
-
For the exercise, choose:
- init() method
- Language localization methods
- cron() method
-
Click on Next
Step 4 - Image and documentation
Image
- Choose an image inpng
format to be displayed for the plugin. An image is added by default if no image is selected.Documentation
- The Information tab inPlugin Studio
is available for displaying information about the plugin. In some cases, it may be preferable to create html documentation accessible via a browser. If the documentation requires an HTTP server, the A.V.A.T.A.R server can be used as the documentation server.
Note
To access a plugin's documentation, open the plugins tab, then do a left-click on the plugin. If the plugin is not the current one, the tab will close, so try again to display its contextual menu. If the plugin has documentation, the Documentation
menu will appear.
- Click on select then move to the assets/images/pluginCreation folder.
- Select the myFirstPlugin image.
- This image is an example; you can choose any
png
image from any directory. The image will be copied and renamed in the plugin's images folder.
- This image is an example; you can choose any
- Click on yes for HTML documentation.
- Add a index.html start page.
- Click on the “Documentation server” checkbox.
- click on Next.
Step 5 - Summary
- Review the creation information, then click on Create
Step 6 - Creation
- The myFirstPlugin plugin information page is displayed.
- Open the
Plugins
tab, My first plugin has been added.
- Click on the
Properties
tab to view the plugin's properties.
- Click on the plugin to open its menu and click on documentation.
- Close
Plugin Studio
.
Files created
Several files have been automatically created for the plugin, depending on the choices made earlier in the <A.V.A.T.A.R>/resources/app/core/plugins/myFirstPlugin folder.
Details of the files created for the myFirstPlugin project:
The intention file for checking whether the phrase you're speaking corresponds to a speech rule defined for the plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The action file called if the sentence is validated.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The script file called by the action file.
The script file including:
Line 7
: Theinit()
method executed when the plugin is loaded.Line 8
: Loads pack of the localized messages.Line 13
: Thecron()
function for executing tasks at regular intervals.Line 17
: Theaction()
function is the entry point for all plugin actions.Line 20
: Searchs for localized messages for the client language.Ligne 45
: Thetest()
function is the generic private test function added when the plugin was created. It must then be deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
The plugin properties file including:
Ligne 3
: A requiredmodules
.myFirstPlugin
object containing all plugin properties.Ligne 6
: Amodules
.myFirstPlugin
.rules
object with which the intention is checked in theintent.myFirstPlugin.js
file.Ligne 11
: Acron
object as requested when creating the myFirstPlugin plugin and defining the execution interval of thecron()
function in themyFirstPlugin.js
file. Default is every 2 hours.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The package.json
file is not mandatory, the plugin can work just fine without it.
However, this configuration file is preferable if you are adding npm
modules to the plugin.
Modify section values as required.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
This file has been created as an example and needs to be completed. It contains main objects (here “message”) grouping by category the messages you wish to add in <key>:<value>
Use the function Locale.get(“message.first”)
to retrieve the value
1 2 3 4 5 |
|
The documentation start page defined in the documentation.ini file. This file has been created as an example and must be modified.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
</head>
<body>
<h1>myFirstPlugin documentation</h1>
</body>
</html>
Test the plugin
A.V.A.T.A.R is updated with the new plugin without needing to restart.
You can view the plugin loading in the console if show all information option is active.
Say the rule to test the plugin:
- Rule:
test the command