在 Microsoft Teams 中添加机器人菜单

重要

本文基于 v3 Bot Framework SDK。 如果要查找 SDK 的当前文档 4.6 或更高版本,请参阅 对话机器人 部分。

为了帮助发现并帮助让用户了解机器人的功能,现在可以添加每当用户与机器人交互时出现的菜单。 菜单将显示命令文本,并提供帮助文本,例如使用示例或命令用途说明。

机器人菜单的屏幕截图

当用户选择菜单项时,命令字符串将插入到文本框中,以帮助用户完成机器人消息。

Teams 移动应用上的机器人菜单支持

注意

移动设备上不显示机器人菜单。

应用部件清单

若要创建机器人菜单,请在机器人部分下将新 commandLists 对象添加到应用清单。 对于机器人支持的每个范围,可以使用单独的命令声明单个菜单, personal (、 groupChatteam) 每个菜单最多支持 10 个命令。

清单摘录 - 这两个范围的单个菜单

{
  ⋮
  "bots":[
    {
      "botId":"[Microsoft App ID for your bot]",
      "scopes": [
        "personal",
        "team"
      ],
      "commandLists":[
        {
          "scopes":[
            "team",
            "personal"
          ],
          "commands":[
            {
              "title":"Help",
              "description":"Displays this help message"
            },
            {
              "title":"Search Flights",
              "description":"Search flights from Seattle to Phoenix May 2-5 departing after 3pm"
            },
            {
              "title":"Search Hotels",
              "description":"Search hotels in Portland tonight"
            },
            {
              "title":"Best Time to Fly",
              "description":"Best time to fly to London for a 5 day trip this summer"
            }
          ]
        }
      ]
    }
  ],
  ...
}

清单摘录 - 每个作用域的单独菜单

{
  ...
  "bots":[
    {
      "botId":"[Microsoft app ID for your bot]",
      "scopes": [
        "groupChat",
        "team"
      ],
      "commandLists":[
        {
          "scopes":[
            "team"
          ],
          "commands":[
            {
            "title":"help",
            "description":"Displays this help message for channels"
            }
          ]
        },
        {
          "scopes":[
            "groupChat"
          ],
          "commands":[
            {
            "title":"help",
            "description":"Displays this help message for group chat"
            }
          ]
        }
      ]
    }
  ],
  ...
}

最佳做法

  • 保持简单:机器人菜单旨在呈现机器人的关键功能。
  • 保持简短:菜单选项不应是极其长且复杂的自然语言语句 - 它们应该是简单的命令。
  • 始终可用:无论机器人处于何种对话状态或对话状态,机器人菜单操作/命令都应始终可调用。