Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

Can i send custom properties/data in slack message attachments?

I want to send some custom properties in the attachment for interactive messages and retrieve them back in the action response. is there a way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, that is possible. However, it only works well for small sets of data.

Assuming we are talking about buttons the normal approach would be to use the value field of an action to transfer custom data based on which button the user clicked back to your app. The field is a normal string within a JSON message, which is send by POST request to your app. So it can in principle contain a whole data set, not only a single value. All you need to do is include it in the button attachment that is send to Slack and your app will receive the respective value field back. (depending on what data you want to send you might need to encode it, e.g. you want to encode binary data into base64, so that is can be transferred as JSON string)

I have used it successfully in one of my apps to transfer serialized objects containing information about the user's application context.

There is one caveat though, that caused me to later abandon this approach again. As I found out the field length is limited, so if your string is too long you might end up with truncated data. In my estimation the limit is about 2.000 chars, but I do not have a definitive number.

Instead of transferring all data in the attachment, I now keep the user application context in a server session (PHP) and only transfer IDs through the value field of my buttons.

Conclusion: If you have small sets of data you can transfer them through the value field. If you have larger sets of data I would not recommend it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...