[SOLVED] Incoming Webhook cannot send result to user

Summary

In the payload of an incoming webhook, specifying a user results in error 500 “Couldn’t find the channel”

Steps to reproduce

  1. Create incoming webhook
  2. Open Firefox (or web browser with capability to POST and pass parameters)
  3. Use the URL of the webhook and post the suggested example in the documentation (Make sure to put application/json in the content type of the header):
    {"text": "Hello, this is some text."}
  4. Message should appear in the channel
  5. Try again, but now add the channel property
    {"channel":"@username","text": "Hello, this is some text."}
  6. Enter a valid user name in @username (leave the @ sign).
  7. Post will now fail with a 500 error and message “Couldn’t find the channel”
  8. Changing channel property to a public channel works. Only with @username is not working.

Expected behavior

As per documentation, “the message will be sent to that user’s direct message channel”

Observed behavior

Returned JSON:
{"id":"web.incoming_webhook.channel.app_error","message":"Couldn't find the channel","detailed_error":"","request_id":"8aajaxpkybn8mmm7t4nkefnrca","status_code":500}

Also, misspelling the username or putting an invalid username results in “Couldn’t find the user”. So maybe the problem is that there’s no “channel” message for the user (as in Slack, the user can have private messages with themselves)

Hi @ngcnelson,

Is this issue only when trying to send a post to a Direct Message channel with the user creating the webhook?

We currently don’t have a Direct Message channel for users to message themselves, so that would cause the channel not found error.

There’s a feature request for that channel here: https://mattermost.uservoice.com/forums/306457-general/suggestions/15697014-add-option-to-direct-message-yourself

And if anyone is interested in adding that feature, please feel free to join our daily builds server to discuss.

Hi
Yes. If it’s a slash command, and I use ephemeral then the user gets the message in whatever channel they’re in. But a incoming webhook cannot direct a message to specific user. Directing it to a channel works like a charm. I would suggest that the documentation gets updated, because it looks like it’s possible to send the message to a user.

The reason why I discovered this is because I’m creating a “reminder” bot (similar to the one in Slack). But because the post cannot be directed to a user, I can only create reminders for the channel.

I wanted to get involved in the development (I think Mattermost is an amazing app) but I don’t know how to program in Go. Maybe if I have some time I’ll study it. Mostly I wanted to get involved because I see that some features (of the same JSON payload) work under some features and not under another (like attachments do not work in slash commands but work in incoming webhooks). I wanted to consolidate the processing and posting of a JSON payload so that any feature that gets added/supported works in all places that it is used.

OK so for now, this is not possible (from a webhook to send the message to specific user)
Thanks

1 Like

@ngcnelson - just to clarify, it should be possible for an incoming webhook to send to most users, just not the user who created the webhook.

I just tested and it was working for me for most users, with the one exception of sending a message to myself (since I created the webhook).

Pull request here to clarify the documentation: https://github.com/mattermost/docs/pull/572

Ahhh…OK I see.
I was testing it with myself. That’s why it was not working.
Alright, I’ll give it a try with a different user and see what happens.
Thanks!

Tested it. What you state is correct: Message can be send to any user, except the creator of the webhook

One last thing: It can only post to the channel of other users only if there’s a channel for private messages between the target user and the creator of the webhook.
If those users have never talked privately before, the channel doesn’t exists and we get the same error 500.

Ah interesting, thanks for letting us know! I created a ticket here to track that issue: https://mattermost.atlassian.net/browse/PLT-4354

Do I understand it correctly that an incomming webhook can only devliver messages to private messages the creator of the webhook is part of? So it cannot post to any private message scenario as another user?
Can it post to a private channel, the creator is not part of?

To clarify, I’m using a slash command (so everyone can trigger it everywhere) and then try to get the response back via an incomming web hook (because slash commands dont support attachments).

In version 3.4 that was the case. To overcome that part, in my implementation the slash commands posts a link to my web interface that has the files (I was also dealing with attachments among other things)

It seems like version 3.6 might support attachments or some form of it now. I noticed that a slash command we had from our time with Slack is now bringing the extra data that we sent as attachments, which was not doing before.

I cannot confirm that.
I’m using 3.6 and I cannot send an over an incomming webhook to private message channels. Only to those where the creator of the webhook is part of.
Everything else gives me an
code=500 … Inappropriate channel permissions [details: ]

Yes, that is still an issue. I was referring to the original reason why you did this, which is, the lack of attachments. That seems to be available now.

You mean attachments do work now for slash commands? I don’t think so… but I’ll try. That would completely solve my problem, I guess…

This is a slash command in our organization that provides the license code for customers. We created it while using Slack. When we moved to Mattermost the “Customer Code” and “Customer Name” were not coming. We were OK because we just needed the code.
Now, in 3.6 they’re coming in nicely like it did in Slack

Correct. attachments work with slash commands with 3.6.2 ! Hallelujah! :smiley:

I’m having the same issues with a slash command only working where the creator (me) is a part of the channel. It is not working for 2 other users when I’m not involved.

Did you solve this issue? If so, how? I was a little confused how attachments might solve your problem.

Yes it is working now. I am not sure any more, what it really was but I think it had to do with https somehow.
I registered myself another user that was not admin and tested it with that account. Also look up the log, there should be an error message.

I have it working now! It was the format of the response I was sending back. I also needed to add the response_type property.