要求在松弛对话框中输入文本格式

require format for text input in slack dialog

我最近开始为我的 Slack 应用程序制作对话,并且想知道如何从用户那里获取具有所需格式样式的文本输入。我已经看到像 EventBot 这样的应用程序在您尝试创建一个新事件时会执行此操作,它会打开一个对话,并且文本输入行会要求您以特定格式输入日期和时间 MM/DD/YY HH:mm am/pm.如果您不遵循此格式,当您尝试提交对话时,文本框下方会出现一个红色的小警告。

我似乎找不到任何文档来说明当用户不遵循您的格式并且没有看到任何用于从用户那里获取日期的属性时如何抛出此警告。

有谁知道要调用什么方法或我需要包含什么属性来进行这种限制?

-谢谢

这有点不同。没有API可以调用。

相反,您的应用程序需要评估用户输入(在提交对话框后),然后可以在必要时向 Slack 响应错误消息。该错误消息随后会显示在对话框中。

这里是official documentation的相关部分:

If your app finds any errors with the submission, respond with an application/json payload describing the elements and error messages. The API returns these errors to the user in-app, allowing the user to make corrections and submit again.

下面是来自官方文档的响应示例:

{
  "errors": [
    {
      "name": "email_address",
      "error": "Sorry, this email domain is not authorized!"
    },
    {
      "name": "username",
      "error": "Uh-oh. This username has been taken!"
    }
  ]
}