MyTommy.com

Building Mini Programs

Mini programs enable you to extend Tommy’s core functionality in almost any way. This flexibility is one of the key features of the Tommy platform.

There are three addon types that can be used for different purposes:

  1. Visual Mini Program Mini program which integrate with and extend the Tommy App interface.
  2. Non-Visual Addon Addons which integrate with the Tommy Action System
  3. A combination of both Visual and Non-Visual.

File Structure

The addon folder structure is very simple:

addons/{my_addon_version}/{my_addon_name}
.
├── manifest.yml
├── icon.png
└── views
    └── main.html
└── tasks
    └── mytask.js
└── locales
    └── en-US.json

The simplest possible mini program that has no views or tasks could be comprised of just a single manifest.yml file.

Let’s continue with an explanation of the manifest.yml file.

Manifest File

The manifest.yml manifest file is the most important file in a mini program. Each mini program must contain a single manifest file, which contains all the metadata information, configuration options, and a list of views and actions to be exposed by your mini program.

The example manifest below is taken from the very basic Poke mini program. This mini program contains just one view, one task, and one action, and the manifest file looks like this:

---
  title: "Poke"
  package: "poke"
  version: "1.0.0"
  summary: "Unleash your inner mongrel."
  description: "This is a super imaginative long description for the Poke addon."
  developer: "Kam Low"
  homepage: "https://mytommy.com"
  private: false
  dependencies: &dependencies
    email: "*"
    chat: "*"
  tasks:
    default:
      name: "Default"
      description: "Task that fires the `poke.triggers.default` trigger."
      execute: "tasks/poke.js"
  triggers:
    default:
      name: "Default"
      description: "Trigger that contains a single message string parameter."
      parameters:
        message:
          type: "string"
          required: true
  actions:
    poke_to_message:
      title: "Poke chat message"
      description: "Send an annoying scheduled poke message to team members."
      task: "poke.tasks.default"
      trigger: "poke.triggers.default"
      activity: "chat.activities.send_message"
      mappings:
        message:
          title: "Message text"
          type: "variable"
          value: "trigger.message"
      dependencies: *dependencies
      timer:
        cron: "0 9 * * *"
  views:
    main:
      title: "Poke"
      file: "views/main.html"
      type: "page"
      framed: false
      default: true
      assets:
        -
          type: "stylesheet"
          file: "views/main.css"
        -
          type: "javascript"
          file: "views/main.js"
        -
          type: "template"
          file: "views/main.tpl.html"
The manifest options are as follows:
  • title: (String) The human readable name of the mini program.
  • package: (String) The machine readable name of the mini program in underscore case.
  • version: (String) The release version number (must be incremented on each release).
  • author: (String) The addons author name (may be individual or organisation).
  • private: (Boolean) The privacy setting that determines if this mini program is usable by other Tommy users or not.
  • views: (Object) The object containing the views to be exposed on the interface.
  • actions: (Object) The object containing the predefined actions implemented by the mini program.
  • triggers: (Object) The object containing the action triggers implemented by the mini program.
  • conditions: (Object) The object containing the action conditions implemented by the mini program.
  • activities: (Object) The object containing the action activities implemented by the mini program.
  • roles: (Array) Can be any role that has been dynamically assigned to a team member, or one of the built in roles: “Team Member”, “Team Manager”, “Team Admin”.

Views

Each mini program may contain multiple views to be exposed on the interface. Views are defined within the views option in the manifest.yml file.

The manifest options are as follows:
  • id: (String) The view page id (must be unique within addon scope).
  • name: (String) The view page title.
  • file: (String) The relative view path to the view HTML file ie. client/main.html.
  • type: (String) The view type, current supported are page and form
  • index: (Boolean) Set to true for the main view that will be loaded when the mini program is started.
  • framed: (Boolean) Weather or not the view should be loaded inside an iframe.
  • roles: (Array) Can be any role that has been dynamically assigned to a team member, or one of the built in roles: “Team Member”, “Team Manager”, “Team Admin”.
  • lockable: (Boolean) Allows the index view to show a locked layout.

If you want your view to be framed inside an iframe, you can do so by specifying the framed: true option. This is good for security your view data, but be aware that since your view will be running in a sandboxed environment, none of the Tommy environment, API instance, or CSS styles will be available for use.