Documentation

Plugin Guide

A plugin is two small files: one describing it and one with its code. This page shows everything a plugin can do, and the limits it runs under.

Free plugins ยท Runs in a sandbox

1. The two files

Put both in one folder (or at the top of a public GitHub repository). The plugin code is one JavaScript file of up to 1 MB. There is no require, no import, no files and no internet unless you ask for it: your code runs in a sealed sandbox, and a global object called tfx is the only way out.

turbofex-plugin.json

{
  "manifestVersion": 1,
  "id": "hello-plugin",
  "version": "1.0.0",
  "apiVersion": 1,
  "name": "Hello",
  "description": "Greets you and counts the greetings.",
  "author": { "name": "Your name" },
  "permissions": ["chat.send", "storage"],
  "commands": [
    { "name": "hello", "who": "everyone",
      "description": "Greets you and counts the greetings" }
  ]
}

index.js

tfx.command('hello', async (c) => {
  const count = Number((await tfx.storage.get('count')) || 0) + 1;
  await tfx.storage.set('count', String(count));
  await c.reply('๐Ÿ‘‹ *Hello ' + (c.sender.name || 'there') + '!*\nโ–ธ *Times used:* ' + count);
});
  • id: 3 to 32 characters, lowercase letters, numbers and dashes. version looks like 1.0.0 and goes up with every release. apiVersion is always 1.
  • name up to 40 characters, description up to 200. Only free plugins (leave out pricing).
  • Optional: "entry": "index.js" (the code file name) and "minBotVersion": "1.4.0".
  • Optional but recommended: "category", the menu section where your commands appear on the bot (bot 1.6.6 or newer): general, group, autoreply, status, watch, tools, fun, games, ai, budget, download, effect, media, audio, video, editor, security, lookup, other. Without it the bot guesses from your plugin's name and description, and the owner can always move it with .plugin category. Set it, so the guess is never wrong: a mention or tag-reply plugin is autoreply, a group tool is group.
  • A plugin needs at least one command, schedule or event.

2. Commands

Each command has a name (2 to 20 lowercase letters or numbers), up to 5 aliases, a description (up to 120 characters), and who can use it: everyone, admin or owner. Add "groupOnly": true to allow it only in groups, and "usage" for a short help line. Up to 20 commands. A name already used by the bot or another plugin is refused.

Your handler receives c:

  • c.args (the words after the command), c.rest (the same as one text), c.prefix
  • c.sender: { id, name, isAdmin, isOwner }. The id is a private code made for your plugin. You never see phone numbers.
  • c.chat: { id, isGroup, name }
  • c.mentions: the people tagged in the command or message (private codes)
  • c.mentionsOwner: in a message event, true when the owner was tagged (bot 1.6.5 or newer). A reply to someone's message is not a tag.
  • await c.reply(text) sends a message in the same chat.
  • c.quoted: when the command replies to a message, { text, sender, media } (the text of that message, who wrote it as a private code, and image, video, sticker, audio or null). Otherwise it is empty. c.hasMedia says what kind of file the command message itself carries.

3. Permissions

A plugin can only do what it lists in permissions. The bot owner sees the list, in plain words, before installing. Ask for as little as you can.

Low riskEverydaySafe, small things. Most plugins only need these.6
  • chat.sendc.reply and sending messages
  • storagetfx.storage.get / set / delete / list: its own small notes
  • chat.reactctx.react: react with one emoji to the message that used it
  • group.readtfx.group.info(): group name, size, number of admins
  • schedulerun now and then (schedules in the manifest)
  • media.sendtfx.media.send: pictures, stickers, files
Medium riskReads or sends moreThe owner will look at these a little closer.8
  • owner.notifytfx.owner.notify(text): message the bot owner
  • media.converttfx.media.toSticker and tfx.media.toAudio: the bot turns a picture into a sticker or audio into a small MP3
  • networktfx.net.fetch to the https websites you list in network.domains
  • events.messageread the text of group messages that are not commands
  • events.membersknow when someone joins or leaves a group
  • user.dmc.dm(text): a private message to the person who used the command
  • group.memberstfx.group.members(): the member list (private codes and who is an admin)
  • media.readtfx.media.download(): the picture, sticker, audio or short video a command was used on
High riskPowerfulCan change the group. Ask for them only when you truly need them.3
  • group.manageremove a member, open or close the group, rename it
  • group.adminsmake a member an admin, or take admin away
  • group.invitetfx.group.inviteLink(): the group invite link (admins only)

4. What you can call

  • tfx.storage.get(key) and tfx.storage.set(key, value): text only. Up to 200 keys, 64,000 characters per value, 1 MB in total. tfx.storage.delete(key) removes a note and tfx.storage.list() gives the list of keys (sorted).
  • ctx.react(emoji) (needs chat.react): reacts to the message that used the command or was heard by the listener. One emoji only (an empty text removes the reaction), 1 per call and 10 per minute. A plugin cannot react to any other message.
  • tfx.net.fetch(url) returns { status, text } (first 256,000 characters). Only https, only the domains you listed, up to 3 requests per call, 5 seconds each. tfx.net.fetchBytes(url) returns { status, base64 } (up to 1 MB), for pictures.
  • tfx.media.toSticker(data) and tfx.media.toAudio(data) (need media.convert): data is base64 text of a picture (PNG, JPEG, GIF, WebP) or an audio file (MP3, OGG, WAV, M4A, FLAC, AMR, WebM), up to 1 MB. You get base64 text back (a WebP sticker, or an MP3 of at most 60 seconds) that you can pass to tfx.media.send (kind sticker or audio). Up to 2 conversions per call and 6 per minute; the bot does the work, never the plugin.
  • tfx.media.send({ kind, data, mimetype, fileName, caption }): kind is image, sticker (WebP), audio (MP3, OGG, WAV, M4A, FLAC, AMR or WebM) or document; data is base64, up to 1 MB. The bot checks that the file really is what you say. Up to 3 per call, 6 per minute.
  • tfx.group.info() returns { name, size, admins } (inside a command in a group).
  • tfx.group.kick(member), tfx.group.open(), tfx.group.close(), tfx.group.rename(name) (1 to 100 plain characters), and with group.admins also tfx.group.promote(member) and tfx.group.demote(member) (one person per call, 6 an hour; promote, demote and rename work only inside a command used by a group admin, never from a listener or a timer; the group creator is never demoted): only where the bot is an admin, and only on people in the very command or event (never the owner, an admin or the bot). Up to 3 removals per call and 20 per hour.
  • tfx.owner.notify(text): up to 500 characters, 3 per hour.
  • New in bot 1.6.1 (Plugin API 1.1), all in the quick reference below: c.quote, c.mention, c.typing, c.poll, c.dm, tfx.group.members / describe / inviteLink, tfx.media.download, tfx.net.post, tfx.storage.chat.*, tfx.util.hash / fromBase64 and the events member.promote and member.demote. Plugins that need them should set "minBotVersion": "1.6.1".
  • tfx.log(text) writes to the plugin log the owner can read.
  • tfx.util.toBase64(text) turns text into base64 (the sandbox has no Buffer).

4b. Quick reference: every call

Everything a plugin can do, in one table. c is the handler's argument. All of it runs through the bot, which checks the permission, the limits and the target every time. A plugin never chooses who or what chat it talks to.

CallNeedsWhat you get, and the limits
c.reply(text)chat.sendMessage in the same chat. Up to 4,000 characters; 5 per call, 20 per minute (shared with quote, mention and poll).
c.quote(text)chat.sendThe same, sent as a reply to the message that triggered it.
c.mention(text, ids)chat.sendWrite {1}, {2}โ€ฆ in the text where the people should be tagged; ids are 1 to 10 private codes from c.sender, c.mentions, c.members or tfx.group.members().
c.typing(kind)chat.send'typing', 'recording' or 'paused'. 20 per minute.
c.poll(question, options, multi)chat.sendQuestion up to 250 characters, 2 to 12 different options of up to 100. multi true lets people pick several. 6 polls an hour.
c.react(emoji)chat.reactOne emoji on the triggering message. 10 per minute.
c.dm(text)user.dmPrivate message to the person who used the command (commands only). One per call, 10 an hour.
tfx.group.info()group.read{ name, size, admins }
tfx.group.members()group.membersA list of { id, admin } (private codes, no phone numbers), up to 1,024. The codes work with kick, promote, demote and mention.
tfx.group.kick / open / close / rename / describegroup.manageWhere the bot is an admin; never the owner or an admin. describe(text) is up to 500 plain characters. 6 changes an hour (kick: 20).
tfx.group.promote / demotegroup.adminsOnly inside a command used by an admin. 6 an hour.
tfx.group.inviteLink()group.inviteThe invite link, only inside a command used by an admin. 6 an hour.
tfx.media.download(which)media.readwhich is 'message', 'quoted' or 'any'. Gives { kind, mimetype, size, base64 } or null when there is no file. Up to 2 MB, 6 a minute, commands only.
tfx.media.send / toSticker / toAudiomedia.send / media.convertSee section 4.
tfx.net.fetch(url), tfx.net.fetchBytes(url)networkOnly your listed https domains. 3 requests per call.
tfx.net.post(url, body, type)networkSame rules. type is application/json (default), application/x-www-form-urlencoded or text/plain; body up to 64,000 characters; 10 a minute. Gives { status, text }. Redirects are not followed.
tfx.storage.get / set / delete / liststorageThe plugin's notes (text), 200 keys, 1 MB.
tfx.storage.chat.get / set / deletestorageThe same, but kept separately for each chat (keys up to 40 characters). Counts toward the same 1 MB.
tfx.util.hash(text, algo)nothingHex text of 'sha256' (default), 'sha1' or 'md5'. Up to 100,000 characters. The Playground only does sha256.
tfx.util.toBase64(text), tfx.util.fromBase64(b64)nothingText to base64 and back (UTF-8).
tfx.owner.notify(text)owner.notifyUp to 500 characters, 3 an hour.
tfx.log(text)nothingWrites to the plugin log. 100 lines per call.
tfx.on(event, fn)see section 5Events: message, member.join, member.leave, member.promote, member.demote.

Every call can fail (the owner did not allow it, a limit was reached, the target is protected), so use try / catch around the ones that matter. Calls the manifest does not declare count as strikes against the plugin; five strikes and the bot switches it off.

5. Events and schedules

Add "events": ["member.join"] to the manifest (with the permission it needs: message needs events.message; member.join, member.leave, member.promote and member.demote need events.members), then:

tfx.on('member.join', async (c) => {
  await c.reply('๐Ÿ‘‹ *Welcome to the group!*');
});

In a message event, c.text is the text of the message. In a join or leave event, c.members holds the people involved (private codes, up to 50). Events work in groups only, and the owner can switch a plugin off in a group with plugin groups <id> deny.

For a repeating job, add the schedule permission and "schedules": [{ "id": "daily", "everyMinutes": 1440 }] (1 to 10,080 minutes, up to 5), then tfx.schedule('daily', async () => { ... });. A scheduled run has no chat to answer in, so it can use tfx.owner.notify, tfx.storage and tfx.net.

5b. Options the owner can change

Add "settings" to turbofex-plugin.json and the bot builds the screens for you (.plugin options your-plugin and .plugin option your-plugin key value). No permission is needed. Your code reads the values from ctx.settings (for example ctx.settings.greeting); they are always valid and always there, because the default is used when nothing was set.

"settings": [
  { "key": "greeting", "type": "text", "label": "Greeting", "default": "hello", "maxLength": 20, "perGroup": true },
  { "key": "times", "type": "number", "label": "Repeat", "default": 1, "min": 1, "max": 5 },
  { "key": "shout", "type": "toggle", "label": "Shout", "default": false },
  { "key": "mood", "type": "choice", "label": "Mood", "default": "calm", "options": ["calm", "happy"] }
]
  • Up to 10 options. A key is a lowercase letter followed by letters and numbers (up to 20). A label is up to 60 characters, an optional description up to 120.
  • Types: text (plain text, maxLength 1 to 200), number (min and max), toggle (true or false) and choice (2 to 10 different options). The default must fit.
  • "perGroup": true lets the owner give one group its own value (by using the command inside that group). Without it the value is the same everywhere.
  • The owner's choices are kept when the plugin updates. A saved value that no longer fits the new definition is ignored and the default is used.

5c. Optional README and CHANGELOG

Put a README.md and a CHANGELOG.md next to turbofex-plugin.json (same folder, same tag). If they are there, people can open them on the Plugins page with the buttons "About this plugin" and "What changed". They are plain text up to 16 KB each (no pictures, no links that run, nothing is run). The site checks them when you send the plugin in, you and the reviewer can see them, and once your version is published they never change (the next version can have new ones).

5c-2. A logo for your plugin

Put a file called icon.png next to turbofex-plugin.json. It must be a square PNG picture, between 64 and 512 pixels wide, up to 32 KB. It is shown next to your plugin's name on the Plugins page. The reviewer sees it too, and it is covered by the store's signature, so nobody can swap it later. Like the README, it belongs to one version: change it in a new version.

5c-3. Screenshots

Up to three pictures that show your plugin working: screenshot1.png, screenshot2.png, screenshot3.png next to turbofex-plugin.json (in that order, no gaps). Each must be a PNG, between 200 and 2000 pixels on each side, up to 200 KB. They show on your plugin's card on the Plugins page, and like the logo they are covered by the store's signature and belong to one version.

5d. Test it before you send it

The TurboFex bot comes with a test tool that runs your plugin in the same sandbox the bot uses, with a pretend chat. Nothing is sent to anyone. Download the latest TurboFex release (zip) from GitHub, unpack it, run npm install once, then:

node tools/plugin-test.js path/to/your-plugin-folder
node tools/plugin-test.js path/to/your-plugin-folder --command "hello Sam"
node tools/plugin-test.js path/to/your-plugin-folder --event message --text "hi"

It first checks your two files with the same rules as the bot, then runs every command, event and schedule once and shows what the bot would say, react with, send or do in the group. Websites you call get a pretend answer unless you add --live-network. Use --as owner or --as admin to try a command that needs more than an everyday member. It does not replace the owner review.

No computer? Use the Playground: type or paste your two files and run them in your browser, with the same safety rules and a pretend chat.

5e. Send new releases automatically

Instead of pressing "Send for review" every time, you can let GitHub do it. On the Developers page, add your repository under "Send new releases automatically", then press "Show my webhook details". In your GitHub repository go to Settings, Webhooks, Add webhook. Paste the Payload URL, choose the content type application/json, paste the secret, pick "Let me select individual events" and tick only "Releases".

From then on, each time you publish a release, the plugin is copied at that release's tag and sent for review exactly like a manual send, with the same checks. Draft and pre-releases are ignored. The result of the last release is shown on your Developers page. Raise the version in turbofex-plugin.json before you tag, because a version that was already sent is refused. If the secret ever leaks, press "Make a new secret" and paste the new one into GitHub.

6. The limits

  • Each call may use about 1.5 seconds of computing time and 5 seconds in total, and 32 MB of memory.
  • Up to 5 messages per call and 20 per minute, up to 4,000 characters each.
  • A plugin that crashes 3 times in 10 minutes, runs out of time or memory, or keeps asking for things it did not list is switched off, and the bot owner is told.
  • Any change to the plugin files switches the plugin off until the owner installs it again, so every release is a new version.

7. Send it in

  1. Put the two files in a public repository on your GitHub account.
  2. On GitHub, make a release with a tag such as v1.0.0.
  3. Open the Developer Centre, sign in, and send the repository address and the tag.

You can test a plugin yourself first: copy the folder into the bot's data/plugins folder, then send .plugin install your-plugin-id.

Reviewers read the code. Keep it plain and readable: code that is minified, hides what it does, or builds code while running is flagged and is much more likely to be refused.