本文整理汇总了Golang中github.com/mattermost/platform/model.CommandResponse.ToJson方法的典型用法代码示例。如果您正苦于以下问题:Golang CommandResponse.ToJson方法的具体用法?Golang CommandResponse.ToJson怎么用?Golang CommandResponse.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.CommandResponse
的用法示例。
在下文中一共展示了CommandResponse.ToJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleResponse
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, commandArgs *model.CommandArgs, cmd *model.Command, builtIn bool) {
post := &model.Post{}
post.ChannelId = commandArgs.ChannelId
post.RootId = commandArgs.RootId
post.ParentId = commandArgs.ParentId
post.UserId = c.Session.UserId
if !builtIn {
post.AddProp("from_webhook", "true")
}
if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
if len(cmd.Username) != 0 {
post.AddProp("override_username", cmd.Username)
} else if len(response.Username) != 0 {
post.AddProp("override_username", response.Username)
}
}
if utils.Cfg.ServiceSettings.EnablePostIconOverride {
if len(cmd.IconURL) != 0 {
post.AddProp("override_icon_url", cmd.IconURL)
} else if len(response.IconURL) != 0 {
post.AddProp("override_icon_url", response.IconURL)
} else {
post.AddProp("override_icon_url", "")
}
}
if _, err := app.CreateCommandPost(post, c.TeamId, response); err != nil {
l4g.Error(err.Error())
}
w.Write([]byte(response.ToJson()))
}
示例2: handleResponse
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, commandArgs *model.CommandArgs, cmd *model.Command, builtIn bool) {
post := &model.Post{}
post.ChannelId = commandArgs.ChannelId
post.RootId = commandArgs.RootId
post.ParentId = commandArgs.ParentId
if !builtIn {
post.AddProp("from_webhook", "true")
}
if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
if len(cmd.Username) != 0 {
post.AddProp("override_username", cmd.Username)
} else if len(response.Username) != 0 {
post.AddProp("override_username", response.Username)
} else {
post.AddProp("override_username", model.DEFAULT_WEBHOOK_USERNAME)
}
}
if utils.Cfg.ServiceSettings.EnablePostIconOverride {
if len(cmd.IconURL) != 0 {
post.AddProp("override_icon_url", cmd.IconURL)
} else if len(response.IconURL) != 0 {
post.AddProp("override_icon_url", response.IconURL)
} else {
post.AddProp("override_icon_url", "")
}
}
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
post.Message = response.Text
post.UserId = c.Session.UserId
if _, err := CreatePost(c, post, true); err != nil {
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
}
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL && response.Text != "" {
post.Message = response.Text
post.CreateAt = model.GetMillis()
post.UserId = c.Session.UserId
post.ParentId = ""
SendEphemeralPost(
c.TeamId,
c.Session.UserId,
post,
)
}
w.Write([]byte(response.ToJson()))
}
示例3: handleResponse
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string) {
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
post := &model.Post{}
post.ChannelId = channelId
post.Message = response.Text
if _, err := CreatePost(c, post, true); err != nil {
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
}
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
// post := &model.Post{}
// post.ChannelId = channelId
// post.Message = "TODO_EPHEMERAL: " + response.Text
// if _, err := CreatePost(c, post, true); err != nil {
// c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
// }
}
w.Write([]byte(response.ToJson()))
}