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

sendMessage API returns 'invalid channel id' with Docs examples #300

Closed
3 tasks done
mmmulani opened this issue Dec 13, 2016 · 10 comments
Closed
3 tasks done

sendMessage API returns 'invalid channel id' with Docs examples #300

mmmulani opened this issue Dec 13, 2016 · 10 comments
Labels
docs M-T: Documentation work only needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info

Comments

@mmmulani
Copy link

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Description

When calling rtm.sendMessage('test', ...) with a username like @test, or userid provided from message.user (like U3B4XADP9) it does not work. Instead a SlackRTMError is returned with 'invalid channel id'.

The only way I've found to DM a user or send a message to a chat is to hardcode the channel found from message.channel (like G3BBUJ7HE).

The docs make it sound like this should work: https://slackapi.github.io/node-slack-sdk/bots#posting-a-message

However the docs here: https://api.slack.com/methods/chat.postMessage discuss Channels and explain some of these issues.

So what's broken? Is it the API, or are the docs inconsistent?

@UncannyBingo
Copy link

A fair question, thank you for raising it! At the lowest level, the RTM API only allows you to specify a channel/group/DM id. You cannot use a channel name, a user name, or a user id. This is clearly a problem with the documentation for this project.

Please note that chat.postMessage is a different API from the RTM API—and it is much more permissive about what it will accept.

@UncannyBingo UncannyBingo added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented docs M-T: Documentation work only Priority—Medium labels Dec 13, 2016
@UncannyBingo UncannyBingo self-assigned this Dec 13, 2016
@mmmulani
Copy link
Author

ahh cool, docs problem then.

how do you go about messaging a private user then? is there a way to DM them without having to check if you already have a conversation with them?

@UncannyBingo
Copy link

You need to know the DM id. Each DM conversation has a DM id that is separate from the participants' user ids. To participate in a DM using the RTM API, you'll need to start a DM using the im.open web API endpoint, and then cache the resulting DM id for future use.

@jwulf
Copy link

jwulf commented Jan 6, 2017

The docs are broken.

Put this in the README.md example:

let channel;

rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED,  (rtmStartData) => {
  for (const c of rtmStartData.channels) {
	  if (c.is_member && c.name ==='general') { channel = c.id }
  }
  console.log(`Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}, but not yet connected to a channel`);
});

Then the example will work with a copy and paste.

@saifalfalah
Copy link

So if I understand this correctly, in order to send a DM to a user, I need to use the im.open web API endpoint. But a custom bot user (internal integration) which does not have the authorization token required to use the web API endpoint, how does it send a DM? Or in order to send a DM, I have to attach the bot user to a Slack app and do the OAuth dance? Or is xoxb- token enough for using the web API?

@saifalfalah
Copy link

So, I got around this issue by using the Web API im.open to get the DM ID and then use the RTM API to send a DM to a user. Apparently, it's possible to use the Web API with a custom bot user's auth token.

CharlieHess added a commit to CharlieHess/node-slack-sdk that referenced this issue May 17, 2017
@aoberoi
Copy link
Contributor

aoberoi commented May 17, 2017

closed in #347

@aoberoi aoberoi closed this as completed May 17, 2017
@Robert-Ernst
Copy link

I want to reopen this case.
I've spent days to find this information.
It's still not clear how limited the RTM API is from the regular documentation.

@aoberoi aoberoi reopened this May 27, 2018
@aoberoi
Copy link
Contributor

aoberoi commented May 27, 2018

@BerndErnst thanks for the feedback. Your experience is valuable, since as maintainers it’s harder for us to unlearn ideas to document them in the best way.

Which information did this issue have that you thought should have been more clear in the documentation? Any suggestions on changes?

@aoberoi aoberoi removed the bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented label May 27, 2018
@aoberoi aoberoi added the needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info label Jun 4, 2018
@aoberoi
Copy link
Contributor

aoberoi commented Aug 28, 2020

It's been a little while here. I hope that you've gotten past any issues you were having. Closing now, but feel free to open a new issue if there's still a problem we can solve.

@aoberoi aoberoi closed this as completed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs M-T: Documentation work only needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info
Projects
None yet
Development

No branches or pull requests

6 participants