7. Technical Explanation#
7.1. What is WebAssembly?#
WebAssembly (WASM) is a binary instruction format based on a stack-based virtual machine, designed as a portable target for high-level languages such as C, C++, and Rust. It enables deployment in both client-side and server-side applications. For more details, refer to the official WebAssembly documentation <https://webassembly.org/docs/>.
7.2. Creating Custom WASM Files#
Write Code: Develop backend task logic in your preferred programming language.
Compile to WASM: Compile your code into a WASM file. Examples for Python and C:
Python: Use py2wasm to compile Python code into WASM.
C: Use Emscripten to compile C code into WASM.
Upload to MailTrigger: Upload the compiled WASM file to the MailTrigger system and set the execution interval (in seconds).
7.3. Sample Program#
Below is a simple example program demonstrating how to make http requests in Python and compile it into WebAssembly format:
# example.py
import json
# Get the current task information from the workspace's input.json
with open("./input.json", "r", encoding="utf8") as f:
input = json.loads(f.read())
mailboxId = input["mailboxId"]
taskId = input["taskId"]
# Write the parameters for executing the request
with open("/requests/get.txt", "w", encoding="utf8") as f:
config = json.dumps(
{
"url": "https://jsonplaceholder.typicode.com/posts/1"
}
)
f.write(config)
# Actually execute the request and get the response
with open("/requests/response.txt", "r", encoding="utf8") as f:
response = f.read()
After compiling the above program into WebAssembly format, it can be uploaded and used within the MailTrigger system.