如何在Slack对话框表单中添加文件上传字段?
在Slack对话框中添加文件上传区域的方法
嘿,刚好我对Slack对话框的配置很熟悉,你只需要在elements数组里添加一个**file类型**的字段,就能让用户看到文件上传区域啦!
你注释的位置(也就是现有两个元素的后面)就是最合适的添加点,直接插入下面这个对象就行:
{ label: 'Upload File', // 显示给用户的上传提示文字 type: 'file', // 必须设为file才能触发文件上传控件 name: 'uploaded_file', // 提交后用来识别这个文件字段的键名 optional: false // 设为false的话用户必须上传文件才能提交 }
修改后的完整dialogData代码如下,我把新增的部分标出来了:
const dialogData = { token: authToken, trigger_id: slackReqObj.trigger_id, response_url: slackReqObj.response_url, dialog: JSON.stringify({ title: 'Upload a file with comments', callback_id: 'submit-upload', submit_label: 'Submit', elements: [ { label: 'Description', type: 'textarea', name: 'description', optional: false }, { label: 'Title', type: 'text', name: 'title', value: 'title ...', hint: 'Name of the file or title ...' }, // 新增的文件上传字段 { label: 'Upload File', type: 'file', name: 'uploaded_file', optional: false } ] }) };
小提示:
- Slack对话框里的
file字段目前只支持单个文件上传,用户没法一次传多个 - 当用户提交表单后,你会在Slack的回调请求里拿到这个文件的
file_id等信息,后续可以用Slack API获取文件详情或者进行其他操作
内容的提问来源于stack exchange,提问作者Rep
相关产品推荐
相关产品推荐

