Pular para o conteúdo principal
Developers Buttons

Add buttons

Put buttons under any card. A button opens a link, changes the card for everyone the moment someone taps it, or tells your service it was pressed.

What you can do

  • Open a linkSend people to a page, a dashboard or a pull request.
  • Change the card on a tapEdit it, remove it, react or reply, straight from the press, with no server of your own.
  • Hear every pressYour service learns who pressed what, live.
  • Run a commandA button can fire one of the community's slash commands, with data.

In the app

Someone rings: the card appears

A tap on Open gate: the card changes for everyone

No server needed for the change itself: the steps are stored with the message. Your gate controller hears the press and opens the gate.

Quick start

  1. Add an actions list

    Buttons go in actions, next to the card, in a webhook post, a command reply or an update.

    json
    {
      "message_container": {
        "color": "yellow",
        "title": "Deploy v2.1 to production?",
        "description": "Requested by maya."
      },
      "actions": [
        { "type": "url:https://ci.example.com/deploys/218", "text": "View changes", "color": "blue" }
      ]
    }
    deploys
    System
    Message from Deploybot

    Deploy v2.1 to production?

    Requested by maya.
  2. Pick what a press does

    A link, a change to the card, or a call to your service. The three kinds are below.

Three kinds of button

The type decides what a press does.

TypeWhat a press doesReaches you
url:{url}Opens the link.No
webhook_actionRuns the steps you stored with it, for everyone in the channel.Yes, on the message's stream_url
trigger:{guid}Fires one of the community's triggers with the button's payload.Yes, as a new request to that trigger's URL

Change the card on a tap

A webhook_action button carries a list of steps in triggers. On a press they run on the mssgs server, in order, and everyone in the channel sees the result.

StepWhat it does, for everyoneFields
update_messageReplaces the card and its buttons. Send "actions": [] to take the buttons away.message_container, actions, content
remove_messageDeletes the message.None
add_reactionAdds a reaction, from the member who pressed.emoji
add_replyPosts a reply, from the member who pressed.content
json
{
  "message_container": { "color": "yellow", "title": "Front door", "description": "Someone rang the bell." },
  "actions": [
    {
      "type": "webhook_action",
      "id": "open_gate",
      "text": "Open gate",
      "color": "green",
      "payload": { "door": "front" },
      "triggers": [
        {
          "action": "update_message",
          "message_container": { "color": "blue", "title": "Front door", "description": "Opening…" },
          "actions": []
        },
        { "action": "add_reaction", "emoji": ":white_check_mark:" }
      ]
    }
  ]
}
Steps are read from the stored message, never from the member's app, so a press can only do what you put there.
Steps run in order and each one is attempted: if one fails, the rest still run.

Hear the press

A message with buttons comes back from the webhook with a stream_url. Keep it open and every press arrives as an event of type action, with the button's id, the stored button and its payload, and who pressed it:

sse
data: {"type": "action", "message_id": "...", "action_id": "open_gate", "action": {"id": "open_gate", "payload": {"door": "front"}, ...}, "member_guid": "member-guid", "member": {...}, "ts": 1790000000000}

Do the real work, like opening the gate, then set the final state of the card through callback_url. How the stream and the callback work is on live updates.

Run a command from a button

A trigger:{guid} button fires one of your community's triggers, as if someone had typed the command, and hands over the button's payload. The trigger receives:

json
{
  "actions": [
    {
      "type": "trigger:5f2c9a1e-trigger-guid",
      "text": "Check status",
      "color": "blue",
      "payload": { "order_id": "12345" }
    }
  ]
}
json
{
  "trigger_match": "/status",
  "message": {
    "content": "[Action Triggered]",
    "member_guid": "member-guid",
    "is_action_button": true,
    "action_payload": { "order_id": "12345" }
  },
  "callback_url": "https://mss.gs/api/v1/trigger-callback/...",
  "stream_url": "https://mss.gs/api/v1/instant/...?token=..."
}
What the trigger answers is posted as a new card. The request does not say which message the button was on: put what you need in payload.

Fields

FieldTypeWhat it does
typestringurl:{url}, webhook_action or trigger:{guid}. Required.
textstringThe label on the button. Required; label works too.
colorstringThe button's colour, see below.
idstringFor webhook_action: which button was pressed. Unique within the message.
payloadobjectYour data, handed back on a press.
triggersarrayFor webhook_action: the steps to run.
disabledbooleanShows the button greyed out, and presses are refused.

Colours

green, blue and purple draw a solid, primary button. red, orange and yellow draw a secondary one: use them for "Reject", "Cancel" and other careful choices.

Errors

When you post a message with buttons, mssgs checks them first:

CodeMeaning
INVALID_ACTIONS_FORMATactions is not a list of objects.
INVALID_ACTION_MISSING_FIELDSA button has no type or no text.
DUPLICATE_ACTION_IDTwo buttons share an id.
INVALID_TRIGGERS_FORMATtriggers is not a list of steps.
INVALID_TRIGGER_MISSING_ACTIONA step has no action.
INVALID_TRIGGER_ACTION_NOT_ALLOWEDA step other than the four above.

When someone presses

CodeMeaning
MESSAGE_NOT_FOUNDThe message was deleted in the meantime.
ACTION_NOT_FOUNDNo button with that id on the message.
ACTION_DISABLEDThe button is disabled.
TRIGGER_NOT_FOUND, TRIGGER_NOT_ACTIVEThe trigger a button points at is gone or switched off.
TRIGGER_NOT_ALLOWEDThe member does not have a role that may use that trigger.

Coming from the old docs?

Buttons of type button with ws:send steps, local:update_message and local:remove_message, previous:success conditions and expire_in_seconds no longer work for outside senders. Use webhook_action with the steps above: they reach everyone, not only the person who pressed.

Keep building