Integration to send private messages


I would like to build an integration into my Mattermost that is able to send private messages to users. It should get a user ID in my mattermost (i. e. “Botbot”) and should be able to send direct private messages to all members of the team.

I have seen, incoming web hooks are only able to post into channels, and I haven’t found anything in the API documentation on how to do this. Any hints that you could give me?

Thanks a lot!


Dear Christian,
for me the incoming webhook also works fine for addressing Users directly.
See here:
For example, you might have a single webhook created for Town Square, but you can use payload={“channel”: “off-topic”, “text”: “Hello, this is some text.”} to send a message to the Off-Topic channel using the same webhook URL.
If an @ symbol followed by a username is specified, then the message will be sent to that user’s direct message channel

Below Additional Notes:

best regards

Thank you for your reply @githubkoma. I have played a bit and yes, I kind of got the webhook message appearing like a private message. For this, I had to create a “pseudo user”, a user which does not have any real person at the other end and add a “channel”-field in my message with the value “@pseudouser”. This way, in my mattermost the user appeared under “direct messages” and the message was there.
What I miss is the “unread messages” counter (the small bubble beside the user name that indicates how many new messages there are).
The default behavior seems to be that in a channel the channel name only gets bold when there are unread messages, and only when there are mentions (“at”-all or “at”-username) then the counter bubble appears. In direct messages, this counter bubble always appears (supposedly because these are always meant like “mentioned”) but in this case when a webhook bot sends messages into a “direct” channel this is still handled like a normal channel message: no way to get the counter there.

Any ideas?

Hi @christiananton - I think it’s not showing as a mention counter only for the account that created the webhook. So as a temporary work around, you could try setting up the integration with the @pseudouser account, and then sending the message to the DM channel of the account you want to get the counter indicator.

I’m not sure if it’s expected or not that the counter doesn’t show for the person who created the webhook, but it’s definitely a bug that mentioning @username doesn’t cause the counter to show up in the DM channel.

Edit: Filed a ticket here for the bug, with the expected behaviour that all webhook messages sent to a Direct Message trigger the counter (like a normal direct message would).