Skip to content
Docs
Modules Constructor

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:

ElementWhat it does
The accounts resourceThe Accounts field in the module's form: picking accounts from the Multogram database. It can't be changed or deleted
The Main functionHands 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 functionWork 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 functionSigns 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:

NameTitleTypeWhat to enter
chatChatStringWhere to write: @username, a t.me/… link or an ID
messageMessage textString, multi-line fieldWhat 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

  1. Save the project — Ctrl+S. The .agmp project appears in Recent modules on the Modules Constructor tab.
  2. Click Build module (the hammer in the top bar), enter the Name, Version and Description and click Build module.
  3. Choose where to save the .agm file, 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

CookiesPrivacy Policy

We use essential cookies to run this site. With your consent, we will also use analytics cookies to improve it and marketing cookies to credit whoever referred you. You can change your choice at any time.