question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sendMessage API returns 'invalid channel id' with Docs examples

See original GitHub issue
  • 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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
jwulfcommented, 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.

1reaction
DEGoodmanWilsoncommented, Dec 13, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chat.postMessage method - Slack API
This method posts a message to a public channel, private channel, or direct message/IM channel. Consider reviewing our message guidelines, especially if ...
Read more >
Build app server send requests | Firebase Cloud Messaging
For Firebase Admin SDKs, this operation uses the sendAll() API under the hood, as shown in the examples. The return value is a...
Read more >
Error and Warning Dictionary | Twilio
Explore the full list of all possible Twilio REST API error codes. ... Alpha Sender ID is Invalid or Not Authorized for this...
Read more >
SendMessage - Amazon Simple Queue Service
Amazon SQS continues to keep track of the message deduplication ID even ... The following example SendMessage request sends a message containing This...
Read more >
API Reference - Discord.py
The following section outlines the API of discord.py. Note. This module uses the Python logging ... Returns a partial messageable with the given...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found