How i can send direct message from mattermost bot to user? I find similar question, but it not works for me:
package main
import (
"github.com/mattermost/mattermost-server/v5/model"
)
func main() {
client := model.NewAPIv4Client("https://server.name.here")
client.SetToken("superdupertoken")
bot, resp := client.GetUserByUsername("NameOf.BotSendingMessage", "here.bot.name")
if resp.Error != nil {
return
}
user, resp := client.GetUserByUsername("UsernameOf.UserToMessage", "here.my.user.name")
if resp.Error != nil {
return
}
channel, resp := client.CreateDirectChannel(bot.Id, user.Id)
if resp.Error != nil {
return
}
post := &model.Post{}
post.ChannelId = channel.Id
post.Message = "some message"
if _, resp := client.CreatePost(post); resp.Error != nil {
return
}
}
i try to run with go run *.go
script start without errors, but nothin happens(not get message from bot), where is my mistake?
Thanks!