Inumedia / SlackAPI

.NET Implementation of the Slack team communication platform API.
MIT License
452 stars 243 forks source link

On receiving a new direct message, the SlackSocketClient DirectMessages list does not contain the id. #111

Open Slagh opened 7 years ago

Slagh commented 7 years ago

When my OnMessageReceived callback is triggered, by a direct message from a user my bot has not previously received a message from, I try to categorize the message as a direct message by finding the received message 'channel' field in the SlackSocketClient.DirectMessages list objects by matching 'id', which is not found.

Under conditions I'm not entirely clear about, but generally, if I reconnect my bot and receive another direct message from the same user, I will find a match for that message's channel field in the DirectMessages list by 'id'.

jamalmach commented 7 years ago

I can confirm the above problem, i'm having a similar issue (also a bot user).

When calling GetDirectMessageHistory from within OnMessageReceived the history array that's passed to the callback does not contain the most recent message in that direct message channel.

I'm needing to determine if the message is a direct message, AND (in another method) re-read a message that was previously sent to my bot

jamalmach commented 7 years ago

@Slagh

I just found that by calling GetDirectMessageList (even with a blank or nonsense callback method) before GetDirectMessageHistory , my most recent message to the bot now shows up as expected in the array of messages.

slackClient.GetDirectMessageList((callback) => { var stuff = callback; }); slackClient.GetDirectMessageHistory(callback: [CALLBACK_FUNCTION], conversationInfo: dmConversation, latest: null, oldest: null, count: 3);

Hope that makes sense.....

### EDIT: This actually still isn't 100%. I'm now having to do extensive Exception handling because this API isn't functioning as expected.

jamalmach commented 7 years ago

@Slagh This was some convo i had with a Slack Support Rep because @Inumedia hasn't given any help.

Me When my MessageReceived event fired, I used the API to checkout the list of DirectMessages to see if the current message came from an open channel, or a directMessage channel. This turned out to be quite unreliable as the DirectMessageList somehow wasn't always updating when a message was received from a user for the first time. I switched my code to check if the channel begins with D instead, which has so far been true for all DirectMessage channels. Am I safe to keep using this assumption? Messages from other channels had their channel ID's beginning with a C

James 11 sec ago Hi there, that is indeed a safe assumption. Public channels start with C Private channels (or groups) and multiparty DMs start with G Direct message channels start with D I hope that helps! James

This still doesn't solve the original problem of it not containing the current conversation though.