Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid channel when targeting a user #40

Open
natcl opened this issue Nov 12, 2020 · 12 comments
Open

Invalid channel when targeting a user #40

natcl opened this issue Nov 12, 2020 · 12 comments

Comments

@natcl
Copy link

natcl commented Nov 12, 2020

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 !

@travisghansen
Copy link
Owner

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?

@natcl
Copy link
Author

natcl commented Nov 12, 2020

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 !

@travisghansen
Copy link
Owner

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.

@natcl
Copy link
Author

natcl commented Nov 12, 2020

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.

@travisghansen
Copy link
Owner

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 :)

@natcl
Copy link
Author

natcl commented Nov 12, 2020

Thanks, I just tested and it seems your therory is good, it happens with users that never interacted with the bot.

@travisghansen
Copy link
Owner

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?

@natcl
Copy link
Author

natcl commented Nov 12, 2020

Yes thanks, will try that !

@natcl
Copy link
Author

natcl commented Nov 12, 2020

just to make sure that I'm on the good path, I would use chat.postMessage ?

@travisghansen
Copy link
Owner

Yes, use chat.postMessage.

@natcl
Copy link
Author

natcl commented Nov 12, 2020

Seems to work ! Thanks a lot ! Closing this.

@natcl natcl closed this as completed Nov 12, 2020
@travisghansen
Copy link
Owner

Going to reopen as the logic in the web out node is too strict.

@travisghansen travisghansen reopened this Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants