Reputation: 620
until now I have only ever used the bot to send messages to a channel. You looked like this.
{
"channel_id": "my-id",
"message": "Hello Channel"
}
How can I send a simple direct message to a user? The url for the direct Chanel is :"/api/v4/channel/direct" right? so try to send it. as reply i get this "Typo? are you missing a team_id or user_id as part of the url?," Thats okay cause i dont set a reciever User. But now? On Github i just read i need to set 2 ids? My id and the id from the reciever right? How i get the ID from another User?
Upvotes: 5
Views: 13360
Reputation: 620
Here's another way, I had this solution
first check if the bot has the correct permissions!! This was my mistake
Then send a Post Request to url+"/api/v4/channels/direct Send Bearer Token in the header and as a body a Json
["bot ID", "reciever ID"]
Now you have to send a second post request. See here: "https://api.mattermost.com/#tag/posts/paths/~1posts/post" This is the same as a message to a channel.
As channel_id you take the "id" you got back from the previous request. Short way: URL "/api/v4/posts" + Bearer Token in the Header This Json in the Body:
{
"channel_id": "the return id from the first request",
"message": "Hello Dude, how are you!"
}
Upvotes: 1
Reputation: 1336
You need to use a special channel form with an underscore like X_Y, where X and Y are user ids. User ids are not the same as user names.
payload={"channel": "6w41z1q367dujfaxr1nrykr5oc__94dzjnkd8igafdraw66syi1cde", "text": "Hello, this is some text\nThis is more text. :tada:"}
You can check FAQ page for the details https://docs.mattermost.com/developer/webhooks-incoming.html
Upvotes: 2