I'm setting up a Slack App to post messages via the Web API and using a bot OAuth token from an ASP.NET web app, and one of the requirements is for the Slack app to be able to return a relevant value for when a user has last read their messages in their DM with the Slack bot. This is to track which messages require updating or reposting.
At first I figured you can send a request with the conversations.info method to get the "last_read" property from the JSON response. And if I was using the user OAuth token (with "xoxp-...") in the request for any direct message opened by the user associated with the token, I would get a value such as "1571423219851.000000" milliseconds.
But when I would use the bot token (using "xoxb-...") to check a DM to a user, it would have for the "last_read" field in zeros.
The steps to reproduce the issue is:
"ok": true,
"no_op": true,
"already_open": true,
"channel": {
"id": "DP4NRGLNE"
}
Send a message to propogate the message window using the DM id. https://api.slack.com/methods/chat.postMessage/test
Test with the conversations.info method using the bot token and DM id. https://api.slack.com/methods/conversations.info/test
However, when I run the method, I would get a response like this.
"ok": true,
"channel": {
"id": "DP4NRGLNE",
"created": 1571404761,
"is_archived": false,
"is_im": true,
"is_org_shared": false,
"user": "UN4F12QH7",
"last_read": "0000000000.000000",
"latest": {
...
},
"unread_count": 3,
"unread_count_display": 3,
"is_open": true,
"priority": 0
}
Expected: The "last_read" field is set to some value, i.e. "1571404761.000000", with unread_count set to 0.
Actual: The "last_read" field is still set to "0000000000.000000" (and unread_count not resetting to 0), despite having message history in the direct message, and having acknowledged "Mark read" for new messages/ physically opened the chat log and scrolled down over the new messages.
The suspicion is that using the user OAuth token will return a relevant last_read value because a user themselves will set a last_read timestamp in a given conversation while a Slack bot doesn't ever set the "last_read" field for a conversation they are part of (i.e. a user doesn't need to know when the bot itself last read the chat?). Though if it that was the case, then why is using a bot token unable to see a set value for the last_read field for a user in their DM? That's sort of where this question comes from (and the confusion).
This is probably an incorrect theory, but Slack documentation doesn't seem to address this concern, so any suggestions would be welcome.
EDIT: After looking closer at the documentation, it would appear that the child family of methods im doesn't have a concept of im.info, hence the default value of 0 is set for a dm.
As the documentation states about the last_read
attribute for channel types:
last_read
is the timestamp for the last message the calling user has read in this channel
If you use the bot token to call conversations.history
then the calling user is the bot user, which apparently has not read any of the messages yet.
So this is not a bug, but works as intended.