|
OperatorHowto
How to write new operator scripts
IntroductionEsmska features a pluggable operator system, which allows to create support for new operators as simple script files and add them to the program without the need of any program modification. With this plugin system, users can create their own operator plugins, and if it works well, they can send it to us so we can integrate it into official release. If you have some basic IT knowledge and you can create plugin for some local country or even international operator, you are very welcome. Creating your own scriptThe operator script is relatively simple to write. There are some rules, which you must abide, but they are quite easy to understand. The rest of the work lies in determining which data you must send to the operator website in order to have the message accepted. Recommended tools
Operator script specificsThe operator script file must be located in the operators directory inside the program installation folder. The filename of the script must contain only ASCII characters (space excluded) and be as similar to the true operator name (see below the format description) as possible. It must end with the .operator suffix, e.g. [XX]Foo.operator. The script file must be encoded in the UTF-8 encoding with standard LF newlines (standard UNIX format). It is recommended that you also supply and icon for your operator, which should be a 16x16 px PNG image with (preferably) transparent background. The filename of the image must be the same as the operator file, but ending with .png, e.g. [XX]Foo.png. The image file must also be in the operators directory. Supplying of the image file is not mandatory though, just recommended. Have a look into the operators folder for some examples. Internal format descriptionThe whole file is just a simple JavaScript file. Therefore you can use there everything which is possible to use in JavaScript. The JavaScript support is based on the Mozilla Rhino project. If you don't know JavaScript, it's a very simple language, just google up some JavaScript reference and you can work with it almost instantly. The script file must implement the OperatorInfo interface, which serves as an list of necessary information about the operator. Content of all the methods are described in their documentation. Additionally, the script must implement the send() method, which is used to actually send the message (see below). In the script you can use some variables, which are predefined and contain some important information. You can find list of these variables in the OperatorVariable enumeration. Be sure not to overwrite this variables with some your temporary ones! And don't forget that JavaScript (as most languages) is case sensitive. There is also one special variable called EXEC. With this variable, you can invoke the public methods listed in OperatorExecutor documentation. All these methods are executed by the program itself and some of them return you some result (e.g. content of the requested web page). Again, behaviour and return values are described in the methods descriptions. On the EXEC variable there are also some constant strings, which you can use to inform the user about particular problem in a localized message. Have a look at some existing operator files to see an examples of working plugins. The send() methodIt's just up to you, how you will use the provided methods and send the message. It's only required that you always end this method returning boolean, whether the message was sent successfully or not. There are also some recommendations you should know about:
Solving problemsPlease be aware of the fact that not all websites which you can use in your browser can also be used in Esmska. There are some extremely poorly-written websites, which this program simply can't handle. It includes only a basic HTTP library, which does not have all the powers and workarounds of full-featured web browser. Therefore websites complying with web standards should pose no problems, but some of the ugly websites may not work.
content = EXEC.getURL("http://somepage.com", [])
print(content)This way you can easily see what you actually got. Of course this means that you must run the program from the terminal/command line.
$ java -jar esmska.jar --debug network After running this command, you will see in the standard error output in your terminal lots of messages. During message sending you will see all HTTP headers of your requests and responses. If need also content of HTTP responses, you can get it with --debug full. But be warned, there will be hundreds of lines on the output. Having your script in the official releaseIt's a complete nonsense to use your script only by yourself. All the users should benefit from your work, that's the reason we have a pluggable operator system - so the users can contribute. If you want to share your work, just create a new issue in the issue tracker and attach your operator script (and the icon) to it. We will include it in the next official release and all the users will be able to benefit from your work. The same procedure also applies when you have found some bugs or you have some improvements to currently available plugins. Just modify them and send them over, we will appreciate it. Just a small legal notice: By sending us some of your work you agree to publish it under GPL-compatible free software license (meaning we can integrate it into our program). |