Buttons

TrueConfAbout 16 min

Buttons

Starting from version 5.5.6, TrueConf Chatbot Connector supports inline buttons that appear directly below the message:

/docs/chatbot-connector/media/buttons_example_3/en.png

Inline buttons allow users to interact with the bot without typing text: execute a command, open a link, send a message, or copy data to the clipboard. The buttons are attached to messages of type 200 (PLAIN_MESSAGE) and can only be sent by chat bots. Changing the set of buttons for a sent message is done through editing it (editMessage).

The display of inline buttons in the chat depends on the version of the client application:

  • Windows/Linux/macOS: 8.6.0+
  • Android: 3.3.0+
  • iOS: 4.2.0+

Button Styles

Different button styles are available:

/docs/chatbot-connector/media/buttons_styles/en.png

You can set the style using the optional style field. If the field is not specified, the default style is used.

StyleThe value of styleDescription
By defaultnot specifiedThe default button design is used if the style field is not specified.
AccentprimaryThe button is highlighted with the accent color of the client application.
DangerousdangerStyle for "dangerous" actions
PositivesuccessStyle for "positive" actions

Types of buttons

Currently, four types of buttons are supported. The type is specified using the mandatory type field within the button object.

TypeThe value of typePurpose
MessagemessageSends a message in the chat on behalf of the user or inserts it as a draft.
LinkurlOpens an external link or TrueConf resource
CopyingcopyCopies data to the clipboard
TeamcommandSends a command to the bot without posting a message in the chat

Button "message"

The button sends a message to the chat, generated by the bot, on behalf of the user who clicked the button. If the parameter draft: true is specified, the message is not sent but is instead placed in the text input field of the client application as a draft.

FieldTypeMandatoryDescription
typestringYesButton type — string "message"
idstringNoUnique button identifier, string. It can be used for additional identification of the pressed button.
меткаstringYesThe string that will be displayed on the button in the client, with a maximum length of 32 Unicode characters.
stylestringNoButton display type: primary, danger, success
сообщениеstringYesThe text of the message that will be sent upon clicking. All rules and restrictions applicable to standard sent messages apply.
черновикbooleanNoIf true, instead of sending, the message is placed in the client's text input field as a draft. If there was another draft in the field before, it will be overwritten.

Button example:

{
    "type": "message",
    "label": "Compose a welcome message",
    "message": "Hello, colleagues!",
    "draft": false
}

Button "url"

The button opens a link. The protocols http://, https://, mailto:, and trueconf: are supported. If the button label is not set, the button displays the link value.

FieldTypeMandatoryDescription
typestringYesButton type — string "url"
idstringNoUnique button identifier, string. It can be used for additional identification of the pressed button.
меткаstringNoThe string that will be displayed on the button in the client, with a maximum length of 32 Unicode characters. If not provided, the name will be taken from the link.
stylestringNoButton display type: primary, danger, success
urlstringYesA link to the resource that needs to be opened. A string ranging from 8 to 8095 ASCII characters. Only the protocols http://, https://, mailto:, and trueconf: are supported.

The behavior of the button depends on the link protocol:

  • http:// and https:// — the link opens in an external browser, and the button has a visual "external link" marker;
  • mailto: — by default, an external email client opens, and the button has an "email" visual marker;
  • trueconf: — opens the TrueConf resource.
    • User's TrueConf ID in the format trueconf:user@server.name with an optional do parameter;
    • Conference ID in the format trueconf:\c\cid@server.name#vcs;
    • Any optional parameters are allowed, but the client will always forcibly append (or override, if they were passed) the following parameters: &templogin=1, &autoclose=0, &force=0.

If a button does not have a specified label, its value is displayed on the button. If the value is a user's TrueConf ID without parameters in the format user@server.name, the network status and the user's display name from the client's address book are shown. If there is no such TrueConf ID in the address book, the full TrueConf ID in the format john_doe@video.example.com is displayed instead of the display name.

Button example:

{
    "type": "url",
    "label": "Open website",
    "url": "https://trueconf.com",
    "style": "primary"
}

The "copy" button

The button copies the text generated by the bot to the clipboard. When pressed, a localized notification briefly appears in the client application indicating that the data has been copied to the clipboard. The button is visually marked with "copy".

FieldTypeMandatoryDescription
typestringYesButton type — string "copy"
idstringNoUnique button identifier, string. It can be used for additional identification of the pressed button.
меткаstringYesThe string that will be displayed on the button in the client, with a maximum length of 32 Unicode characters.
stylestringNoButton display type: primary, danger, success
datastringYesThe text to be placed in the clipboard. A string from 1 to 4095 Unicode characters.

Button example:

{
    "type": "copy",
    "label": "Copy promo code",
    "data": "PROMOCODE-12345",
    "style": "danger"
}

Button "command"

The button sends a command to the connected bot without posting a message in the chat. When the button is pressed, the connected bot receives a notification with the command method — see the "Notification on Press" section. If the button is set to waitReply: true, the bot must respond to the command using the answerCommand request.

FieldTypeMandatoryDescription
typestringYesButton type — string "command"
idstringNoUnique button identifier, string. It can be used for additional identification of the pressed button.
меткаstringYesThe string that will be displayed on the button in the client, with a maximum length of 32 Unicode characters.
stylestringNoButton display type: primary, danger, success
Ожидание ответаbooleanNoIs an additional response expected after the bot processes the command? If true, the notification of the button press will include a commandId, to which the bot should respond.
commandstringYesA command string for the bot, from 1 to 255 ASCII characters
customDatastringNoA string with additional information about the command, from 1 to 4096 ASCII characters. It can contain, for example, a JSON object.
tostringNoThe TrueConf ID of another bot to which this command should be redirected.

Button example:

{
    "type": "command",
    "id": "button_98",
    "label": "Add product to cart",
    "command": "add_to_cart",
    "waitReply": true,
    "customData": "eyBwcm9kdWN0SWQgOiAiMHIyZmozamY5ajM5MyIgfQ=="
}

Limitations

When using the buttons, consider the following limitations:

  • You can place up to 64 buttons under the message: no more than 8 rows with 8 buttons each.
  • Icons may be hidden depending on the number of buttons in a row. For example, in the TrueConf client application for Windows, macOS, and Linux, they are not displayed if the row contains more than 4 buttons.
  • The button text is displayed in a single line. If the text does not fit within the available area, part of it is truncated with an ellipsis.
  • The value of the label field must not exceed 32 Unicode characters. Any Unicode characters, including emojis, are allowed.
  • HTML and Markdown markup within the button text is not processed and is displayed as regular text.
  • Line break characters (\n) are replaced with spaces.
  • An incorrectly configured button will not be displayed.
  • Buttons can only be attached to messages of type 200 (PLAIN_MESSAGE). Only chat bots can send messages with buttons.
  • To modify the set of buttons, for example, when implementing navigation, edit the message using the editMessage method.

How to send buttons

Buttons are passed in the buttons field of the content object in the sendMessage request. Buttons are grouped into rows, with each row represented by a separate array of button objects:

buttons
├── [ ... ]  ← first row
│   ├── { ... } ← button
│   ├── { ... } ← button
│   └── { ... } ← button
└── [ ... ]  ← second row
    ├── { ... } ← button
    └── { ... } ← button

Rows and the buttons within them are displayed in the client application in the same order as specified in buttons. You can place up to 8 rows with 8 buttons each below the message, totaling up to 64 buttons (see limitations).

Request:

In this example, two rows of buttons are displayed below the message.

  • The first row contains three buttons: "Send command to bot 1!", "Add item to cart", and "Open website".
  • The second row contains two buttons: "Copy promo code" and "Write a greeting."
/docs/chatbot-connector/media/buttons_example_4/en.png

You can find an example of an Envelope object with buttons in the “Envelope Examples” section.

The response to the request is a standard sendMessage response.

In the event of an error, a message containing the errorCode parameter is returned. A list of possible values is available in the corresponding section of the documentation.

Click notification

When the user clicks a button of type command, a notification with the command method is sent to the connected bot:

Notification:

FieldTypeMandatoryDescription
methodstringYesMethod command
iduint32YesNotification ID
typeuint32YesMessage type (default is 1). Corresponds to MESSAGE_TYPE.REQUEST
commandIdstringNoUnique command identifier. Present if the button has the waitReply property set to true. Used to send a response to the command — see below
commandSourceobjectYesCommand source
commandSource.typestringYesSource type. The string "inlineKeyboard" indicates that the command came from a button in the message.
commandSource.messageobjectNoPresent if commandSource.type = "inlineKeyboard". Contains the message object (format Envelope) to which the pressed button was attached.
commandPayloadobjectYesThese commands
commandPayload.typestringYesCommand data type. The string "userCommand" indicates that the command was sent from a button of type command.
commandPayload.commandstringNoPresent if commandPayload.type = "userCommand". Contains the string from the command field of the button object.
commandPayload.customDatastringNoPresent if commandPayload.type = "userCommand". Contains a string from the customData field of the button object.

As with any other server notification, it requires a confirmation response (see the client response to the server request):

{
    "type": 2,
    "id": 123456
}

If the commandId field is missing in the incoming notification, the command does not expect an additional response.

Response to the command

If the command notification contains the commandId field, the bot must respond to the command. This is done by sending a request with the answerCommand method:

Request:

FieldTypeMandatoryDescription
methodstringYesMethod answerCommand
iduint32YesUnique request identifier
typeuint32YesMessage type (default is 1). Corresponds to MESSAGE_TYPE.REQUEST
commandIdstringYesUnique team identifier, matches the corresponding string from the incoming notification
answerTypestringYesType of command response. It can take one of the following values: complete, timeout, cancel, message.
сообщениеobjectNoAdditional message for the user
message.statusstringNoResponse status. It can take one of the following values: unknown, pending, running, ok, failed, canceled, timeout.
message.visibilitystringNoResponse display method. It can take one of the following values: default, toast, sticky, alert.
message.levelstringNoThe importance level of the response. It can take one of the following values: info, warning, error, critical.
сообщение.текстstringYesResponse text, length from 1 to 255 ASCII characters

Displaying the response as a modal window (visibility: "alert") requires support from the client application side.

Response to the request is a standard type 2 response.

In the event of an error, a message containing the errorCode parameter is returned. A list of possible values is available in the corresponding section of the documentation.