Search code examples
google-apps-scriptgoogle-hangoutsgoogle-chat

Hangout bot how to @mention user in a card message


I've created a bot that is supposed to inform users from a group about the tasks they were assigned to. It is working well with the simple message using but it's not working once put in a card message - I got "---" or "???" instead of mention. I tried to put it in different widgets: keyValue, textParagrap or header but it doesn't change anything. Does anyone know if it's possible at all?


Solution

  • A review of the API description should have confirmed your suspicions - at this moment, you cannot mention a user via a Card message, only a simple message.

    Per Card Text Formatting:

    Inside cards, most text fields support basic text formatting via a small subset of HTML tags.

    and

    Note that the text body of a basic message is parsed using a different markup syntax

    The API Reference page on message formats for simple messages explicitly identifies how one mentions users in simple messages (1, 2)

    Another hint comes when viewing the API descriptions of spaces.messages and cards: the metadata associated with a Message includes Annotations which include UserMentionMetadata.
    If viewing the specification for a Card, no such specification is observed. The description of a text widget contains only the formatted text.

    Thus, if you need to notify a particular user about the content of a card, you should either DM the card to the user, or mention the user in a simple message immediately before or after the card is sent.