Hangout bot how to @mention user in a card message

守給你的承諾、 提交于 2019-12-11 17:22:15

问题


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?


回答1:


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.




回答2:


You can combine simple messages with cards in a single posting to achieve this.

For example, the following JSON will display a message with @all in the text above the card. If you know the user id, you can change <users/all> to notify a specific user.

{
  "cards": [
    {
      "sections": [
        {
          "widgets": [
            {
              "keyValue": {
                "content": "<pre>ls -l</pre>",
                "contentMultiline": "true",
                "icon": "DESCRIPTION",
                "topLabel": "Executed Job"
              }
            },
            {
              "keyValue": {
                "content": "<pre><font color=\"#006400\">passed</font></pre>",
                "contentMultiline": "true",
                "icon": "BOOKMARK",
                "topLabel": "Status"
              }
            },
            {
              "keyValue": {
                "content": "<pre>5 milliseconds</pre>",
                "contentMultiline": "true",
                "icon": "CLOCK",
                "topLabel": "Elapsed"
              }
            }
          ]
        }
      ]
    }
  ],
  "text": "<users/all> : Job `ls -l` *passed*"
}


来源:https://stackoverflow.com/questions/55279348/hangout-bot-how-to-mention-user-in-a-card-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!