Your first module
A step-by-step example in the Multogram Modules Constructor: a module that sends a message to a chat from each selected account. The new module template (Main, ProcessAccount, AuthSession), settings fields, a test and an .agm build.
Let's build a "Message to a chat" module: the user picks accounts, enters a chat and a text, and the module sends this message from each account. Most of the work is already done by the new module template — all that's left is to add fields and one action.
The new module template
Click Create Module on the Modules Constructor tab. The constructor opens not with a blank sheet but with a ready module skeleton that works with accounts:
| Element | What it does |
|---|---|
| The accounts resource | The Accounts field in the module's form: picking accounts from the Multogram database. It can't be changed or deleted |
| The Main function | Hands accounts out to threads: each thread takes the next account from the list and passes it to ProcessAccount until the accounts run out. An error on one account goes to the log, and the thread moves on to the next one |
| The ProcessAccount function | Work with one account: sign-in through AuthSession, then your actions in the THEN branch, and Destroy Session at the end. If the sign-in failed — a log line in the ELSE branch |
| The AuthSession function | Signs in to the account with its .session and .json files, through the account's proxy if it has one. Returns true or false |
Each account comes into the scenario as an [[account]] object with the phone, session_path,
data_path and proxy fields — see Account picker field.
1. Add settings fields
In the Resources panel click Add Resource and create two resources:
| Name | Title | Type | What to enter |
|---|---|---|---|
chat | Chat | String | Where to write: @username, a t.me/… link or an ID |
message | Message text | String, multi-line field | What to send |
Name is the name for the scenario, Title is the field's label in the module form. Mark both fields as required: the module won't start without them. More in Resources and the module form.
2. Add an action
Open the ProcessAccount function and drag the Send Message action from the Telegram module into the THEN branch, before Destroy Session:
- Target —
{{chat}}; - Message —
{{message}}.
The finished function:
Call Function AuthSession ([[account]].session_path, [[account]].data_path, [[account]].proxy) → [[authorized]]
IF [[authorized]] == true
THEN Add Log "[[account]].phone: signed in"
Send Message Target: {{chat}} · Message: {{message}}
Destroy Session
ELSE Add Log "[[account]].phone: could not sign in"Handing out accounts, errors and finishing the work are handled by Main — you don't need to change it.
If an action is grayed out
Telegram actions belong to Multogram modes: Send Message belongs to the Mailer mode. If your account doesn't have the required mode, the action is shown grayed out, and a tooltip names the mode. The finished module will require these modes from everyone who runs it — see Requirements.
3. Check it
Set test values. In the Resources panel click Set Values and fill in chat,
message and test rows for accounts — the paths to a test account's files.
Run the test. Open Main and click Full Test at the bottom of the canvas (F6). The executed actions are highlighted, and the log is in the Inspector on the Logs tab.
The test runs for real
The messages are really sent. Test on a test account and your own test chat.
4. Save and build
- Save the project — Ctrl+S. The
.agmpproject appears in Recent modules on the Modules Constructor tab. - Click Build module (the hammer in the top bar), enter the Name, Version and Description and click Build module.
- Choose where to save the
.agmfile, and install it on the Modules tab.
When running, the user sees a form with three fields — Accounts, Chat, Message text — and picks the number of threads. The task ends by itself when the threads have processed all the selected accounts. More about building in Saving and building.
Updated
Modules Constructor
The guide to the Multogram Modules Constructor: how to build your own Telegram automation module — a scenario from ready-made actions, a settings form from resources, a test and a build into an .agm file. How a module is structured, key concepts and the workflow.
The constructor window
The Multogram Modules Constructor window: the actions panel, the scenario canvas, the top toolbar, resources, tests, the inspector, the AI assistant, hotkeys and settings.