英文:
How do you save the Slack modal view ID for future updates?
问题
我正在使用Slack的模态对话框和他们新的BlockKit交互式操作。我有一个包含选择菜单附件的模态对话框的多个部分。当其中一个附件发生变化(例如,用户偏好从是->否),我想要更新模态对话框的视图,以反映一些上下文文本的变化。
文档概述了更新模态的两种方法。因为我没有使用传统的模态输入,所以我必须通过API而不是通过response_action
来更新模态。证据是:我甚至都没有收到view_submission
负载...我收到了blockkit_action
负载。
文档有一些冲突。在上面的链接中,他们说要更新视图,必须传入视图在打开时包含的成功响应中的ID:
记住你在之前使用views.open时包含的view.id吗?我们希望你留下它,因为现在你可以使用它来更新那个视图。
但是当你查看views.open和views.update的文档时,似乎还有第二种选择:external_id
。views.update
文档说:
开发者设置的视图的唯一标识符。对于团队上的所有视图必须是唯一的。最大长度为255个字符。要求提供view_id或external_id中的一个。
最初,我通过选择外部ID为myapp-mymodal-[userID]
来很好地使一切都正常工作。但是,一旦我尝试在我的桌面客户端和移动客户端同时打开模态,我开始收到internal_error
响应,并且无法再次打开模态了!
所以我开始研究保存视图ID,根据第一个引用。我的问题是:每次打开模态时,该ID都会更改。我不明白我如何可能跟踪可能在用户的桌面客户端和移动客户端(或者如果他们有iPad,第二台笔记本电脑等,则不止2个)之间进行的0-2个“活动”视图ID。
我试图寻找一些唯一的客户端ID,我可以将其包含在external_id
或我的view_id
持久性逻辑中,但鉴于Slack的API似乎是无状态的,我找不到任何这样的东西。
其他人是如何解决这个问题的?
英文:
I'm using Slack's modals + their new BlockKit interactive actions. I have a modal dialog with several section's that include select menu accessories. When one of those accessories changes (ex: user preference goes from Yes -> No), I want to update the modal's view to reflect the change in some contextual text.
The docs outline two ways to update a model. Because I'm not using the traditional modal inputs, I have to update the modal via the API and not via response_action
. Proof: I don't even receive a view_submission
payload at all... I receive a blockkit_action
payload.
The docs conflict a bit. In the above link they say that to update a view you must pass in the returned ID of the view when it was opened:
> Remember the view.id that was included in the success response when
> you used views.open earlier? We hope you kept it, because you can now
> use it to update that view.
But when you look at the docs for the views.open and views.update, it appears there is a second option: external_id
. The views.update
docs say this:
> A unique identifier of the view set by the developer. Must be unique
> for all views on a team. Max length of 255 characters. Either view_id
> or external_id is required.
Initially I got everything working really nicely by choosing an external ID of myapp-mymodal-[userID]
. But as soon as I tried opening the modal simultaneously on my Desktop + Mobile client, I started getting internal_error
responses and have been unable to open the modal since!
So I started looking into saving the view ID, per the first quote. My problem is: that ID changes every time the modal opens. I don't understand how I am expected to possibly keep track of the 0-2 "active" view IDs that might be taking place across a user's Desktop + Mobile clients (or more than 2 if they have an iPad, a second laptop, etc).
I tried to look for some sort of unique client ID that I could either use to include in the external_id
or in my view_id
persistence logic, but given that Slack's API appears to be sesssion-less I couldn't find any such thing.
How do others solve this problem?
答案1
得分: 4
尝试在视图中使用private_metadata字段
最初我也做了与你相同的事情,它起作用了,但我想尽量避免边缘情况。我发现,我可以将我在打开视图时创建的external_id传递到视图的元数据中,然后在接收交互时检索它。
当我设置external_id时,我将其设置为userID +当前时间(这样即使用户从不同设备打开模态也始终是唯一的)
externalID := UserID + time.Now().String()
然后将其同时用作视图的external_id以及作为一个字符串传递到private_metadata中
PrivateMetadata string `json:"private_metadata"`
当用户与我的某个块进行交互并且Slack向我发送交互消息时,我像这样检索元数据
Request.Payload.View.PrivateMetadata
我用Go编写了我的Slack应用,但我尽量使它对任何语言都清晰。如果有任何不清楚或需要进一步解释的地方,请告诉我 - 这是我第一次回馈Stackoverflow社区。
英文:
Try using the private_metadata field in the View
I initially did the same thing you did, which worked, but I wanted to avoid that edge case if possible. What I figured out, is that I could pass the external_id that I created when opening the view into the view's metadata, and then retrieve it when I receive an interaction.
When I set the external_id I set it to the userID + the current time (so it's always unique, even if the user opens the modal from different devices)
externalID := UserID + time.Now().String()
and pass that both as the external_id for the view, and as a string into the private_metadata.
PrivateMetadata string `json:"private_metadata"`
When the user interacts with one of my blocks and Slack sends me the interactive message, I retrieve the metadata like this:
Request.Payload.View.PrivateMetadata
I wrote my Slack app in Go, but I tried to make it clear for any language. Let me know if anything is unclear or needs expanding on - this is my first time giving back to the Stackoverflow community.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论