我如何从mattermost机器人发送直接消息给用户?我发现类似的问题,但它不适合我:
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
}
}
我尝试运行go run *.go
脚本启动无错误,但什么也没有发生(没有从机器人得到消息),我的错误在哪里?
谢谢!
1条答案
按热度按时间huwehgph1#
我找到解决办法了,在我的MM服务器上使用的是较新版本的API,只是更改:
"github.com/mattermost/mattermost-server/v5/model"
到
"github.com/mattermost/mattermost-server/v6/model"
谢谢!