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

Posting a message to user's DM results in channel_not_found #212

Open
tahasi opened this issue Oct 8, 2024 · 1 comment
Open

Posting a message to user's DM results in channel_not_found #212

tahasi opened this issue Oct 8, 2024 · 1 comment

Comments

@tahasi
Copy link

tahasi commented Oct 8, 2024

My bot is responding to a slash command by posting a message back to the channel the SlashCommand parameter specifies. The posted message's channel is set to the SlashCommand parameter's ChannelId.

When the slash command is ran from my App Message tab, the message is successfully posted to the App Message tab. However, when the slash command is ran from the user's DM, the the post message API is erroring with the message "channel_not_found".

The chat.postMessage documentation indicates that I should be able to post a message to a user's DM.

If the channel parameter is set to a User ID (beginning with U), the message will appear in that user's direct message channel with Slackbot. To post a message to that user's direct message channel with the app, use the DM ID (beginning with D) instead.

I assumed that the user's DM ID would be the SlashCommand.ChannelId field, when the slash command is ran from the user's DM. Unfortunately, using that SlashCommand.ChannelId is resulting in the "channel_not_found" error.

I hoped that it was just a permission issue and reinstalled the app with the im:write permission. But that didn't fix the issue.

I'm sure that the error is due to my modest knowledge of Slack APIs. Unfortunately, I've not yet found how to structure the post message call to have it go to the user's DM.

How may I post a message to a user's DM.

@soxtoby
Copy link
Owner

soxtoby commented Oct 12, 2024

Hi, @tahasi. If you want to respond to the slash command in the same channel it came from, the simplest thing to do is have the handler return a SlashCommandResponse with the message. If you need to post the message after the handler returns, then you can use the ISlackApiClient.Respond() extension method, which takes in the SlashCommand and a SlashCommandResponse.

Hope this helps.

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