Open natcl opened 4 years ago
Behind the scenes we keep a list of all channels etc (slack-state
node(s)) so when you use that syntax what happens is the app does a lookup from the slack state data and then replaces the channel with the real channel id. If the slack state hasn’t loaded yet (the startup situation) or is behind (new users getting created etc) then it may not be able to do the lookup. Or the channel may simply not exist.
At deploy doesn’t bother me and makes sense... after things have loaded (an event gets fired from the second output on the slack-state
node where you can detect this in your flows) does bother me. Do you have many users/channels? Is the issue (after startup) generally happening for users who have just been created? Or don’t yet have a dm channel with the bot?
Hello, yes we have many users (400+) and a lot of channels too (200+) These are not new users, they've been there several years. These users never interacted with the bot however. Le me know if I can provide more info and thanks for the followup !
Yeah, my guess is the fact the bot and user have never conversed means there is no channel created. I would be hesitant to add channel creation logic to the node to handle these scenarios but am open to suggestions for sure. It's been a while since I reviewed the api as well so maybe they have a way to just send the username and the channel gets created on the fly.
Thanks, would there be alternatives ? I'll try with other users that I know have never conversed with the bot to see if it does it for them.
You could inject a node in between that would use the slack-state
data before and do the lookup yourself. If the lookup fails then you could create the conversation using the http api nodes and get the response from the http call and use the more explicit syntax.
But I may have some bad logic as well. I'd have to research the api again to see if it allows for pure @username
syntax or if we must send the action channel id...it's been quite a while since I coded it all up :)
Thanks, I just tested and it seems your therory is good, it happens with users that never interacted with the bot.
Yeah, and the spec seems to indicate the rtm api does not allow sending the username directly: https://api.slack.com/events/message
However, https://api.slack.com/methods/chat.postMessage#channels indicates that it accepts id or #
or @
style syntax.
Unless you really need to use rtm for messages I would consider using the slack-web-out
node + a function node (so you don't have to rewrite all your flows) instead of the slack-rtm-out
node. In the function just 'translate' what you currently send to the rtm node to the proper syntax for the slack-web-out
node.
Make sense?
Yes thanks, will try that !
just to make sure that I'm on the good path, I would use chat.postMessage ?
Yes, use chat.postMessage
.
Seems to work ! Thanks a lot ! Closing this.
Going to reopen as the logic in the web out node is too strict.
I often get a
"invalid channel: @username"
message when targeting a user using the @username syntax in msg.topic. I noticed it often happens shortly after a deploy but seems to happen randomly too. What could be causing this ? Thanks !