Slack API - 创建一个按钮,returns 来自变量的文本
Slack API - Create a button that returns text from a variable
我正在通过 Python 创建一个 Post.message 到 Slack,并想添加一个按钮功能。我希望按钮提供由 low2 = low["serials"]
表示的序列号列表。这是我目前拥有的代码,它将按钮添加到松弛消息中,但是当我单击该按钮时,我收到一条错误消息,显示来自 slackbot 的 "Oh no, something went wrong. Please try that again."。我看到帖子说大多数人必须创建一个机器人来解决他们的按钮问题,但如果按钮只需要读取这个变量,我认为有办法解决这个问题。感谢您的帮助!
"fields": [
{
"title": "Amount Used:",
"value": low1,
"short": 'true'
},{
"title": "Distinct Device ID's:",
"value": out1,
"short": 'true'
},
{
"title": "Total Connection Time (hr):",
"value": data2,
"short": 'true'
}
],
"actions": [
{
"name": "game",
"text": "Serials",
"type": "button",
"value": "serials",
}
],
我通过将确认操作按钮转换为显示我想要的值解决了我的问题。
with open('Count_BB_Serial_weekly.json', 'r') as lowfile:
low = json.load(lowfile)
low1 = low["total_serials"]
low2 = low["serials"]
low3 = '\r\n'.join(low2)
以上是我导入数组并读取值的脚本。下面我把结果放到了"confirm"弹出按钮里。
],
"actions": [
{
"name": "game",
"text": "Serials",
"type": "button",
"value": "serials",
"confirm": {
"title": "Serial Numbers",
"text": low3,
"ok_text": "Yes",
"dismiss_text": "No"
}
}],
不,没有办法解决。您必须在交互式消息上创建 Slack App (or "Internal Integration") in order to use buttons in your app. One reason is that you need to tell Slack what URL to call if someone clicks a button (your "Action URL") and that can only by configured as part of a Slack app. Check out this documentation 以获取详细信息。
关于你的方法。一个按钮只会向用户显示一个值。如果您的目标是让用户从序列号列表中进行选择,我认为您有两种选择:
a) 创建一组按钮,每个序列号一个
b) 使用 interactive menu 为您的列表创建下拉菜单
我正在通过 Python 创建一个 Post.message 到 Slack,并想添加一个按钮功能。我希望按钮提供由 low2 = low["serials"]
表示的序列号列表。这是我目前拥有的代码,它将按钮添加到松弛消息中,但是当我单击该按钮时,我收到一条错误消息,显示来自 slackbot 的 "Oh no, something went wrong. Please try that again."。我看到帖子说大多数人必须创建一个机器人来解决他们的按钮问题,但如果按钮只需要读取这个变量,我认为有办法解决这个问题。感谢您的帮助!
"fields": [
{
"title": "Amount Used:",
"value": low1,
"short": 'true'
},{
"title": "Distinct Device ID's:",
"value": out1,
"short": 'true'
},
{
"title": "Total Connection Time (hr):",
"value": data2,
"short": 'true'
}
],
"actions": [
{
"name": "game",
"text": "Serials",
"type": "button",
"value": "serials",
}
],
我通过将确认操作按钮转换为显示我想要的值解决了我的问题。
with open('Count_BB_Serial_weekly.json', 'r') as lowfile:
low = json.load(lowfile)
low1 = low["total_serials"]
low2 = low["serials"]
low3 = '\r\n'.join(low2)
以上是我导入数组并读取值的脚本。下面我把结果放到了"confirm"弹出按钮里。
],
"actions": [
{
"name": "game",
"text": "Serials",
"type": "button",
"value": "serials",
"confirm": {
"title": "Serial Numbers",
"text": low3,
"ok_text": "Yes",
"dismiss_text": "No"
}
}],
不,没有办法解决。您必须在交互式消息上创建 Slack App (or "Internal Integration") in order to use buttons in your app. One reason is that you need to tell Slack what URL to call if someone clicks a button (your "Action URL") and that can only by configured as part of a Slack app. Check out this documentation 以获取详细信息。
关于你的方法。一个按钮只会向用户显示一个值。如果您的目标是让用户从序列号列表中进行选择,我认为您有两种选择:
a) 创建一组按钮,每个序列号一个
b) 使用 interactive menu 为您的列表创建下拉菜单