python - 如何在 slack api 的事件中触发 Modal?
问题描述
我想创建一个模式,当新用户加入频道时会立即弹出。我的想法是在新成员加入时使用@app.event 触发,然后以某种方式激活我的斜杠命令。但不幸的是 app.event 没有 trigger_id 所以我不能只在事件方法中创建模式。我也不喜欢使用斜杠命令,但我发现这一切都可以让用户使用复选框并提交已检查的模式响应。将两者联系起来的任何帮助都会很棒,或者其他建议将不胜感激。
@app.event("member_joined_channel")
def modal_event(event, say, body):
usr_id = event["user"],
user_id = usr_id[0]
channel_id = event["channel"]
pprint.pprint(body)
say(text=f"Welcome to the channel, <@{user_id}>! You can introduce yourself in this channel.")
app.client.chat_postMessage(
channel=channel_id,
)
@app.command("/cmd")
def modal(body):
pprint.pprint(body)
result = app.client.views_open(
trigger_id=body['trigger_id'],
view={
"title": {
"type": "plain_text",
"text": "My App",
"emoji": True
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": True
},
"type": "modal",
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": True
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n"
}
},
{
"type": "input",
"element": {
"type": "checkboxes",
"options": [
{
"text": {
"type": "plain_text",
"text": "Gary Danko",
"emoji": True
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "Chipotle",
"emoji": True
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "Slack Cafe",
"emoji": True
},
"value": "value-2"
}
]
},
"label": {
"type": "plain_text",
"text": "Please select all restaurants you'd be willing to eat at:",
"emoji": True
}
}
]
}
)
解决方案
不幸的是,您需要trigger_id
打开一个模态。我不知道没有它可以打开一个。您可以做的是监听[member_joined_channel][1]
事件,然后让您的应用程序在频道中向用户发送一条临时消息,提示他们单击一个按钮,然后该按钮将打开一个模式。
推荐阅读
- c# - WPF 滚动视图用户控件
- elasticsearch - 弹性搜索:查询字符串和数字并不总是返回想要的结果
- linux - 有没有办法在文本文件中合并相似(但不相同)的行?
- node.js - 如何访问从 xml nodejs api 转换的 json 中的数据
- json - VBA-JSON 在 API 调用中仅返回 32,767 个字符
- meteor - 升级后,为什么我的 Meteor 应用程序不再启动?
- python - Django-storages 将 FileField 和 ImageField 上传到 Dropbox
- php - 如何使用循环填充输入类型?
- activerecord - Simple_form 问题
- mysql - 如何在mysql中从倒数第二个逗号到最后一个逗号提取文本?