mrb0nj / Slack.Webhooks

Even simpler integration with Slack's Incoming and Outgoing webhooks
MIT License
173 stars 53 forks source link

Get `ts` of posted message, so it is possible to reply to it #91

Open bence-nagy opened 3 years ago

bence-nagy commented 3 years ago

Consider the following use case: A bot wants to post subsequent messages into a single thread within a slack channel. So the first message would be a normal message, further messages would be thread replies to that message.

For this to work - as far as I can tell - you would need to get the identifier (which seems to be the ts property) of the first posted message. The slack API returns this information (see the documentation) in the form of "ts": "1503435956.000247".

If I had the value of that property then I could construct message objects with theirThreadId property set to the value returned by the first posted message, but this wrapper does not seems to expose that returned property.

The Post methods only seem to return with a bool (or a Task<bool>) and it seems that they do not modify the passed SlackMessage object, so the returned ts value is simply discarded. Is it so or am I missing something?

Would it be possible to somehow expose the ts property of a message once posted? Either via returning it from the Post methods or maybe storing it in the message object passed to the methods - so mutating the passed argument?

Or is there any workaround I can use? (Apart from using the slack API directly - which is of course a solution to my problem.)

Thanks in advance.

mrb0nj commented 3 years ago

Hey, you can get if you copy the link to the message and extract the ID from the end of the URL. example:

https://[yourdomain].slack.com/archives/C6JPLL60L/p1582740873000100 ------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^

becomes: 1582740873.000100

hope that helps.

mrb0nj commented 3 years ago

Sorry, I only really addressed part of your question here...

chat.postMessage that you've linked to is not the API method that is being called as part of SlackClient.Post.

Posting to the webhook URL, sadly, does not return the ThreadId in the same way.

I started some time ago implementing the API https://github.com/mrb0nj/Slack.Webhooks/blob/feature/api/src/Slack.Webhooks/Chat/ChatClient.cs but this branch is massively different to the current implementation of this library.

bence-nagy commented 3 years ago

Thanks for the replies and for clarifying that the webhook's post uses a different API method, now I get why this property is not returned.

Do you have a rough estimation about when the mentioned branch will be ready? Or is already in a state that I could try it out? Do you plan to create a (beta) nuget package from it?

Either way, thanks for the great package 👍

danilobassi8 commented 1 year ago

Any updates?

givanytska commented 1 year ago

we need this too!

gergokee commented 1 year ago

we also need this functionality